summaryrefslogtreecommitdiff
path: root/src/conf_mode/vpn_sstp.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/vpn_sstp.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/vpn_sstp.py')
-rwxr-xr-xsrc/conf_mode/vpn_sstp.py12
1 files changed, 3 insertions, 9 deletions
diff --git a/src/conf_mode/vpn_sstp.py b/src/conf_mode/vpn_sstp.py
index 8e5c7587c..070437443 100755
--- a/src/conf_mode/vpn_sstp.py
+++ b/src/conf_mode/vpn_sstp.py
@@ -23,9 +23,9 @@ from subprocess import Popen, PIPE, check_output
from socket import socket, AF_INET, SOCK_STREAM
from copy import deepcopy
from stat import S_IRUSR, S_IWUSR, S_IRGRP
-from psutil import pid_exists
from vyos.config import Config
+from vyos.util import process_running
from vyos import ConfigError
pidfile = r'/var/run/accel_sstp.pid'
@@ -489,14 +489,8 @@ def generate(sstp):
return sstp
def apply(sstp):
- pid = 0
- if os.path.isfile(pidfile):
- pid = 0
- with open(pidfile, 'r') as f:
- pid = int(f.read())
-
if sstp is None:
- if pid_exists(pid):
+ if process_running(pidfile):
cmd = 'start-stop-daemon'
cmd += ' --stop '
cmd += ' --quiet'
@@ -509,7 +503,7 @@ def apply(sstp):
return None
- if not pid_exists(pid):
+ if not process_running(pidfile):
if os.path.exists(pidfile):
os.remove(pidfile)