summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2014-02-18 08:53:35 -0500
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2014-02-18 08:54:12 -0500
commit2de76a7b44c148f2ce9e851060c16513581174ff (patch)
treecec6809ccb30b8ab40c5d855dbc1eac22d03ca9b
parent48913262d9f4f716e9736bad3928eacbaeb4b774 (diff)
downloadbcfg2-2de76a7b44c148f2ce9e851060c16513581174ff.tar.gz
bcfg2-2de76a7b44c148f2ce9e851060c16513581174ff.tar.bz2
bcfg2-2de76a7b44c148f2ce9e851060c16513581174ff.zip
ensure that DB connections are always closed at thread/process exit
-rw-r--r--src/lib/Bcfg2/Reporting/Collector.py9
-rw-r--r--src/lib/Bcfg2/Server/Core.py18
-rwxr-xr-xsrc/sbin/bcfg2-reports3
3 files changed, 20 insertions, 10 deletions
diff --git a/src/lib/Bcfg2/Reporting/Collector.py b/src/lib/Bcfg2/Reporting/Collector.py
index 52700f917..0493c907b 100644
--- a/src/lib/Bcfg2/Reporting/Collector.py
+++ b/src/lib/Bcfg2/Reporting/Collector.py
@@ -56,7 +56,7 @@ class ReportingCollector(object):
"""The collecting process for reports"""
def __init__(self, setup):
- """Setup the collector. This may be called by the daemon or though
+ """Setup the collector. This may be called by the daemon or though
bcfg2-admin"""
self.setup = setup
self.datastore = setup['repo']
@@ -99,12 +99,12 @@ class ReportingCollector(object):
raise ReportingError
try:
- self.logger.debug("Validating storage %s" %
+ self.logger.debug("Validating storage %s" %
self.storage.__class__.__name__)
self.storage.validate()
except:
self.logger.error("Storage backed %s failed to validate: %s" %
- (self.storage.__class__.__name__,
+ (self.storage.__class__.__name__,
traceback.format_exc().splitlines()[-1]))
def run(self):
@@ -162,6 +162,9 @@ class ReportingCollector(object):
pass
if self.storage:
self.storage.shutdown()
+ from django import db
+ self.logger.info("%s: Closing database connection" % self.name)
+ db.close_connection()
def reap_children(self):
"""Join any non-live threads"""
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py
index 587afefe0..cc9270a17 100644
--- a/src/lib/Bcfg2/Server/Core.py
+++ b/src/lib/Bcfg2/Server/Core.py
@@ -414,7 +414,7 @@ class BaseCore(object):
:type plugin: string
:returns: None
"""
- self.logger.debug("Loading plugin %s" % plugin)
+ self.logger.debug("%s: Loading plugin %s" % (self.name, plugin))
try:
mod = getattr(__import__("Bcfg2.Server.Plugins.%s" %
(plugin)).Server.Plugins, plugin)
@@ -450,14 +450,18 @@ class BaseCore(object):
def shutdown(self):
""" Perform plugin and FAM shutdown tasks. """
- self.logger.info("Shutting down core...")
+ self.logger.info("%s: Shutting down core..." % self.name)
if not self.terminate.isSet():
self.terminate.set()
- self.fam.shutdown()
- self.logger.info("FAM shut down")
- for plugin in list(self.plugins.values()):
- plugin.shutdown()
- self.logger.info("All plugins shut down")
+ self.fam.shutdown()
+ self.logger.info("%s: FAM shut down" % self.name)
+ for plugin in list(self.plugins.values()):
+ plugin.shutdown()
+ self.logger.info("%s: All plugins shut down" % self.name)
+ if self._database_available:
+ from django import db
+ self.logger.info("%s: Closing database connection" % self.name)
+ db.close_connection()
@property
def metadata_cache_mode(self):
diff --git a/src/sbin/bcfg2-reports b/src/sbin/bcfg2-reports
index b0c170b1b..2a8447ae4 100755
--- a/src/sbin/bcfg2-reports
+++ b/src/sbin/bcfg2-reports
@@ -24,6 +24,7 @@ sys.path.pop()
os.environ['DJANGO_SETTINGS_MODULE'] = '%s.settings' % project_name
from Bcfg2.Reporting.models import (Client, BaseEntry)
+from django import db
def hosts_by_entry_type(clients, etype, entryspec):
result = []
@@ -293,6 +294,8 @@ def main():
if not client.expiration:
print_fields(fields, client, fmt,
extra=edata.get(client, None))
+ db.close_connection()
+
if __name__ == "__main__":
sys.exit(main())