Add pidfile support
authorJoe Nahmias <joe@nahmias.net>
Fri, 26 Apr 2013 03:44:36 +0000 (23:44 -0400)
committerKeith Packard <keithp@keithp.com>
Mon, 16 Sep 2013 02:09:07 +0000 (21:09 -0500)
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
calypso.py
calypso/config.py
config

index 8919da926005d62c005892501620d92e0e625779..f0b45fecbd8b89ab6905627e3da0bbca2ef4a091 100644 (file)
--- 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 <keithp@keithp.com>
 .SH COPYRIGHT
index 113a24c1b29398e8aaf8684e27dcdba74ef6ee2d..f18e7883740524f24067ae9c226fd36a9cc7e45c 100755 (executable)
@@ -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()
 
index 9baf0ce4f83a87f084f0ee21cca5b1d205995e0a..ddabe715902f34b71dc9e5d7b8f79ba14077efca 100644 (file)
@@ -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 aa2b19e49427d4d8576ea8aecb718cf88bf2ae7f..9018ca08f34272b9cd195be7081ab9bf6a543d40 100644 (file)
--- 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