summaryrefslogtreecommitdiff
path: root/src/op_mode
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2020-04-12 12:15:41 +0200
committerChristian Poessinger <christian@poessinger.com>2020-04-12 12:16:18 +0200
commit3411d1b3864390ba441327eb35b1fa46869c8263 (patch)
treeb192d8b1475fd5968444ead19d86c788cea8078e /src/op_mode
parentcc4be2ccd72b1d48f9cd37c54b151cdf3217a9d1 (diff)
downloadvyos-1x-3411d1b3864390ba441327eb35b1fa46869c8263.tar.gz
vyos-1x-3411d1b3864390ba441327eb35b1fa46869c8263.zip
op-mode: openvpn: T2273: migrate from SysVinit to systemd
Diffstat (limited to 'src/op_mode')
-rwxr-xr-xsrc/op_mode/reset_openvpn.py61
1 files changed, 11 insertions, 50 deletions
diff --git a/src/op_mode/reset_openvpn.py b/src/op_mode/reset_openvpn.py
index 618cad5ea..dbd3eb4d1 100755
--- a/src/op_mode/reset_openvpn.py
+++ b/src/op_mode/reset_openvpn.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
#
-# Copyright (C) 2018 VyOS maintainers and contributors
+# Copyright (C) 2018-2020 VyOS maintainers and contributors
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 or later as
@@ -14,57 +14,18 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-import sys
import os
-
-from time import sleep
-from netifaces import interfaces
-from vyos.util import process_running, cmd
-
-def get_config_name(intf):
- cfg_file = r'/opt/vyatta/etc/openvpn/openvpn-{}.conf'.format(intf)
- return cfg_file
-
-def get_pid_file(intf):
- pid_file = r'/var/run/openvpn/{}.pid'.format(intf)
- return pid_file
-
+from sys import argv, exit
+from vyos.util import call
if __name__ == '__main__':
- if (len(sys.argv) < 1):
- print("Must specify OpenVPN interface name!")
- sys.exit(1)
-
- interface = sys.argv[1]
- if os.path.isfile(get_config_name(interface)):
- pidfile = '/var/run/openvpn/{}.pid'.format(interface)
- if process_running(pidfile):
- command = 'start-stop-daemon'
- command += ' --stop'
- command += ' --oknodo'
- command += ' --quiet'
- command += ' --pidfile ' + pidfile
- cmd(command)
-
- # When stopping OpenVPN we need to wait for the 'old' interface to
- # vanish from the Kernel, if it is not gone, OpenVPN will report:
- # ERROR: Cannot ioctl TUNSETIFF vtun10: Device or resource busy (errno=16)
- while interface in interfaces():
- sleep(0.250) # 250ms
-
- # re-start OpenVPN process
- command = 'start-stop-daemon'
- command += ' --start'
- command += ' --oknodo'
- command += ' --quiet'
- command += ' --pidfile ' + get_pid_file(interface)
- command += ' --exec /usr/sbin/openvpn'
- # now pass arguments to openvpn binary
- command += ' --'
- command += ' --daemon openvpn-' + interface
- command += ' --config ' + get_config_name(interface)
+ if (len(argv) < 1):
+ print('Must specify OpenVPN interface name!')
+ exit(1)
- cmd(command)
+ interface = argv[1]
+ if os.path.isfile(f'/run/openvpn/{interface}.conf'):
+ call(f'systemctl restart openvpn@{interface}.service')
else:
- print("OpenVPN interface {} does not exist!".format(interface))
- sys.exit(1)
+ print(f'OpenVPN interface "{interface}" does not exist!')
+ exit(1)