22 lines
459 B
Python
22 lines
459 B
Python
import os
|
|
import signal
|
|
import configparser
|
|
|
|
from nntp.tiny.config import Config
|
|
|
|
class Daemon():
|
|
def init(config: Config):
|
|
pidfile = config.get('daemon', 'pidfile')
|
|
pid = os.fork()
|
|
|
|
if pid > 0:
|
|
exit(0)
|
|
|
|
with open(pidfile, 'w') as fh:
|
|
print(str(os.getpid()), file=fh)
|
|
|
|
def stop(sig, trace):
|
|
os.unlink(pidfile)
|
|
exit(0)
|
|
|
|
signal.signal(signal.SIGTERM, stop)
|