summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-12-01 10:43:02 +0100
committerChristian Poessinger <christian@poessinger.com>2020-02-23 14:36:56 +0100
commit426f9d33d24a163fc1fc169930d7b969abf846b0 (patch)
tree736780b423add5d94707680ddd1392e9d47285d4 /src
parent70049969d8e3c28c8ae7a342fa84eb35ed5c9e14 (diff)
downloadvyos-1x-426f9d33d24a163fc1fc169930d7b969abf846b0.tar.gz
vyos-1x-426f9d33d24a163fc1fc169930d7b969abf846b0.zip
pppoe: T1318: use systemd to manage connection
This reduces the amount of self written code to start-stop-daemon and also kill the process if it has no connection yet (there won't be a PID file in this case) and getting the proper PID for multiple processes would require me to walk the /proc/<pid>/cmdline for every binary involved.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/conf_mode/interfaces-pppoe.py32
-rw-r--r--src/etc/systemd/system/ppp@.service11
2 files changed, 17 insertions, 26 deletions
diff --git a/src/conf_mode/interfaces-pppoe.py b/src/conf_mode/interfaces-pppoe.py
index 6c194f60b..219a40dbf 100755
--- a/src/conf_mode/interfaces-pppoe.py
+++ b/src/conf_mode/interfaces-pppoe.py
@@ -20,7 +20,6 @@ from sys import exit
from copy import deepcopy
from jinja2 import Template
-from psutil import pid_exists
from stat import S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IXGRP, S_IROTH, S_IXOTH
from subprocess import Popen, PIPE
@@ -223,6 +222,10 @@ 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'])
+ # Always hang-up PPPoE connection prior generating new configuration file
+ cmd = 'systemctl stop ppp@{}.service'.format(pppoe['intf'])
+ subprocess_cmd(cmd)
+
if pppoe['deleted']:
# Delete PPP configuration files
if os.path.exists(config_file_pppoe):
@@ -249,32 +252,9 @@ def generate(pppoe):
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'
- cmd += ' --exec /usr/sbin/pppd'
- # now pass arguments to pppd binary
- cmd += ' -- '
- cmd += ' call {}'.format(pppoe['intf'])
-
- # execute assembled command
+ # Dial PPPoE connection
+ cmd = 'systemctl start ppp@{}.service'.format(pppoe['intf'])
subprocess_cmd(cmd)
return None
diff --git a/src/etc/systemd/system/ppp@.service b/src/etc/systemd/system/ppp@.service
new file mode 100644
index 000000000..d271efb41
--- /dev/null
+++ b/src/etc/systemd/system/ppp@.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Dialing PPP connection %I
+After=network.target
+
+[Service]
+ExecStart=/usr/sbin/pppd call %I nodetach nolog
+Restart=on-failure
+RestartSec=5s
+
+[Install]
+WantedBy=multi-user.target