1
0
Fork 0
mirror of https://github.com/Kozea/Radicale.git synced 2025-06-26 16:45:52 +00:00

First support for IPv6 and multiple interfaces

This commit is contained in:
René 'Necoro' Neumann 2011-02-08 19:27:00 +01:00
parent 9b535ba4b2
commit 396d7c3721
2 changed files with 60 additions and 10 deletions

View file

@ -38,6 +38,7 @@ arguments.
import os
import sys
import optparse
import threading, signal
import radicale
@ -97,8 +98,40 @@ if options.daemon:
sys.exit()
sys.stdout = sys.stderr = open(os.devnull, "w")
def exit (servers):
"""Cleanly shutdown all servers.
Might be called multiple times."""
for s in servers:
s.shutdown()
# Launch calendar server
server_class = radicale.HTTPSServer if options.ssl else radicale.HTTPServer
server = server_class(
(options.host, options.port), radicale.CalendarHTTPHandler)
server.serve_forever()
servers = []
threads = []
for host in (x.strip() for x in options.host.split(',')):
try:
server = server_class(
(host, options.port), radicale.CalendarHTTPHandler)
servers.append(server)
t = threading.Thread(target = server.serve_forever)
threads.append(t)
t.start()
except:
exit(servers)
raise
# clean exit on SIGTERM
signal.signal(signal.SIGTERM, lambda *a: exit(servers))
try:
while threads:
threads[0].join(1) # try one second
if threading.active_count() <= len(threads): # one thread died
break
except KeyboardInterrupt:
pass
finally:
exit(servers)