User Tools

Site Tools


scripts:perl:ping_check_openvpn.pl

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

scripts:perl:ping_check_openvpn.pl [2014/09/07 19:12] (current)
Thomas York created
Line 1: Line 1:
 +<file perl ping_check_openvpn.pl>​
 +#​!/​usr/​bin/​perl
 +#
 +# Written by Thomas York
 +# Written to restart OpenVPN when pinging fails
 +# REQUIRED PACKAGES : p5-net-ping
 +#
  
 +$|=1;
 +use Net::Ping;
 +use POSIX qw/​strftime/;​
 +use strict;
 +
 +###################​
 +# <​CONFIGURATION>​ #
 +###################​
 +
 +# Ping destination
 +my $ping_dst = "​8.8.8.8";​
 +
 +# Timeout (in seconds)
 +my $timeout = 5;
 +
 +####################​
 +# </​CONFIGURATION>​ #
 +####################​
 +
 +# Main program execution
 +
 +# Create new ping object
 +my $objPing = Net::​Ping->​new("​icmp"​);​
 +
 +# Continully ping
 +while () {
 +
 +        # Ping!
 +        if ($objPing->​ping($ping_dst,​ $timeout)) {
 +
 +                # Host is alive
 +                # print "DEBUG : "​.$ping_dst."​ is alive.\n";​
 +
 +        } else {
 +
 +                # Host is dead
 +                # print "DEBUG : "​.$ping_dst."​ is dead.\n";​
 +
 +                # Restart OpenVPN
 +                system("​service",​ "​openvpn",​ "​restart"​);​
 +
 +                # Wait 15 seconds, to allow routing to come up
 +                sleep 15;
 +        }
 +
 +        # Wait for 5 seconds before looping back around
 +        sleep 5;
 +
 +}
 +</​file>​
/var/www/vhost/www.fuhell.com/data/pages/scripts/perl/ping_check_openvpn.pl.txt · Last modified: 2014/09/07 19:12 by Thomas York