1 # vim: set encoding=utf-8 et sw=4 sts=4 :
5 from signal import SIGTERM
6 from subprocess import Popen, PIPE
7 import logging ; log = logging.getLogger('pymin.services.vrrp')
9 from pymin import procman
10 from pymin.seqtools import Sequence
11 from pymin.dispatcher import Handler, handler, HandlerError
12 from pymin.services.util import Restorable, TransactionalHandler, \
13 ReloadHandler, RestartHandler, \
14 ServiceHandler, ParametersHandler, call
16 __all__ = ('VrrpHandler',)
18 # FIXME the the command should not use new parameters unless commit where called
19 # i.e. integrate commit with procman to update internal procman parameters.
20 class VrrpHandler(Restorable, ParametersHandler, ReloadHandler, RestartHandler,
21 ServiceHandler, TransactionalHandler):
23 handler_help = u"Manage VRRP service"
25 _persistent_attrs = ['params']
27 _restorable_defaults = dict(
29 ipaddress = '192.168.0.1',
39 command = ['vrrpd', '-i', self.params['dev'], '-v', self.params['id']]
40 if self.params['prio']:
41 command.extend(('-p', self.params['prio']))
42 command.append(self.params['ipaddress'])
45 def _service_start(self):
46 log.debug(u'VrrpHandler._service_start()')
47 procinfo = procman.get('vrrp')
48 procinfo.command = self._command
49 procinfo.persist = self.params['persist']
52 def _service_stop(self):
53 log.debug(u'VrrpHandler._service_stop()')
56 def _service_restart(self):
57 procinfo = procman.get('vrrp')
58 procinfo.command = self._command
59 procinfo.persist = self.params['persist']
60 procman.restart('vrrp')
62 def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
63 log.debug(u'VrrpHandler(%r, %r, $r)', pickle_dir, config_dir, pid_dir)
64 self._persistent_dir = pickle_dir
65 self._pid_dir = pid_dir
66 procman.register('vrrp', None)
67 ServiceHandler.__init__(self)
70 if __name__ == '__main__':
73 level = logging.DEBUG,
74 format = '%(asctime)s %(levelname)-8s %(message)s',