Community discussions

MikroTik App
 
Admire
just joined
Topic Author
Posts: 4
Joined: Tue Dec 08, 2009 1:36 pm

OpenVPN restart script

Thu Sep 09, 2010 11:45 am

Hi,

I have the following situation. 2 lines - main and backup. 2 default gateways - backup with larger metrics. It works well, but I have an OpenVPN client which does not restart when changing from main to backup line. So I basically need script to watch if the backup is on then to restart the OpenVPN interface and wait for the main line to become available again then restart the OpenVPN again. Can anyone give me an example or something?
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7199
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: OpenVPN restart script

Thu Sep 09, 2010 11:46 am

You can also adjust OVPN keepalive timeouts.
 
Admire
just joined
Topic Author
Posts: 4
Joined: Tue Dec 08, 2009 1:36 pm

Re: OpenVPN restart script

Thu Sep 09, 2010 11:52 am

I tried the idle timeout setting, but the timeout timer resets everytime someone tries to push traffic through the vpn, so it's no use. And I don't want the vpn to disconnect when there is no need
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7199
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: OpenVPN restart script

Thu Sep 09, 2010 12:00 pm

well then you can simply check gateway status and disable/enable ovpn interface

Add comments to routes for example "main" and "backup"

{
:if ([/ip route get [find comment="backup"] active] != false) do={
:local id [/interface ovpn-client find name="ovpn-name"];
/interface ovpn-client disable $id;
/interface ovpn-client enable $id;
}
 
Admire
just joined
Topic Author
Posts: 4
Joined: Tue Dec 08, 2009 1:36 pm

Re: OpenVPN restart script

Thu Sep 09, 2010 12:24 pm

Thanks, I think that will work.
I'll write 2 similar scripts - one to check if backup is on and restart the VPN and one to check if main is on and restart the VPN. The second one will be disabled in scheduler. When the first one executes it will disable itself and enable the second one and vice versa.
 
User avatar
mrz
MikroTik Support
MikroTik Support
Posts: 7199
Joined: Wed Feb 07, 2007 12:45 pm
Location: Latvia
Contact:

Re: OpenVPN restart script

Thu Sep 09, 2010 12:26 pm

Also add some kind of check whether vpn is already restarted once after gateway change otherwise ovpn interface will be disabled/enabled every x interval