Add an option to store PID in daemon mode
This commit is contained in:
parent
bd2c50dadf
commit
06f1987975
2
config
2
config
@ -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
|
||||||
|
13
radicale.py
13
radicale.py
@ -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,8 +92,13 @@ 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()
|
||||||
sys.exit()
|
if pid:
|
||||||
|
try:
|
||||||
|
if options.pid:
|
||||||
|
open(options.pid, 'w').write(str(pid))
|
||||||
|
finally:
|
||||||
|
sys.exit()
|
||||||
sys.stdout = sys.stderr = open(os.devnull, "w")
|
sys.stdout = sys.stderr = open(os.devnull, "w")
|
||||||
|
|
||||||
radicale.log.LOGGER.info("Starting Radicale")
|
radicale.log.LOGGER.info("Starting Radicale")
|
||||||
|
@ -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"},
|
||||||
|
Loading…
Reference in New Issue
Block a user