From f9120cd8b866cbcd6aaaa48f5fc8303f034cad50 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sat, 30 Nov 2019 09:04:31 +0100 Subject: pppoe: T1318: move process startup to apply() --- src/conf_mode/interfaces-pppoe.py | 39 ++++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 21 deletions(-) (limited to 'src/conf_mode/interfaces-pppoe.py') diff --git a/src/conf_mode/interfaces-pppoe.py b/src/conf_mode/interfaces-pppoe.py index c7eca5056..16c59b39b 100755 --- a/src/conf_mode/interfaces-pppoe.py +++ b/src/conf_mode/interfaces-pppoe.py @@ -224,22 +224,6 @@ def generate(pppoe): config_file_pppoe = '/etc/ppp/peers/{}'.format(pppoe['intf']) config_file_ifup = '/etc/ppp/ipv6-up.d/50-vyos-{}-autoconf'.format(pppoe['intf']) - pid = 0 - pidfile = '/var/run/{}.pid'.format(pppoe['intf']) - if os.path.isfile(pidfile): - pid = 0 - with open(pidfile, 'r') as f: - pid = int(f.read()) - - # Always stop OpenVPN service. We can not send a SIGUSR1 for restart of the - # service as the configuration is not re-read. Stop daemon only if it's - # running - it could have died or killed by someone evil - print("pid: {}".format(pid)) - if pid_exists(pid): - cmd = 'start-stop-daemon --stop --quiet' - cmd += ' --pidfile ' + pidfile - subprocess_cmd(cmd) - if pppoe['deleted']: # Delete PPP configuration files if os.path.exists(config_file_pppoe): @@ -263,8 +247,26 @@ def generate(pppoe): os.chmod(config_file_ifup, S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH) + return None + +def apply(pppoe): + pid = 0 + pidfile = '/var/run/{}.pid'.format(pppoe['intf']) + if os.path.isfile(pidfile): + pid = 0 + with open(pidfile, 'r') as f: + pid = int(f.read()) + + # Always stop PPPoE dialer first + if pid_exists(pid): + cmd = 'start-stop-daemon --stop --quiet' + cmd += ' --pidfile ' + pidfile + subprocess_cmd(cmd) + if not pppoe['disable']: # No matching PPP process running - spawn a new one + # NOTE: PID file is only created after dial-in is complete. This is bad + # as you could have zombie dialers. cmd = 'start-stop-daemon --start --quiet' cmd += ' --pidfile ' + pidfile cmd += ' --background' @@ -278,11 +280,6 @@ def generate(pppoe): return None - -def apply(pppoe): - return None - - if __name__ == '__main__': try: c = get_config() -- cgit v1.2.3