View | Details | Raw Unified | Return to bug 31752
Collapse All | Expand All

(-)console/protocol/server.py (-32 / +8 lines)
 Lines 60-66    Link Here 
60
60
61
from ..resources import moduleManager, categoryManager
61
from ..resources import moduleManager, categoryManager
62
from ..log import CORE, CRYPT, RESOURCES
62
from ..log import CORE, CRYPT, RESOURCES
63
from ..config import ucr, SERVER_MAX_CONNECTIONS
63
from ..config import ucr, SERVER_MAX_CONNECTIONS, get_ucr_notifier
64
from ..statistics import statistics
64
from ..statistics import statistics
65
65
66
class MagicBucket( object ):
66
class MagicBucket( object ):
 Lines 380-386    Link Here 
380
			self.reload()
380
			self.reload()
381
381
382
		# register dispatch function to reload UCR Variables on change
382
		# register dispatch function to reload UCR Variables on change
383
		notifier.dispatcher_add(self._get_ucr_inotify_callback())
383
		try:
384
			callback = get_ucr_notifier()
385
		except OSError, exc:
386
			# inotify limit is reached
387
			CORE.warn('Cannot register UCR notifier: %s' % (exc))
388
		else:
389
			notifier.dispatcher_add(callback)
384
390
385
		CORE.info( 'Initialising server process' )
391
		CORE.info( 'Initialising server process' )
386
		self.__port = port
392
		self.__port = port
 Lines 468-503    Link Here 
468
		CORE.info( '__verify_cert_cb: errnum=%d  depth=%d	 ok=%d' % (errnum, depth, ok) )
474
		CORE.info( '__verify_cert_cb: errnum=%d  depth=%d	 ok=%d' % (errnum, depth, ok) )
469
		return ok
475
		return ok
470
476
471
	def _get_ucr_inotify_callback(self):
472
		''' returns a function which calls an event to reload UCR Variables if they have changed '''
473
		class UCR_update_handler(pyinotify.ProcessEvent):
474
			def __init__(self):
475
				self.running = None
476
			def process(self):
477
				''' reloads UCR Variables '''
478
				ucr.load()
479
				CORE.info('UCR Variables have been reloaded')
480
				self.running = None
481
				return False # destroy timer
482
			def process_IN_MODIFY(self, event):
483
				if self.running:
484
					# remove running timer
485
					notifier.timer_remove(self.running)
486
				# add a timer which reloads UCR Variables in 10 seconds
487
				self.running = notifier.timer_add( 10000, self.process )
488
				return True
489
490
		wm = pyinotify.WatchManager()
491
		wm.add_watch('/etc/univention/base.conf', pyinotify.IN_MODIFY)
492
		ucr_notifier = pyinotify.Notifier(wm, UCR_update_handler())
493
494
		def cb():
495
			ucr_notifier.process_events()
496
			if ucr_notifier.check_events(10):
497
				ucr_notifier.read_events()
498
			return True
499
		return cb
500
501
	def _connection( self, socket ):
477
	def _connection( self, socket ):
502
		'''Signal callback: Invoked on incoming connections.'''
478
		'''Signal callback: Invoked on incoming connections.'''
503
		socket, addr = socket.accept()
479
		socket, addr = socket.accept()
(-)console/config.py (+41 lines)
 Lines 41-47    Link Here 
41
some constants that are used internally.
41
some constants that are used internally.
42
"""
42
"""
43
import univention.config_registry
43
import univention.config_registry
44
from .log import CORE
44
45
46
import pyinotify
47
import notifier
48
45
ucr = univention.config_registry.ConfigRegistry()
49
ucr = univention.config_registry.ConfigRegistry()
46
ucr.load()
50
ucr.load()
47
51
 Lines 58-60    Link Here 
58
62
59
MODULE_DEBUG_LEVEL = get_int( 'umc/module/debug/level', 1 )
63
MODULE_DEBUG_LEVEL = get_int( 'umc/module/debug/level', 1 )
60
MODULE_INACTIVITY_TIMER = get_int( 'umc/module/timeout', 120 ) * 1000
64
MODULE_INACTIVITY_TIMER = get_int( 'umc/module/timeout', 120 ) * 1000
65
66
BASE_CONF = '/etc/univention/base.conf'
67
68
class UCR_update_handler(pyinotify.ProcessEvent):
69
	def __init__(self):
70
		self.running = None
71
72
	def process(self):
73
		''' reload UCR variables '''
74
		ucr.load()
75
		CORE.info('UCR variables have been reloaded')
76
		self.running = None
77
		return False # destroy timer
78
79
	def process_IN_MODIFY(self, event):
80
		if self.running:
81
			# remove running timer
82
			notifier.timer_remove(self.running)
83
		# add a timer which reloads UCR variables in 10 seconds
84
		self.running = notifier.timer_add( 10000, self.process )
85
		return True
86
87
def get_ucr_notifier():
88
	''' returns a function which calls an event to reload UCR variables if they have changed '''
89
90
	wm = pyinotify.WatchManager()
91
	wm.add_watch(BASE_CONF, pyinotify.IN_MODIFY)
92
	ucr_notifier = pyinotify.Notifier(wm, UCR_update_handler())
93
94
	def cb():
95
		ucr_notifier.process_events()
96
		if ucr_notifier.check_events(10):
97
			ucr_notifier.read_events()
98
		return True
99
100
	return cb
101

Return to bug 31752