From c7b3020087ca72d3fce48317ab83fdece452e913 Mon Sep 17 00:00:00 2001 From: "Chris St. Pierre" Date: Thu, 18 Oct 2012 10:00:19 -0400 Subject: use daemon.pid[lock]file.PIDLockFile to write PID file --- src/lib/Bcfg2/Server/BuiltinCore.py | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) (limited to 'src/lib/Bcfg2/Server/BuiltinCore.py') diff --git a/src/lib/Bcfg2/Server/BuiltinCore.py b/src/lib/Bcfg2/Server/BuiltinCore.py index 889e4d4d6..a15aadc49 100644 --- a/src/lib/Bcfg2/Server/BuiltinCore.py +++ b/src/lib/Bcfg2/Server/BuiltinCore.py @@ -10,24 +10,12 @@ from Bcfg2.Server.Core import BaseCore, NoExposedMethod from Bcfg2.Compat import xmlrpclib, urlparse from Bcfg2.SSLServer import XMLRPCServer - -class PidFile(object): - """ Context handler used by :class:`daemon.DaemonContext` to write - the PID file. """ - - def __init__(self, pidfile): - """ - :param pidfile: The full path to the PID file to write on - entering the context handler - :type pidfile: string - """ - 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) +# pylint: disable=E0611 +try: + from daemon.pidfile import PIDLockFile +except ImportError: + from daemon.pidlockfile import PIDLockFile +# pylint: enable=E0611 class Core(BaseCore): @@ -47,7 +35,7 @@ class Core(BaseCore): self.context = \ daemon.DaemonContext(uid=self.setup['daemon_uid'], gid=self.setup['daemon_gid'], - pidfile=PidFile(self.setup['daemon'])) + pidfile=PIDLockFile(self.setup['daemon'])) __init__.__doc__ = BaseCore.__init__.__doc__.split('.. -----')[0] def _dispatch(self, method, args, dispatch_dict): -- cgit v1.2.3-1-g7c22