#!/sbin/runscript VPNDIR="/etc/openvpn" depend() { need net } checktundevice() { if [ -h /dev/net/tun ] && [ -c /dev/misc/net/tun ]; then ebegin Detected broken /dev/net/tun symlink, fixing... rm /dev/net/tun ln -s /dev/misc/net/tun /dev/net/tun eend $? fi } start() { checktundevice || return 1 cd ${VPNDIR} for VPN in * do if [ -d ${VPN} ] && [ -e ${VPN}/local.conf ]; then if [ -f ${VPN}/onlinecheck ]; then ping -c 3 `head -n 1 ${VPN}/onlinecheck` >& /dev/null else false fi if [ $? -gt 0 ]; then ebegin "Starting openvpn for ${VPN}" start-stop-daemon --start --pidfile /var/run/openvpn-${VPN}.pid \ --startas /usr/sbin/openvpn -- --config ${VPN}/local.conf \ --writepid /var/run/openvpn-${VPN}.pid \ --daemon --cd ${VPN} eend $? else einfo "Connection ${VPN} already online. Skipping..." fi else ewarn "Expected ${VPNDIR}/${VPN} to be a directory containing a local.conf." fi done } stop() { cd ${VPNDIR} for VPN in * do if [ -e /var/run/openvpn-${VPN}.pid ]; then ebegin "Stopping openvpn for ${VPN}" start-stop-daemon --oknodo --stop --pidfile /var/run/openvpn-${VPN}.pid rm /var/run/openvpn-${VPN}.pid eend 0 else ewarn "${VPN} has no pidfile!" fi done return 0 }