When launched in daemon mode, attach to the socket
This commit is contained in:
parent
eb70fe560b
commit
c51b0a9170
@ -106,13 +106,25 @@ def attach(pid, socketfile):
|
||||
return 0
|
||||
|
||||
|
||||
def daemonize():
|
||||
def daemonize(socketfile=None):
|
||||
"""Detach the running process to run as a daemon
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
if socketfile is not None:
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
import time
|
||||
os.waitpid(pid, 0)
|
||||
time.sleep(1)
|
||||
sys.exit(attach(pid, socketfile))
|
||||
except OSError as err:
|
||||
sys.stderr.write("Unable to fork: %s\n" % err)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
pid = os.fork()
|
||||
if pid > 0:
|
||||
|
@ -148,7 +148,7 @@ def main():
|
||||
# Daemonize
|
||||
if not args.debug:
|
||||
from nemubot import daemonize
|
||||
daemonize()
|
||||
daemonize(args.socketfile)
|
||||
|
||||
# Signals handling
|
||||
def sigtermhandler(signum, frame):
|
||||
|
Loading…
Reference in New Issue
Block a user