Add an option to store PID in daemon mode
This commit is contained in:
		
							
								
								
									
										2
									
								
								config
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										13
									
								
								radicale.py
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								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")
 | 
			
		||||
 
 | 
			
		||||
@@ -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"},
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user