diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/Bcfg2/Server/BuiltinCore.py | 6 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/CherryPyCore.py | 5 | ||||
-rw-r--r-- | src/lib/Bcfg2/Server/Core.py | 27 | ||||
-rw-r--r-- | src/lib/Bcfg2/Statistics.py | 4 |
4 files changed, 27 insertions, 15 deletions
diff --git a/src/lib/Bcfg2/Server/BuiltinCore.py b/src/lib/Bcfg2/Server/BuiltinCore.py index b62312828..5b9c3302c 100644 --- a/src/lib/Bcfg2/Server/BuiltinCore.py +++ b/src/lib/Bcfg2/Server/BuiltinCore.py @@ -5,6 +5,7 @@ import sys import time import socket import daemon +import Bcfg2.Statistics from Bcfg2.Server.Core import BaseCore, NoExposedMethod from Bcfg2.Compat import xmlrpclib, urlparse from Bcfg2.SSLServer import XMLRPCServer @@ -56,7 +57,8 @@ class Core(BaseCore): try: result = method_func(*args) finally: - self.stats.add_value(method, time.time() - method_start) + Bcfg2.Statistics.stats.add_value(method, + time.time() - method_start) except xmlrpclib.Fault: raise except Exception: @@ -89,7 +91,9 @@ class Core(BaseCore): err = sys.exc_info()[1] self.logger.error("Server startup failed: %s" % err) self.context.close() + return False self.server.register_instance(self) + return True def _block(self): try: diff --git a/src/lib/Bcfg2/Server/CherryPyCore.py b/src/lib/Bcfg2/Server/CherryPyCore.py index 79e939344..53f3de018 100644 --- a/src/lib/Bcfg2/Server/CherryPyCore.py +++ b/src/lib/Bcfg2/Server/CherryPyCore.py @@ -2,6 +2,7 @@ import sys import time +import Bcfg2.Statistics from Bcfg2.Compat import urlparse, xmlrpclib, b64decode from Bcfg2.Server.Core import BaseCore import cherrypy @@ -84,7 +85,8 @@ class Core(BaseCore): try: body = handler(*rpcparams, **params) finally: - self.stats.add_value(rpcmethod, time.time() - method_start) + Bcfg2.Statistics.stats.add_value(rpcmethod, + time.time() - method_start) xmlrpcutil.respond(body, 'utf-8', True) return cherrypy.serving.response.body @@ -112,6 +114,7 @@ class Core(BaseCore): cherrypy.config.update(config) cherrypy.tree.mount(self, '/', {'/': self.setup}) cherrypy.engine.start() + return True def _block(self): cherrypy.engine.block() diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py index 0f32387d2..3b8c79a9e 100644 --- a/src/lib/Bcfg2/Server/Core.py +++ b/src/lib/Bcfg2/Server/Core.py @@ -15,7 +15,7 @@ import Bcfg2.Server import Bcfg2.Logger import Bcfg2.Server.FileMonitor from Bcfg2.Cache import Cache -from Bcfg2.Statistics import Statistics +import Bcfg2.Statistics from Bcfg2.Compat import xmlrpclib, reduce, wraps # pylint: disable=W0622 from Bcfg2.Server.Plugin import PluginInitError, PluginExecutionError @@ -55,7 +55,7 @@ class track_statistics(object): # pylint: disable=C0103 try: return func(obj, *args, **kwargs) finally: - obj.stats.add_value(name, time.time() - start) + Bcfg2.Statistics.stats.add_value(name, time.time() - start) return inner @@ -208,7 +208,6 @@ class BaseCore(object): target=self._file_monitor_thread) self.lock = threading.Lock() - self.stats = Statistics() self.metadata_cache = Cache() def plugins_by_type(self, base_cls): @@ -310,9 +309,9 @@ class BaseCore(object): self.logger.error("%s: Error invoking hook %s: %s" % (plugin, hook, err)) finally: - self.stats.add_value("%s:client_run_hook:%s" % - (self.__class__.__name__, hook), - time.time() - start) + Bcfg2.Statistics.stats.add_value("%s:client_run_hook:%s" % + (self.__class__.__name__, hook), + time.time() - start) @track_statistics() def validate_structures(self, metadata, data): @@ -430,9 +429,10 @@ class BaseCore(object): raise PluginExecutionError("No matching generator: %s:%s" % (entry.tag, entry.get('name'))) finally: - self.stats.add_value("%s:Bind:%s" % (self.__class__.__name__, - entry.tag), - time.time() - start) + Bcfg2.Statistics.stats.add_value("%s:Bind:%s" % + (self.__class__.__name__, + entry.tag), + time.time() - start) def BuildConfiguration(self, client): """Build configuration for clients.""" @@ -507,9 +507,12 @@ class BaseCore(object): self.setup['daemon_uid'], self.setup['daemon_gid']) os.chmod(piddir, 420) # 0644 - self._daemonize() + if not self._daemonize(): + return False - self._run() + if not self._run(): + self.shutdown() + return False self.fam.start() self.fam_thread.start() @@ -777,4 +780,4 @@ class BaseCore(object): @exposed def get_statistics(self, _): """Get current statistics about component execution""" - return self.stats.display() + return Bcfg2.Statistics.stats.display() diff --git a/src/lib/Bcfg2/Statistics.py b/src/lib/Bcfg2/Statistics.py index 2379dd1c8..2fd40e601 100644 --- a/src/lib/Bcfg2/Statistics.py +++ b/src/lib/Bcfg2/Statistics.py @@ -1,7 +1,6 @@ """ module for tracking execution time statistics from the bcfg2 server core """ - class Statistic(object): """ a single named statistic, tracking minimum, maximum, and average execution time, and number of invocations """ @@ -39,3 +38,6 @@ class Statistics(object): def display(self): """ return a dict of all statistics """ return dict([value.get_value() for value in list(self.data.values())]) + + +stats = Statistics() |