From 35e0254622f8f099db3c7829cd61b85f6976c416 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Sun, 29 Mar 2020 15:46:12 +0200 Subject: 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(). --- src/conf_mode/vpn_sstp.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'src/conf_mode/vpn_sstp.py') 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) -- cgit v1.2.3