1 # vim: set encoding=utf-8 et sw=4 sts=4 :
5 from signal import SIGTERM
6 from subprocess import Popen, PIPE
8 from pymin.seqtools import Sequence
9 from pymin.dispatcher import Handler, handler, HandlerError
10 from pymin.services.util import Restorable, TransactionalHandler, \
11 ReloadHandler, RestartHandler, \
12 ServiceHandler, ParametersHandler, call
14 __ALL__ = ('VrrpHandler',)
16 pid_filename = 'vrrp.pid'
18 class VrrpHandler(Restorable, ParametersHandler, ReloadHandler, RestartHandler,
19 ServiceHandler, TransactionalHandler):
21 handler_help = u"Manage VRRP service"
23 _persistent_attrs = ['params']
25 _restorable_defaults = dict(
26 params = dict( ipaddress='192.168.0.1',
33 def _service_start(self):
34 if self.params['prio'] != '':
35 call(('vrrp', '-i', self.params['dev'], '-v', self.params['id'],
36 '-p', self.params['prio'], self.params['ipaddress']))
38 call(('vrrp', '-i', self.params['dev'], '-v', self.params['id'], \
39 self.params['ipaddress']))
41 def _service_stop(self):
43 pid = file(path.join(self._pid_dir, pid_filename )).read().strip()
44 os.kill(int(pid), SIGTERM)
45 except (IOError, OSError):
49 def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
50 self._persistent_dir = pickle_dir
51 self._pid_dir = pid_dir
52 ServiceHandler.__init__(self)
55 if __name__ == '__main__':