Add an option to store PID in daemon mode

This commit is contained in:
Guillaume Ayoub 2011-05-13 22:50:55 +02:00
parent bd2c50dadf
commit 06f1987975
3 changed files with 14 additions and 2 deletions

2
config
View File

@ -17,6 +17,8 @@
hosts = 0.0.0.0:5232 hosts = 0.0.0.0:5232
# Daemon flag # Daemon flag
daemon = False daemon = False
# File storing the PID in daemon mode
pid =
# SSL flag, enable HTTPS protocol # SSL flag, enable HTTPS protocol
ssl = False ssl = False
# SSL certificate path # SSL certificate path

View File

@ -47,6 +47,10 @@ parser.add_option(
"-d", "--daemon", action="store_true", "-d", "--daemon", action="store_true",
default=radicale.config.getboolean("server", "daemon"), default=radicale.config.getboolean("server", "daemon"),
help="launch as daemon") help="launch as daemon")
parser.add_option(
"-p", "--pid",
default=radicale.config.get("server", "pid"),
help="set PID filename for daemon mode")
parser.add_option( parser.add_option(
"-f", "--foreground", action="store_false", dest="daemon", "-f", "--foreground", action="store_false", dest="daemon",
help="launch in foreground (opposite of --daemon)") help="launch in foreground (opposite of --daemon)")
@ -88,7 +92,12 @@ radicale.log.start()
# Fork if Radicale is launched as daemon # Fork if Radicale is launched as daemon
if options.daemon: if options.daemon:
if os.fork(): pid = os.fork()
if pid:
try:
if options.pid:
open(options.pid, 'w').write(str(pid))
finally:
sys.exit() sys.exit()
sys.stdout = sys.stderr = open(os.devnull, "w") sys.stdout = sys.stderr = open(os.devnull, "w")

View File

@ -41,6 +41,7 @@ INITIAL_CONFIG = {
"server": { "server": {
"hosts": "0.0.0.0:5232", "hosts": "0.0.0.0:5232",
"daemon": "False", "daemon": "False",
"pid": "",
"ssl": "False", "ssl": "False",
"certificate": "/etc/apache2/ssl/server.crt", "certificate": "/etc/apache2/ssl/server.crt",
"key": "/etc/apache2/ssl/server.key"}, "key": "/etc/apache2/ssl/server.key"},