diff options
author | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-09-25 16:55:12 -0400 |
---|---|---|
committer | Chris St. Pierre <chris.a.st.pierre@gmail.com> | 2012-09-25 16:55:12 -0400 |
commit | bc636a8bbddde9dc1d09a6dab2f325c4190f871a (patch) | |
tree | 718b901e4a4645817a1a6a4e7aa847617a5a9aa6 /src | |
parent | f08ecec3ec2c8ff2baed5c9fa613a61e5c3406cd (diff) | |
download | bcfg2-bc636a8bbddde9dc1d09a6dab2f325c4190f871a.tar.gz bcfg2-bc636a8bbddde9dc1d09a6dab2f325c4190f871a.tar.bz2 bcfg2-bc636a8bbddde9dc1d09a6dab2f325c4190f871a.zip |
moved pidfile creation into the server backends
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/Bcfg2/Server/BuiltinCore.py | 16 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/CherryPyCore.py | 3 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Core.py | 3 |
3 files changed, 18 insertions, 4 deletions
diff --git a/src/lib/Bcfg2/Server/BuiltinCore.py b/src/lib/Bcfg2/Server/BuiltinCore.py index ebd426802..61edd9cf7 100644 --- a/src/lib/Bcfg2/Server/BuiltinCore.py +++ b/src/lib/Bcfg2/Server/BuiltinCore.py @@ -1,5 +1,6 @@ """ the core of the builtin bcfg2 server """ +import os import sys import time import socket @@ -9,6 +10,18 @@ from Bcfg2.Compat import xmlrpclib, urlparse from Bcfg2.SSLServer import XMLRPCServer +class PidFile(object): + """ context handler to write the pid file """ + def __init__(self, pidfile): + self.pidfile = pidfile + + def __enter__(self): + open(self.pidfile, "w").write("%s\n" % os.getpid()) + + def __exit__(self, exc_type, exc_value, exc_traceback): + os.unlink(self.pidfile) + + class Core(BaseCore): """ The built-in server core """ name = 'bcfg2-server' @@ -16,7 +29,8 @@ class Core(BaseCore): def __init__(self, setup): BaseCore.__init__(self, setup) self.server = None - self.context = daemon.DaemonContext() + self.context = \ + daemon.DaemonContext(pidfile=PidFile(self.setup['daemon'])) def _dispatch(self, method, args, dispatch_dict): """Custom XML-RPC dispatcher for components. diff --git a/src/lib/Bcfg2/Server/CherryPyCore.py b/src/lib/Bcfg2/Server/CherryPyCore.py index 6b438b71c..a840d5ae9 100644 --- a/src/lib/Bcfg2/Server/CherryPyCore.py +++ b/src/lib/Bcfg2/Server/CherryPyCore.py @@ -7,7 +7,7 @@ from Bcfg2.Server.Core import BaseCore import cherrypy from cherrypy.lib import xmlrpcutil from cherrypy._cptools import ErrorTool -from cherrypy.process.plugins import Daemonizer +from cherrypy.process.plugins import Daemonizer, PIDFile def on_error(*args, **kwargs): # pylint: disable=W0613 @@ -91,6 +91,7 @@ class Core(BaseCore): def _daemonize(self): Daemonizer(cherrypy.engine).subscribe() + PIDFile(cherrypy.engine, self.setup['daemon']).subscribe() def _run(self): hostname, port = urlparse(self.setup['location'])[1].split(':') diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 81b020a13..14b9d9d0a 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -502,7 +502,6 @@ class BaseCore(object): the server core implementation to call shutdown() """ if self.setup['daemon']: self._daemonize() - open(self.setup['daemon'], "w").write("%s\n" % os.getpid()) self._run() @@ -513,7 +512,7 @@ class BaseCore(object): self._block() def _daemonize(self): - """ daemonize the server """ + """ daemonize the server and write the pidfile """ raise NotImplementedError def _run(self): |