from pymin.seqtools import Sequence
from pymin.dispatcher import Handler, handler, HandlerError
from pymin.services.util import Restorable, ConfigWriter, ReloadHandler, \
TransactionalHandler, DictSubHandler, call
from pymin.seqtools import Sequence
from pymin.dispatcher import Handler, handler, HandlerError
from pymin.services.util import Restorable, ConfigWriter, ReloadHandler, \
TransactionalHandler, DictSubHandler, call
def __init__(self, pickle_dir='.', config_dir='.'):
r"Initialize Ppphandler object, see class documentation for details."
def __init__(self, pickle_dir='.', config_dir='.'):
r"Initialize Ppphandler object, see class documentation for details."
self._persistent_dir = pickle_dir
self._config_writer_cfg_dir = config_dir
self._config_build_templates()
self._restore()
self._persistent_dir = pickle_dir
self._config_writer_cfg_dir = config_dir
self._config_build_templates()
self._restore()
conn._running = False
self.start(conn.name)
self.conn = ConnectionHandler(self)
@handler(u'Start one or all the connections.')
def start(self, name=None):
conn._running = False
self.start(conn.name)
self.conn = ConnectionHandler(self)
@handler(u'Start one or all the connections.')
def start(self, name=None):
call(('pppd', 'call', name))
self.conns[name]._running = True
self._dump_attr('conns')
else:
call(('pppd', 'call', name))
self.conns[name]._running = True
self._dump_attr('conns')
else:
raise ConnectionNotFoundError(name)
@handler(u'Stop one or all the connections.')
def stop(self, name=None):
raise ConnectionNotFoundError(name)
@handler(u'Stop one or all the connections.')
def stop(self, name=None):
- call(('poff', name))
- if path.exists('/var/run/ppp-' + name + '.pid'):
- pid = file('/var/run/ppp-' + name + '.pid').readline()
+ pid_file = '/var/run/ppp-' + name + '.pid'
+ log.debug(u'PppHandler.stop: getting pid from %r', pid_file)
+ if path.exists(pid_file):
+ pid = file(pid_file).readline()
+ pid = int(pid.strip())
- os.kill(int(pid.strip()), SIGTERM)
- except OSError:
- pass # XXX report error?
+ log.debug(u'PppHandler.stop: killing pid %r', pid)
+ os.kill(pid, SIGTERM)
+ except OSError, e:
+ log.debug(u'PppHandler.stop: error killing: %r', e)
+ else:
+ log.debug(u'PppHandler.stop: pid file not found')
raise ConnectionNotFoundError(name)
@handler(u'Restart one or all the connections (even disconnected ones).')
def restart(self, name=None):
raise ConnectionNotFoundError(name)
@handler(u'Restart one or all the connections (even disconnected ones).')
def restart(self, name=None):
@handler(u'Restart only one or all the already running connections.')
def reload(self, name=None):
r"reload() -> None :: Reload the configuration of the service."
@handler(u'Restart only one or all the already running connections.')
def reload(self, name=None):
r"reload() -> None :: Reload the configuration of the service."
@handler(u'Tell if the service is running.')
def running(self, name=None):
r"reload() -> None :: Reload the configuration of the service."
@handler(u'Tell if the service is running.')
def running(self, name=None):
r"reload() -> None :: Reload the configuration of the service."
p = subprocess.Popen(('pgrep', '-f', 'pppd call ' + c.name),
stdout=subprocess.PIPE)
pid = p.communicate()[0]
p = subprocess.Popen(('pgrep', '-f', 'pppd call ' + c.name),
stdout=subprocess.PIPE)
pid = p.communicate()[0]
p = PppHandler()
p.conn.add('ppp_c','nico','nico',type='PPP',device='tty0')
p.conn.add('pppoe_c','fede','fede',type='OE',device='tty1')
p = PppHandler()
p.conn.add('ppp_c','nico','nico',type='PPP',device='tty0')
p.conn.add('pppoe_c','fede','fede',type='OE',device='tty1')