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 class VrrpHandler(Restorable, ParametersHandler, ReloadHandler, RestartHandler,
17 ServiceHandler, TransactionalHandler):
19 handler_help = u"Manage VRRP service"
21 _persistent_attrs = ['params']
23 _restorable_defaults = dict(
24 params = dict( ipaddress='192.168.0.1',
31 def _service_start(self):
32 if self.params['prio'] != '':
33 call(('vrrp', '-i', self.params['dev'], '-v', self.params['id'],
34 '-p', self.params['prio'], self.params['ipaddress']))
36 call(('vrrp', '-i', self.params['dev'], '-v', self.params['id'], \
37 self.params['ipaddress']))
39 def _service_stop(self):
41 pid_filename = 'vrrpd_%(dev)s_%(id)s.pid' % self.params
42 pid = file(path.join(self._pid_dir, pid_filename )).read().strip()
43 os.kill(int(pid), SIGTERM)
44 except (IOError, OSError):
48 def __init__(self, pickle_dir='.', config_dir='.', pid_dir='.'):
49 self._persistent_dir = pickle_dir
50 self._pid_dir = pid_dir
51 ServiceHandler.__init__(self)
54 if __name__ == '__main__':