User Tools

Site Tools


Sidebar


guides:unix_admin:vpnc

vpnc

Vpnc scripts that work in Centos 5.x

vpnc init script

Create /etc/init.d/vpnc with following:

#!/bin/sh
#
# vpnc  Control the vpnc service.
#
# chkconfig: 2345 90 10
# description: init script for vpnc
# config:
# pidfile: /var/run/vpnc/pid


# Source function library.
. /etc/init.d/functions

RETVAL=0
PIDFILE=/var/run/vpnc/pid

case "$1" in
  start)
        echo -n "Starting VPNC connection: "
        /sbin/vpnc /etc/vpnc/theplanet.conf
        echo
        ;;
  stop)
        echo -n "Stopping VPNC connection: "
        if [ -f $PIDFILE ]; then
           PID=$(cat $PIDFILE)
           kill $PID
           while [ -d /proc/$PID ];
           do
                sleep 1
           done
        fi
        echo
        ;;
  restart|reload)
        $0 stop
        $0 start
        ;;
  *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
esac

Make script executable

chmod +x /etc/init.d/vpnc

vpnc-keepalive script

Create /usr/bin/vpnc-keepalive and add following

#!/bin/sh
#
# vpnc-keepalive
#
# Restart VPNC if one of the specified hosts is unavailable
#
# Usage: /usr/bin/vpnc-keepalive <host1 ip> [host2 ip]
#

if [ $(ping -q -c 1 ${1} 2>&1 | grep "1 packets transmitted" | sed "s/.*\(1\) received.*/\1/") ] ||
   [ $(ping -q -c 1 ${2} 2>&1 | grep "1 packets transmitted" | sed "s/.*\(1\) received.*/\1/") ]; then
   echo Alive $1 or $2
else
   echo Not alive $1 or $2, restarting VPNC
   /etc/init.d/vpnc restart
fi

Make script executable

chmod +x /usr/bin/vpnc-keepalive

cron entry to keepalive

Add to /etc/crontab

# check every minute - keep vpnc link alive
*/1 * * * *   root   /usr/bin/vpnc-keepalive HOST1 HOST2

References

https://forum.openwrt.org/viewtopic.php?id=13980

guides/unix_admin/vpnc.txt · Last modified: 2010/07/07 23:54 by michaelc