2024-12-03 16:53:31 -05:00
|
|
|
import os
|
|
|
|
import signal
|
|
|
|
import configparser
|
|
|
|
|
2024-12-04 11:48:56 -05:00
|
|
|
from nntp.tiny.config import Config
|
2024-12-03 16:53:31 -05:00
|
|
|
|
|
|
|
class Daemon():
|
2024-12-04 11:48:56 -05:00
|
|
|
def init(config: Config):
|
2024-12-03 16:53:31 -05:00
|
|
|
pidfile = config.get('daemon', 'pidfile')
|
2024-12-04 11:48:56 -05:00
|
|
|
pid = os.fork()
|
2024-12-03 16:53:31 -05:00
|
|
|
|
|
|
|
if pid > 0:
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
with open(pidfile, 'w') as fh:
|
|
|
|
print(str(os.getpid()), file=fh)
|
|
|
|
|
2024-12-03 17:00:49 -05:00
|
|
|
def stop(sig, trace):
|
|
|
|
os.unlink(pidfile)
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
signal.signal(signal.SIGTERM, stop)
|