Commit c84b8405 authored by Joe Nahmias's avatar Joe Nahmias Committed by Keith Packard

use python-daemon to daemonize calypso

parent 5035efc3
......@@ -36,10 +36,11 @@ arguments.
# TODO: Manage smart and configurable logs
import daemon
import logging
import optparse
import os
import sys
import optparse
import calypso
import calypso.webdav as webdav
......@@ -132,14 +133,22 @@ if options.import_dest:
else:
sys.exit(1)
# Fork if Calypso is launched as daemon
if options.daemon:
if os.fork():
sys.exit()
sys.stdout = sys.stderr = open(os.devnull, "w")
# Launch server
server_class = calypso.HTTPSServer if options.ssl else calypso.HTTPServer
server = server_class(
(options.host, options.port), calypso.CollectionHTTPHandler)
server.serve_forever(poll_interval=10)
def run_server():
# Launch server
server_class = calypso.HTTPSServer if options.ssl else calypso.HTTPServer
server = server_class(
(options.host, options.port), calypso.CollectionHTTPHandler)
server.serve_forever(poll_interval=10)
# If foreground execution is requested, just run the server
if not options.daemon:
run_server()
sys.exit(0)
# Otherwise, daemonize Calypso
context = daemon.DaemonContext()
context.umask = 0o002
with context:
run_server()
# vim: set ts=4 sw=4 et si :
......@@ -77,7 +77,7 @@ setup(
platforms="Any",
packages=["calypso", "calypso.acl"],
provides=["calypso"],
install_requires=["vobject",],
install_requires=["daemon","vobject"],
scripts=["calypso.py"],
cmdclass={"build_scripts": BuildScripts},
keywords=["calendar", "CalDAV"],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment