summaryrefslogtreecommitdiff
path: root/src/conf_mode/interfaces-openvpn.py
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-03-29 15:46:12 +0200
committerChristian Poessinger <christian@poessinger.com>2020-03-29 15:46:12 +0200
commit35e0254622f8f099db3c7829cd61b85f6976c416 (patch)
tree77014e7562e26edf4f0561a79c72babcdf52df14 /src/conf_mode/interfaces-openvpn.py
parent552106b0fb27003e5e5be5494f2213f54a699b9e (diff)
downloadvyos-1x-35e0254622f8f099db3c7829cd61b85f6976c416.tar.gz
vyos-1x-35e0254622f8f099db3c7829cd61b85f6976c416.zip
vyos.util: increase usage of process_running() and remove duplicated code
OpenVPN, WIFI, SSTP all had the same boiler plate copied about checking if a process associated with a pidfile is running or not. This has been migrated to the common library function vyos.util.process_running().
Diffstat (limited to 'src/conf_mode/interfaces-openvpn.py')
-rwxr-xr-xsrc/conf_mode/interfaces-openvpn.py9
1 files changed, 2 insertions, 7 deletions
diff --git a/src/conf_mode/interfaces-openvpn.py b/src/conf_mode/interfaces-openvpn.py
index 17aa4697f..fb2d6e6d9 100755
--- a/src/conf_mode/interfaces-openvpn.py
+++ b/src/conf_mode/interfaces-openvpn.py
@@ -24,7 +24,6 @@ from stat import S_IRUSR,S_IRWXU,S_IRGRP,S_IXGRP,S_IROTH,S_IXOTH
from grp import getgrnam
from ipaddress import ip_address,ip_network,IPv4Interface
from netifaces import interfaces
-from psutil import pid_exists
from pwd import getpwnam
from subprocess import Popen, PIPE
from time import sleep
@@ -33,6 +32,7 @@ from shutil import rmtree
from vyos import ConfigError
from vyos.config import Config
from vyos.ifconfig import VTunIf
+from vyos.util import process_running
from vyos.validate import is_addr_assigned
user = 'openvpn'
@@ -977,17 +977,12 @@ def generate(openvpn):
return None
def apply(openvpn):
- pid = 0
pidfile = '/var/run/openvpn/{}.pid'.format(openvpn['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
- if pid_exists(pid):
+ if process_running(pidfile):
cmd = 'start-stop-daemon'
cmd += ' --stop '
cmd += ' --quiet'