summaryrefslogtreecommitdiff
path: root/src/op_mode
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/op_mode
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/op_mode')
-rwxr-xr-xsrc/op_mode/reset_openvpn.py21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/op_mode/reset_openvpn.py b/src/op_mode/reset_openvpn.py
index 176cd51cf..4c29fbbba 100755
--- a/src/op_mode/reset_openvpn.py
+++ b/src/op_mode/reset_openvpn.py
@@ -17,10 +17,10 @@
import sys
import os
-from psutil import pid_exists
from subprocess import Popen, PIPE
from time import sleep
from netifaces import interfaces
+from vyos.util import process_running
def get_config_name(intf):
cfg_file = r'/opt/vyatta/etc/openvpn/openvpn-{}.conf'.format(intf)
@@ -42,18 +42,13 @@ if __name__ == '__main__':
interface = sys.argv[1]
if os.path.isfile(get_config_name(interface)):
pidfile = '/var/run/openvpn/{}.pid'.format(interface)
- if os.path.isfile(pidfile):
- pid = 0
- with open(pidfile, 'r') as f:
- pid = int(f.read())
-
- if pid_exists(pid):
- cmd = 'start-stop-daemon'
- cmd += ' --stop'
- cmd += ' --oknodo'
- cmd += ' --quiet'
- cmd += ' --pidfile ' + pidfile
- subprocess_cmd(cmd)
+ if process_running(pidfile):
+ cmd = 'start-stop-daemon'
+ cmd += ' --stop'
+ cmd += ' --oknodo'
+ cmd += ' --quiet'
+ cmd += ' --pidfile ' + pidfile
+ subprocess_cmd(cmd)
# When stopping OpenVPN we need to wait for the 'old' interface to
# vanish from the Kernel, if it is not gone, OpenVPN will report: