From e5e13faa7c058a7b533e1c4cf8cc0bb9b79cfb59 Mon Sep 17 00:00:00 2001 From: Unrud Date: Thu, 16 Aug 2018 07:59:59 +0200 Subject: [PATCH] Remove daemonization --- config | 6 ------ radicale/__main__.py | 43 ------------------------------------------- radicale/config.py | 11 ----------- 3 files changed, 60 deletions(-) diff --git a/config b/config index f250e78..0cdc0b5 100644 --- a/config +++ b/config @@ -17,12 +17,6 @@ # For example: 0.0.0.0:9999, [::]:9999 #hosts = 127.0.0.1:5232 -# Daemon flag -#daemon = False - -# File storing the PID in daemon mode -#pid = - # Max parallel connections #max_connections = 20 diff --git a/radicale/__main__.py b/radicale/__main__.py index be1697e..7b5bf54 100644 --- a/radicale/__main__.py +++ b/radicale/__main__.py @@ -23,13 +23,11 @@ from a python programme with ``radicale.__main__.run()``. """ import argparse -import atexit import os import select import signal import socket import ssl -import sys from wsgiref.simple_server import make_server from radicale import (VERSION, Application, RequestHandler, ThreadedHTTPServer, @@ -135,45 +133,6 @@ def run(): exit(1) -def daemonize(configuration): - """Fork and decouple if Radicale is configured as daemon.""" - # Check and create PID file in a race-free manner - if configuration.get("server", "pid"): - try: - pid_path = os.path.abspath(os.path.expanduser( - configuration.get("server", "pid"))) - pid_fd = os.open( - pid_path, os.O_CREAT | os.O_EXCL | os.O_WRONLY) - except OSError as e: - raise OSError("PID file exists: %r" % - configuration.get("server", "pid")) from e - pid = os.fork() - if pid: - # Write PID - if configuration.get("server", "pid"): - with os.fdopen(pid_fd, "w") as pid_file: - pid_file.write(str(pid)) - sys.exit() - if configuration.get("server", "pid"): - os.close(pid_fd) - - # Register exit function - def cleanup(): - """Remove the PID files.""" - logger.debug("Cleaning up") - # Remove PID file - os.unlink(pid_path) - atexit.register(cleanup) - # Decouple environment - os.chdir("/") - os.setsid() - with open(os.devnull, "r") as null_in: - os.dup2(null_in.fileno(), sys.stdin.fileno()) - with open(os.devnull, "w") as null_out: - os.dup2(null_out.fileno(), sys.stdout.fileno()) - os.dup2(null_out.fileno(), sys.stderr.fileno()) - - def serve(configuration): """Serve radicale from configuration.""" logger.info("Starting Radicale") @@ -260,8 +219,6 @@ def serve(configuration): if not shutdown_program_socket_out or os.name == "nt": # Fallback to busy waiting. (select.select blocks SIGINT on Windows.) select_timeout = 1.0 - if configuration.getboolean("server", "daemon"): - daemonize(configuration) logger.info("Radicale server ready") while not shutdown_program: try: diff --git a/radicale/config.py b/radicale/config.py index fbbddee..f5a9090 100644 --- a/radicale/config.py +++ b/radicale/config.py @@ -57,17 +57,6 @@ INITIAL_CONFIG = OrderedDict([ "help": "set server hostnames including ports", "aliases": ["-H", "--hosts"], "type": str}), - ("daemon", { - "value": "False", - "help": "launch as daemon", - "aliases": ["-d", "--daemon"], - "opposite": ["-f", "--foreground"], - "type": bool}), - ("pid", { - "value": "", - "help": "set PID filename for daemon mode", - "aliases": ["-p", "--pid"], - "type": str}), ("max_connections", { "value": "20", "help": "maximum number of parallel connections",