mirror of
https://github.com/codex-storage/deluge.git
synced 2025-01-12 04:24:27 +00:00
add patch from #1473
This commit is contained in:
parent
b0a0574ae0
commit
9a54beef78
@ -149,6 +149,7 @@ this should be an IP address", metavar="IFACE",
|
||||
parser.add_option("-u", "--ui-interface", dest="ui_interface",
|
||||
help="Interface daemon will listen for UI connections on, this should be\
|
||||
an IP address", metavar="IFACE", action="store", type="str")
|
||||
if not (deluge.common.windows_check() or deluge.common.osx_check()):
|
||||
parser.add_option("-d", "--do-not-daemonize", dest="donot",
|
||||
help="Do not daemonize", action="store_true", default=False)
|
||||
parser.add_option("-c", "--config", dest="config",
|
||||
@ -157,6 +158,11 @@ this should be an IP address", metavar="IFACE",
|
||||
help="Set the logfile location", action="store", type="str")
|
||||
parser.add_option("-P", "--pidfile", dest="pidfile",
|
||||
help="Use pidfile to store process id", action="store", type="str")
|
||||
if not deluge.common.windows_check():
|
||||
parser.add_option("-U", "--user", dest="user",
|
||||
help="User to switch to. Only use it when starting as root", action="store", type="str")
|
||||
parser.add_option("-g", "--group", dest="group",
|
||||
help="Group to switch to. Only use it when starting as root", action="store", type="str")
|
||||
parser.add_option("-L", "--loglevel", dest="loglevel",
|
||||
help="Set the log level: none, info, warning, error, critical, debug", action="store", type="str")
|
||||
parser.add_option("-q", "--quiet", dest="quiet",
|
||||
@ -197,24 +203,30 @@ this should be an IP address", metavar="IFACE",
|
||||
open(options.pidfile, "wb").write("%s\n" % os.getpid())
|
||||
|
||||
# If the donot daemonize is set, then we just skip the forking
|
||||
if not options.donot:
|
||||
# Windows check, we log to the config folder by default
|
||||
if deluge.common.windows_check() or deluge.common.osx_check():
|
||||
open_logfile()
|
||||
write_pidfile()
|
||||
else:
|
||||
if os.fork() == 0:
|
||||
if not (deluge.common.windows_check() or deluge.common.osx_check() or options.donot):
|
||||
if os.fork():
|
||||
# We've forked and this is now the parent process, so die!
|
||||
os._exit(0)
|
||||
os.setsid()
|
||||
if os.fork() == 0:
|
||||
# Do second fork
|
||||
if os.fork():
|
||||
os._exit(0)
|
||||
|
||||
# Write pid file before chuid
|
||||
write_pidfile()
|
||||
|
||||
if options.user:
|
||||
if not options.user.isdigit():
|
||||
import pwd
|
||||
options.user = pwd.getpwnam(options.user)[2]
|
||||
os.setuid(options.user)
|
||||
if options.group:
|
||||
if not options.group.isdigit():
|
||||
import grp
|
||||
options.group = grp.getgrnam(options.group)[2]
|
||||
os.setuid(options.group)
|
||||
|
||||
open_logfile()
|
||||
write_pidfile()
|
||||
else:
|
||||
os._exit(0)
|
||||
else:
|
||||
os._exit(0)
|
||||
else:
|
||||
# Do not daemonize
|
||||
write_pidfile()
|
||||
|
||||
# Setup the logger
|
||||
try:
|
||||
|
@ -56,9 +56,20 @@ class Web(_UI):
|
||||
group.add_option("-b", "--base", dest="base",
|
||||
help="Set the base path that the ui is running on (proxying)",
|
||||
action="store", default=None)
|
||||
if not (deluge.common.windows_check() or deluge.common.osx_check()):
|
||||
group.add_option("-f", "--fork", dest="fork",
|
||||
help="Fork the web interface process into the background",
|
||||
action="store_true", default=False)
|
||||
group.add_option("-P", "--pidfile", dest="pidfile", type="str",
|
||||
help="Use pidfile to store process id",
|
||||
action="store", default=None)
|
||||
if not deluge.common.windows_check():
|
||||
group.add_option("-U", "--user", dest="user", type="str",
|
||||
help="User to switch to. Only use it when starting as root",
|
||||
action="store", default=None)
|
||||
group.add_option("-g", "--group", dest="group", type="str",
|
||||
help="Group to switch to. Only use it when starting as root",
|
||||
action="store", default=None)
|
||||
group.add_option("-p", "--port", dest="port", type="int",
|
||||
help="Sets the port to be used for the webserver",
|
||||
action="store", default=None)
|
||||
@ -86,7 +97,7 @@ class Web(_UI):
|
||||
import deluge.common
|
||||
# Steps taken from http://www.faqs.org/faqs/unix-faq/programmer/faq/
|
||||
# Section 1.7
|
||||
if self.options.fork and not deluge.common.windows_check():
|
||||
if self.options.fork:
|
||||
# fork() so the parent can exit, returns control to the command line
|
||||
# or shell invoking the program.
|
||||
if os.fork():
|
||||
@ -104,6 +115,20 @@ class Web(_UI):
|
||||
import deluge.configmanager
|
||||
os.chdir(deluge.configmanager.get_config_dir())
|
||||
|
||||
if self.options.pidfile:
|
||||
open(self.options.pidfile, "wb").write("%d\n" % os.getpid())
|
||||
|
||||
if self.options.group:
|
||||
if not self.options.group.isdigit():
|
||||
import grp
|
||||
self.options.group = grp.getgrnam(self.options.group)[2]
|
||||
os.setuid(self.options.group)
|
||||
if self.options.user:
|
||||
if not self.options.user.isdigit():
|
||||
import pwd
|
||||
self.options.user = pwd.getpwnam(self.options.user)[2]
|
||||
os.setuid(self.options.user)
|
||||
|
||||
import server
|
||||
self.__server = server.DelugeWeb()
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user