summaryrefslogtreecommitdiffstats
path: root/src/lib/Bcfg2/Server/FileMonitor
diff options
context:
space:
mode:
authorChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-04 16:30:13 -0400
committerChris St. Pierre <chris.a.st.pierre@gmail.com>2012-09-04 16:30:13 -0400
commit3417435d20e0ec7002ee7fd7a33e5efbec2bc0cf (patch)
tree570f696e4eb477c0eda96514aaa7032974d448f6 /src/lib/Bcfg2/Server/FileMonitor
parent40258619c474cbaaf783abb6c3a94771984285a1 (diff)
downloadbcfg2-3417435d20e0ec7002ee7fd7a33e5efbec2bc0cf.tar.gz
bcfg2-3417435d20e0ec7002ee7fd7a33e5efbec2bc0cf.tar.bz2
bcfg2-3417435d20e0ec7002ee7fd7a33e5efbec2bc0cf.zip
Core: fixed threading issues preventing successful daemonization of builtin core
Diffstat (limited to 'src/lib/Bcfg2/Server/FileMonitor')
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/Inotify.py27
-rw-r--r--src/lib/Bcfg2/Server/FileMonitor/__init__.py5
2 files changed, 27 insertions, 5 deletions
diff --git a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
index 32390c4eb..e4948ea8d 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/Inotify.py
@@ -1,10 +1,10 @@
""" Inotify driver for file alteration events """
+import os
+import sys
import logging
import operator
-import os
import pyinotify
-import sys
from Bcfg2.Compat import reduce
from Bcfg2.Server.FileMonitor import Event
from Bcfg2.Server.FileMonitor.Pseudo import Pseudo
@@ -22,11 +22,22 @@ class Inotify(Pseudo, pyinotify.ProcessEvent):
def __init__(self, ignore=None, debug=False):
Pseudo.__init__(self, ignore=ignore, debug=debug)
+ self.event_filter = dict()
+ self.watches_by_path = dict()
+ # these are created in start() after the server is done forking
+ self.notifier = None
+ self.wm = None
+ self.started = False
+ self.add_q = []
+
+ def start(self):
self.wm = pyinotify.WatchManager()
self.notifier = pyinotify.ThreadedNotifier(self.wm, self)
self.notifier.start()
- self.event_filter = dict()
- self.watches_by_path = dict()
+ self.started = True
+ for monitor in self.add_q:
+ self.AddMonitor(*monitor)
+ self.add_q = []
def fileno(self):
return self.wm.get_fd()
@@ -75,6 +86,11 @@ class Inotify(Pseudo, pyinotify.ProcessEvent):
def AddMonitor(self, path, obj):
# strip trailing slashes
path = path.rstrip("/")
+
+ if not self.started:
+ self.add_q.append((path, obj))
+ return path
+
if not os.path.isdir(path):
# inotify is a little wonky about watching files. for
# instance, if you watch /tmp/foo, and then do 'mv
@@ -123,4 +139,5 @@ class Inotify(Pseudo, pyinotify.ProcessEvent):
return path
def shutdown(self):
- self.notifier.stop()
+ if self.started:
+ self.notifier.stop()
diff --git a/src/lib/Bcfg2/Server/FileMonitor/__init__.py b/src/lib/Bcfg2/Server/FileMonitor/__init__.py
index c490acc81..a9bf50ccf 100644
--- a/src/lib/Bcfg2/Server/FileMonitor/__init__.py
+++ b/src/lib/Bcfg2/Server/FileMonitor/__init__.py
@@ -44,6 +44,11 @@ class FileMonitor(object):
def __repr__(self):
return "%s (%s events, fd %s)" % (str(self), len(self.events), self.fileno)
+ def start(self):
+ """ start threads or anything else that needs to be done after
+ the server forks and daemonizes """
+ pass
+
def debug_log(self, msg):
if self.debug:
logger.info(msg)