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. ...@@ -36,10 +36,11 @@ arguments.
# TODO: Manage smart and configurable logs # TODO: Manage smart and configurable logs
import daemon
import logging import logging
import optparse
import os import os
import sys import sys
import optparse
import calypso import calypso
import calypso.webdav as webdav import calypso.webdav as webdav
...@@ -132,14 +133,22 @@ if options.import_dest: ...@@ -132,14 +133,22 @@ if options.import_dest:
else: else:
sys.exit(1) sys.exit(1)
# Fork if Calypso is launched as daemon def run_server():
if options.daemon: # Launch server
if os.fork(): server_class = calypso.HTTPSServer if options.ssl else calypso.HTTPServer
sys.exit() server = server_class(
sys.stdout = sys.stderr = open(os.devnull, "w") (options.host, options.port), calypso.CollectionHTTPHandler)
server.serve_forever(poll_interval=10)
# Launch server
server_class = calypso.HTTPSServer if options.ssl else calypso.HTTPServer # If foreground execution is requested, just run the server
server = server_class( if not options.daemon:
(options.host, options.port), calypso.CollectionHTTPHandler) run_server()
server.serve_forever(poll_interval=10) 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( ...@@ -77,7 +77,7 @@ setup(
platforms="Any", platforms="Any",
packages=["calypso", "calypso.acl"], packages=["calypso", "calypso.acl"],
provides=["calypso"], provides=["calypso"],
install_requires=["vobject",], install_requires=["daemon","vobject"],
scripts=["calypso.py"], scripts=["calypso.py"],
cmdclass={"build_scripts": BuildScripts}, cmdclass={"build_scripts": BuildScripts},
keywords=["calendar", "CalDAV"], 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