[Osaas-commits] r47 - in trunk: . server server/osaas server/osaas/http
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Nov 21 17:19:03 CET 2008
Author: bh
Date: 2008-11-21 17:19:02 +0100 (Fri, 21 Nov 2008)
New Revision: 47
Modified:
trunk/ChangeLog
trunk/server/demo-config.xml
trunk/server/osaas/http/run.py
trunk/server/osaas/run.py
Log:
First step towards implementing feature request #801
* server/osaas/http/run.py (ServerProgram.create_option_parser):
New option --pid-file
(ServerProgram.write_pid_file): New method to write the pid into a
file
(ServerProgram.remove_pid_file): New method to remvoe the pid file
(ServerProgram.main): call write_pid_file and remove_pid_file
* server/osaas/run.py (OSAASServerProgram.create_option_parser):
New config file option PidFile in the OSAASConfig section
* server/demo-config.xml: Add PidFile option and comments
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2008-11-20 20:25:08 UTC (rev 46)
+++ trunk/ChangeLog 2008-11-21 16:19:02 UTC (rev 47)
@@ -1,3 +1,19 @@
+2008-11-21 Bernhard Herzog <bh at intevation.de>
+
+ First step towards implementing feature request #801
+
+ * server/osaas/http/run.py (ServerProgram.create_option_parser):
+ New option --pid-file
+ (ServerProgram.write_pid_file): New method to write the pid into a
+ file
+ (ServerProgram.remove_pid_file): New method to remvoe the pid file
+ (ServerProgram.main): call write_pid_file and remove_pid_file
+
+ * server/osaas/run.py (OSAASServerProgram.create_option_parser):
+ New config file option PidFile in the OSAASConfig section
+
+ * server/demo-config.xml: Add PidFile option and comments
+
2008-11-20 Bernhard Herzog <bh at intevation.de>
Cope with WMS clients that omit the SERVICE field of GetMap
Modified: trunk/server/demo-config.xml
===================================================================
--- trunk/server/demo-config.xml 2008-11-20 20:25:08 UTC (rev 46)
+++ trunk/server/demo-config.xml 2008-11-21 16:19:02 UTC (rev 47)
@@ -13,6 +13,9 @@
<!-- The users database file. -->
<UserDB>/etc/osaas-users</UserDB>
+ <!-- File in which to write the PID. Useful for /etc/init.d scripts -->
+ <PidFile>/va/run/osaas.pid</PidFile>
+
<!-- The database connection parameters -->
<DBConnection>
<!-- Type of the database. Possible values: oracle, postgresql -->
Modified: trunk/server/osaas/http/run.py
===================================================================
--- trunk/server/osaas/http/run.py 2008-11-20 20:25:08 UTC (rev 46)
+++ trunk/server/osaas/http/run.py 2008-11-21 16:19:02 UTC (rev 47)
@@ -1,5 +1,5 @@
#! /bin/env python
-# Copyright (C) 2007 by Intevation GmbH
+# Copyright (C) 2007, 2008 by Intevation GmbH
# Authors:
# Bernhard Herzog <bh at intevation.de>
#
@@ -13,6 +13,7 @@
import optparse
import logging
import signal
+import tempfile
import httpserver
@@ -82,6 +83,7 @@
def __init__(self):
self.server = None
+ self.pid_file = None
def create_option_parser(self, **kw):
parser = ProgramWithOptions.create_option_parser(self, **kw)
@@ -89,6 +91,7 @@
parser.add_option("--port", type="int")
parser.add_option("--access-log")
parser.add_option("--error-log")
+ parser.add_option("--pid-file")
return parser
def setup_signals(self):
@@ -123,6 +126,28 @@
hdlr.setFormatter(logging.Formatter(format))
logger.addHandler(hdlr)
+ def write_pid_file(self, opts):
+ """Writes the process ID to the file given in opts.pid_file"""
+ if opts.pid_file is None:
+ return
+
+ dirname, basename = os.path.split(opts.pid_file)
+ fileno, tempname = tempfile.mkstemp("", basename, dirname)
+ try:
+ os.write(fileno, "%d\n" % os.getpid())
+ os.close(fileno)
+ os.rename(tempname, opts.pid_file)
+ self.pid_file = opts.pid_file
+ finally:
+ if os.path.exists(tempname):
+ os.remove(tempname)
+
+ def remove_pid_file(self):
+ try:
+ os.remove(self.pid_file)
+ except:
+ pass
+
def instantiate_server(self, server_class, server_address, opts, **kw):
return server_class(server_address, **kw)
@@ -132,6 +157,7 @@
self.setup_signals()
self.setup_logging(opts)
+ self.write_pid_file(opts)
logger = logging.getLogger("httpserver.error")
@@ -152,6 +178,8 @@
logger.info("received SIGTERM; stopping server")
self.server.server_close()
+ self.remove_pid_file()
+
logmessage = "server stopped"
print logmessage
logger.info(logmessage)
Modified: trunk/server/osaas/run.py
===================================================================
--- trunk/server/osaas/run.py 2008-11-20 20:25:08 UTC (rev 46)
+++ trunk/server/osaas/run.py 2008-11-21 16:19:02 UTC (rev 47)
@@ -30,7 +30,7 @@
def create_option_parser(self, **kw):
parser = ServerProgram.create_option_parser(self, **kw)
- for name in ["port", "access-log", "error-log"]:
+ for name in ["port", "access-log", "error-log", "pid-file"]:
path = "OSAASConfig/" + "".join([part.capitalize()
for part in name.split("-")])
parser.get_option("--" + name).xml_path = path
More information about the Osaas-commits
mailing list