Index: console/protocol/server.py =================================================================== --- console/protocol/server.py (Revision 41414) +++ console/protocol/server.py (Arbeitskopie) @@ -60,7 +60,7 @@ from ..resources import moduleManager, categoryManager from ..log import CORE, CRYPT, RESOURCES -from ..config import ucr, SERVER_MAX_CONNECTIONS +from ..config import ucr, SERVER_MAX_CONNECTIONS, get_ucr_notifier from ..statistics import statistics class MagicBucket( object ): @@ -380,7 +380,13 @@ self.reload() # register dispatch function to reload UCR Variables on change - notifier.dispatcher_add(self._get_ucr_inotify_callback()) + try: + callback = get_ucr_notifier() + except OSError, exc: + # inotify limit is reached + CORE.warn('Cannot register UCR notifier: %s' % (exc)) + else: + notifier.dispatcher_add(callback) CORE.info( 'Initialising server process' ) self.__port = port @@ -468,36 +474,6 @@ CORE.info( '__verify_cert_cb: errnum=%d depth=%d ok=%d' % (errnum, depth, ok) ) return ok - def _get_ucr_inotify_callback(self): - ''' returns a function which calls an event to reload UCR Variables if they have changed ''' - class UCR_update_handler(pyinotify.ProcessEvent): - def __init__(self): - self.running = None - def process(self): - ''' reloads UCR Variables ''' - ucr.load() - CORE.info('UCR Variables have been reloaded') - self.running = None - return False # destroy timer - def process_IN_MODIFY(self, event): - if self.running: - # remove running timer - notifier.timer_remove(self.running) - # add a timer which reloads UCR Variables in 10 seconds - self.running = notifier.timer_add( 10000, self.process ) - return True - - wm = pyinotify.WatchManager() - wm.add_watch('/etc/univention/base.conf', pyinotify.IN_MODIFY) - ucr_notifier = pyinotify.Notifier(wm, UCR_update_handler()) - - def cb(): - ucr_notifier.process_events() - if ucr_notifier.check_events(10): - ucr_notifier.read_events() - return True - return cb - def _connection( self, socket ): '''Signal callback: Invoked on incoming connections.''' socket, addr = socket.accept() Index: console/config.py =================================================================== --- console/config.py (Revision 41414) +++ console/config.py (Arbeitskopie) @@ -41,7 +41,11 @@ some constants that are used internally. """ import univention.config_registry +from .log import CORE +import pyinotify +import notifier + ucr = univention.config_registry.ConfigRegistry() ucr.load() @@ -58,3 +62,40 @@ MODULE_DEBUG_LEVEL = get_int( 'umc/module/debug/level', 1 ) MODULE_INACTIVITY_TIMER = get_int( 'umc/module/timeout', 120 ) * 1000 + +BASE_CONF = '/etc/univention/base.conf' + +class UCR_update_handler(pyinotify.ProcessEvent): + def __init__(self): + self.running = None + + def process(self): + ''' reload UCR variables ''' + ucr.load() + CORE.info('UCR variables have been reloaded') + self.running = None + return False # destroy timer + + def process_IN_MODIFY(self, event): + if self.running: + # remove running timer + notifier.timer_remove(self.running) + # add a timer which reloads UCR variables in 10 seconds + self.running = notifier.timer_add( 10000, self.process ) + return True + +def get_ucr_notifier(): + ''' returns a function which calls an event to reload UCR variables if they have changed ''' + + wm = pyinotify.WatchManager() + wm.add_watch(BASE_CONF, pyinotify.IN_MODIFY) + ucr_notifier = pyinotify.Notifier(wm, UCR_update_handler()) + + def cb(): + ucr_notifier.process_events() + if ucr_notifier.check_events(10): + ucr_notifier.read_events() + return True + + return cb +