#!/sbin/runscript VPNDIR="/etc/openvpn" VPNCONFS=`ls ${VPNDIR}/*.conf` depend() { need net } checktundevice() { if [[ ! -e /dev/net/tun ]]; then if ! modprobe tun ; then eerror "TUN/TAP support is not available in this kernel" return 1 fi fi if [[ -h /dev/net/tun && -c /dev/misc/net/tun ]]; then ebegin "Detected broken /dev/net/tun symlink, fixing..." rm -f /dev/net/tun ln -s /dev/misc/net/tun /dev/net/tun eend $? fi } start() { checktundevice || return 1 for vpn in ${VPNCONFS} do VPN=`basename ${vpn} .conf` ebegin "Starting ${myservice} for ${VPN}" if [[ ! -e "${vpn}" ]]; then eend 1 "${vpn} does not exist" return 1 fi VPNPID="/var/run/openvpn.${VPN}.pid" start-stop-daemon --start --exec /usr/sbin/openvpn --pidfile "${VPNPID}" \ -- --config "${vpn}" --writepid "${VPNPID}" \ --daemon eend $? "Check your logs to see why startup failed" done } stop() { VPNPIDS=`ls /var/run/openvpn.*.pid` for vpnpid in ${VPNPIDS} do VPN=`basename ${vpnpid} .pid | sed -e 's/openvpn\.//g'` ebegin "Stopping ${myservice} for ${VPN}" start-stop-daemon --stop --exec /usr/sbin/openvpn --pidfile "${vpnpid}" eend $? done } # vim: ts=4