OpenVPN Linux auto-restart: Difference between revisions

From EnigmaGuy Wiki
Jump to navigation Jump to search
(Created page with "== Intro == There are basically two files to install on linux * openvpn-restart.service * restart_openvpn.py You can get these files from [https://github.com/koss822/misc/tre...")
 
No edit summary
 
Line 4: Line 4:
* restart_openvpn.py
* restart_openvpn.py


You can get these files from [https://github.com/koss822/misc/tree/master/openvpn/restart/linux Github.com]
You can get these files from [https://github.com/koss822/misc/tree/master/Linux/Projects/openvpn/restart/linux Github.com]


Propably interesting is how these scripts works
Propably interesting is how these scripts works

Latest revision as of 13:01, 24 January 2019

Intro

There are basically two files to install on linux

  • openvpn-restart.service
  • restart_openvpn.py

You can get these files from Github.com

Propably interesting is how these scripts works

#!/usr/bin/env python3
import os,time
def reachable():
    for i in range(0,3):
        time.sleep(60)
        if os.system('ping -c1 YOUR_VPN_SERVER_PRIVATE_IP 2>&1 > /dev/null') == 0:
            print('ping succesfull')
            return True
        print('host unreachable')
    return False



while(True):
    if reachable():
        continue
    print('restarting openvpn')
    os.system('systemctl restart openvpn@YOUR_CONFIG_NAME.service')

How to set-up

  1. Replace YOUR_VPN_SERVER_PRIVATE_IP with your OpenVPN gateway IP - this IP is permanently pinged and if it goes down openvpn process is restarted
  2. Replace YOUR_CONFIG_NAME with name of your openvpn client config in /etc/openvpn, e.g. /etc/openvpn/client.conf means CLIENT as YOUR_CONFIG_NAME