#!/bin/bash # source application-specific settings OPENVPN_ARGS= [ -f /etc/conf.d/openvpn ] && . /etc/conf.d/openvpn . /etc/rc.conf . /etc/rc.d/functions PID=`pidof -o %PPID /usr/sbin/openvpn` case "$1" in start) stat_busy "Starting OpenVPN Daemon" [ -z "$PID" ] && /usr/sbin/openvpn ${OPENVPN_ARGS} if [ $? -gt 0 ]; then stat_fail else # Bring up any TAP interfaces for tap in "${OPENVPN_TAP[@]}"; do # Gracefully fail when the tunnel already exists. This allows # stopping and starting openvpn without the client connections # resetting. /usr/sbin/openvpn --mktun --dev $tap 2> /dev/null done add_daemon openvpn stat_done fi ;; stop) stat_busy "Stopping OpenVPN Daemon" [ ! -z "$PID" ] && kill $PID &> /dev/null if [ $? -gt 0 ]; then stat_fail else for tap in "${OPENVPN_TAP[@]}"; do /sbin/ifconfig $tap down /usr/sbin/openvpn --rmtun --dev $tap if [ $? -gt 0 ]; then stat_fail fi done rm_daemon openvpn stat_done fi ;; restart) $0 stop sleep 1 $0 start ;; *) echo "usage: $0 {start|stop|restart}" esac exit 0