When launched in daemon mode, attach to the socket
This commit is contained in:
parent
b7e12037de
commit
838b76081d
@ -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