From 21654d20777926da572f220607a2d85b2eeb4d52 Mon Sep 17 00:00:00 2001 From: Joe Nahmias Date: Thu, 25 Apr 2013 23:44:36 -0400 Subject: [PATCH] Add pidfile support Add config option for the pidfile, with a reasonable default. Have calypso create the pidfile when it daemonizes. Add -P,--pid-file command-line option to specify the file. Document the option in the manpage. --- calypso.1 | 3 +++ calypso.py | 8 ++++++++ calypso/config.py | 4 +++- config | 2 ++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/calypso.1 b/calypso.1 index 8919da9..f0b45fe 100644 --- a/calypso.1 +++ b/calypso.1 @@ -40,6 +40,9 @@ certificate file .TP \fB\-g\fR, \fB\-\-debug\fR enable debug logging +.TP +.BI \-P " PIDFILE" "\fR, \fB\-\-pid-file=" PIDFILE +set location of file containing calypso process-id .SH AUTHOR Written by Keith Packard .SH COPYRIGHT diff --git a/calypso.py b/calypso.py index 113a24c..f18e788 100755 --- a/calypso.py +++ b/calypso.py @@ -37,6 +37,7 @@ arguments. # TODO: Manage smart and configurable logs import daemon +from daemon import pidlockfile import logging import optparse import os @@ -87,6 +88,10 @@ parser.add_option( "-g", "--debug", action="store_true", default=False, help="enable debug logging") +parser.add_option( + "-P", "--pid-file", dest="pidfile", + default=calypso.config.get("server", "pidfile"), + help="set location of process-id file") (options, args) = parser.parse_args() @@ -151,6 +156,9 @@ if not options.daemon: # Otherwise, daemonize Calypso context = daemon.DaemonContext() context.umask = 0o002 +if options.pidfile: + # Generate a pidfile where requested + context.pidfile = pidlockfile.PIDLockFile(options.pidfile) with context: run_server() diff --git a/calypso/config.py b/calypso/config.py index 9baf0ce..ddabe71 100644 --- a/calypso/config.py +++ b/calypso/config.py @@ -44,7 +44,9 @@ INITIAL_CONFIG = { "daemon": "False", "ssl": "False", "certificate": "/etc/apache2/ssl/server.crt", - "key": "/etc/apache2/ssl/server.key"}, + "key": "/etc/apache2/ssl/server.key", + "pidfile": "/var/run/calypso.pid", + }, "encoding": { "request": "utf-8", "stock": "utf-8"}, diff --git a/config b/config index aa2b19e..9018ca0 100644 --- a/config +++ b/config @@ -18,6 +18,8 @@ ssl = False certificate = /etc/apache2/ssl/server.crt # SSL private key (if needed) key = /etc/apache2/ssl/server.key +# File to store the PID of the running calypso instance +# pidfile = /var/run/calypso.pid [encoding] # Encoding for responding requests -- 2.34.1