diff --git a/config b/config index 90c2e825..45349e36 100644 --- a/config +++ b/config @@ -17,6 +17,8 @@ hosts = 0.0.0.0:5232 # Daemon flag daemon = False +# File storing the PID in daemon mode +pid = # SSL flag, enable HTTPS protocol ssl = False # SSL certificate path diff --git a/radicale.py b/radicale.py index 8ac9bdbb..a5349b57 100755 --- a/radicale.py +++ b/radicale.py @@ -47,6 +47,10 @@ parser.add_option( "-d", "--daemon", action="store_true", default=radicale.config.getboolean("server", "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( "-f", "--foreground", action="store_false", dest="daemon", help="launch in foreground (opposite of --daemon)") @@ -88,8 +92,13 @@ radicale.log.start() # Fork if Radicale is launched as daemon if options.daemon: - if os.fork(): - sys.exit() + pid = os.fork() + if pid: + try: + if options.pid: + open(options.pid, 'w').write(str(pid)) + finally: + sys.exit() sys.stdout = sys.stderr = open(os.devnull, "w") radicale.log.LOGGER.info("Starting Radicale") diff --git a/radicale/config.py b/radicale/config.py index 80742781..a4a780fb 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -41,6 +41,7 @@ INITIAL_CONFIG = { "server": { "hosts": "0.0.0.0:5232", "daemon": "False", + "pid": "", "ssl": "False", "certificate": "/etc/apache2/ssl/server.crt", "key": "/etc/apache2/ssl/server.key"},