summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/Core.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/Bcfg2/Server/Core.py')
-rw-r--r--src/lib/Bcfg2/Server/Core.py14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/lib/Bcfg2/Server/Core.py b/src/lib/Bcfg2/Server/Core.py
index 25acc8ac0..a9628c024 100644
--- a/src/lib/Bcfg2/Server/Core.py
+++ b/src/lib/Bcfg2/Server/Core.py
@@ -27,6 +27,7 @@ from Bcfg2.Server.Statistics import track_statistics
try:
from django.core.exceptions import ImproperlyConfigured
+ import django
import django.conf
HAS_DJANGO = True
except ImportError:
@@ -83,10 +84,14 @@ def close_db_connection(func):
""" The decorated function """
rv = func(self, *args, **kwargs)
if self._database_available: # pylint: disable=W0212
- from django import db
self.logger.debug("%s: Closing database connection" %
threading.current_thread().getName())
- db.close_connection()
+
+ if django.VERSION[0] == 1 and django.VERSION[1] >= 7:
+ for connection in django.db.connections.all():
+ connection.close()
+ else:
+ django.db.close_connection()
return rv
return inner
@@ -430,6 +435,7 @@ class Core(object):
self.logger.error("Unexpected instantiation failure for plugin %s"
% plugin, exc_info=1)
+ @close_db_connection
def shutdown(self):
""" Perform plugin and FAM shutdown tasks. """
if not self._running:
@@ -444,10 +450,6 @@ class Core(object):
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):