mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
Use atexit.register to cleanup after shutdown
This commit is contained in:
parent
3149643706
commit
a28bd4a5fa
1 changed files with 9 additions and 4 deletions
13
radicale.py
13
radicale.py
|
@ -32,6 +32,7 @@ Launch the server according to configuration and command-line options.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import atexit
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import optparse
|
import optparse
|
||||||
|
@ -101,6 +102,14 @@ if options.daemon:
|
||||||
sys.exit()
|
sys.exit()
|
||||||
sys.stdout = sys.stderr = open(os.devnull, "w")
|
sys.stdout = sys.stderr = open(os.devnull, "w")
|
||||||
|
|
||||||
|
# Register exit function
|
||||||
|
def cleanup():
|
||||||
|
radicale.log.LOGGER.debug("Cleaning up")
|
||||||
|
# Remove PID file
|
||||||
|
if options.pid and options.daemon:
|
||||||
|
os.unlink(options.pid)
|
||||||
|
|
||||||
|
atexit.register(cleanup)
|
||||||
radicale.log.LOGGER.info("Starting Radicale")
|
radicale.log.LOGGER.info("Starting Radicale")
|
||||||
|
|
||||||
# Create calendar servers
|
# Create calendar servers
|
||||||
|
@ -159,7 +168,3 @@ finally:
|
||||||
"Closing server listening to %s port %s" % (
|
"Closing server listening to %s port %s" % (
|
||||||
server.server_name, server.server_port))
|
server.server_name, server.server_port))
|
||||||
server.shutdown()
|
server.shutdown()
|
||||||
|
|
||||||
# Remove PID file
|
|
||||||
if options.pid and options.daemon:
|
|
||||||
os.unlink(options.pid)
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue