mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-05 16:08:40 +00:00
Modify startup script to make a true unix daemon by using two fork()s
Work will need to be done to make deluged a windows service
This commit is contained in:
parent
f548dbce7c
commit
282f842663
2 changed files with 38 additions and 21 deletions
|
@ -32,10 +32,18 @@
|
||||||
# statement from all source files in the program, then also delete it here.
|
# statement from all source files in the program, then also delete it here.
|
||||||
|
|
||||||
import deluge.configmanager
|
import deluge.configmanager
|
||||||
|
import deluge.common
|
||||||
from deluge.log import LOG as log
|
from deluge.log import LOG as log
|
||||||
|
|
||||||
class Daemon:
|
class Daemon:
|
||||||
def __init__(self, options, args):
|
def __init__(self, options, args):
|
||||||
|
version = deluge.common.get_version()
|
||||||
|
if deluge.common.get_revision() != "":
|
||||||
|
version = version + "r" + deluge.common.get_revision()
|
||||||
|
|
||||||
|
log.info("Deluge daemon %s", version)
|
||||||
|
log.debug("options: %s", options)
|
||||||
|
log.debug("args: %s", args)
|
||||||
# Set the config directory
|
# Set the config directory
|
||||||
deluge.configmanager.set_config_dir(options.config)
|
deluge.configmanager.set_config_dir(options.config)
|
||||||
|
|
||||||
|
|
|
@ -37,6 +37,8 @@
|
||||||
"""Main starting point for Deluge. Contains the main() entry point."""
|
"""Main starting point for Deluge. Contains the main() entry point."""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import os.path
|
||||||
|
import sys
|
||||||
from optparse import OptionParser
|
from optparse import OptionParser
|
||||||
|
|
||||||
import deluge.common
|
import deluge.common
|
||||||
|
@ -71,6 +73,8 @@ def start_ui():
|
||||||
|
|
||||||
def start_daemon():
|
def start_daemon():
|
||||||
"""Entry point for daemon script"""
|
"""Entry point for daemon script"""
|
||||||
|
import deluge.common
|
||||||
|
|
||||||
# Setup the argument parser
|
# Setup the argument parser
|
||||||
parser = OptionParser(usage="%prog [options] [actions]",
|
parser = OptionParser(usage="%prog [options] [actions]",
|
||||||
version=deluge.common.get_version())
|
version=deluge.common.get_version())
|
||||||
|
@ -80,29 +84,34 @@ def start_daemon():
|
||||||
help="Do not daemonize", action="store_true", default=False)
|
help="Do not daemonize", action="store_true", default=False)
|
||||||
parser.add_option("-c", "--config", dest="config",
|
parser.add_option("-c", "--config", dest="config",
|
||||||
help="Set the config location", action="store", type="str")
|
help="Set the config location", action="store", type="str")
|
||||||
|
parser.add_option("-l", "--logfile", dest="logfile",
|
||||||
|
help="Set the logfile location", action="store", type="str")
|
||||||
|
|
||||||
# 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()
|
||||||
|
|
||||||
from deluge.log import LOG as log
|
# If the donot daemonize is set, then we just skip the forking
|
||||||
|
if not options.donot:
|
||||||
version = deluge.common.get_version()
|
if os.fork() == 0:
|
||||||
if deluge.common.get_revision() != "":
|
os.setsid()
|
||||||
version = version + "r" + deluge.common.get_revision()
|
if os.fork() == 0:
|
||||||
|
if options.logfile:
|
||||||
log.info("Deluge daemon %s", version)
|
logfile = options.logfile
|
||||||
log.debug("options: %s", options)
|
else:
|
||||||
log.debug("args: %s", args)
|
if options.config:
|
||||||
|
logfile = os.path.join(options.config, "deluged.log")
|
||||||
from deluge.core.daemon import Daemon
|
else:
|
||||||
|
config_dir = deluge.common.get_default_config_dir()
|
||||||
|
logfile = os.path.join(config_dir, "deluged.log")
|
||||||
|
|
||||||
|
sys.stdout = open(logfile, "w")
|
||||||
|
sys.stderr = sys.stdout
|
||||||
|
sys.stdin = None
|
||||||
|
else:
|
||||||
|
os._exit(0)
|
||||||
|
else:
|
||||||
|
os._exit(0)
|
||||||
|
|
||||||
if options.donot:
|
from deluge.core.daemon import Daemon
|
||||||
log.info("Starting daemon..")
|
Daemon(options, args)
|
||||||
Daemon(options, args)
|
|
||||||
else:
|
|
||||||
cmd = "deluged -d " + "".join(a for a in args)
|
|
||||||
if options.port != None:
|
|
||||||
cmd = cmd + " -p %s" % options.port
|
|
||||||
if options.config != None:
|
|
||||||
cmd = cmd + " -c %s" % options.config
|
|
||||||
os.popen2(cmd)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue