Use os.popen2() instead of os.fork() to daemonize.

This commit is contained in:
Andrew Resch 2008-01-22 11:45:56 +00:00
parent 4ba32dc4bf
commit bbe31367d4
1 changed files with 11 additions and 5 deletions

View File

@ -70,7 +70,8 @@ def start_daemon():
version=deluge.common.get_version()) version=deluge.common.get_version())
parser.add_option("-p", "--port", dest="port", parser.add_option("-p", "--port", dest="port",
help="Port daemon will listen on", action="store", type="int") help="Port daemon will listen on", action="store", type="int")
parser.add_option("-d", "--do-not-daemonize", dest="donot",
help="Do not daemonize", action="store_true", default=False)
# Get the options and args from the OptionParser # Get the options and args from the OptionParser
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
@ -81,8 +82,13 @@ def start_daemon():
log.debug("args: %s", args) log.debug("args: %s", args)
from deluge.core.daemon import Daemon from deluge.core.daemon import Daemon
log.info("Starting daemon..") if options.donot:
pid = os.fork() log.info("Starting daemon..")
if not pid:
Daemon(options.port) Daemon(options.port)
else:
cmd = "deluged -d " + "".join(a for a in args)
if options.port != None:
cmd = cmd + " -p %s" % options.port
os.popen2(cmd)