#!/bin/bash . /etc/rc.conf . /etc/rc.d/functions CFGDIR="/etc/openvpn" STATEDIR="/var/run/openvpn" SVCNAME="$(basename $0)" case "$1" in start) stat_busy "Starting OpenVPN ... " success=0 mkdir -p "${STATEDIR}" cfg="${SVCNAME#*.}.conf" stat_append "$(basename "${cfg}" .conf) " /usr/sbin/openvpn --daemon --writepid "${STATEDIR}"/"$(basename "${cfg}" .conf)".pid --cd "${CFGDIR}" --config "${cfg}" || success=$? if [ $success -eq 0 ]; then add_daemon $SVCNAME stat_done else stat_fail fi ;; stop) stat_busy "Stopping OpenVPN ..." pidfile="${STATEDIR}"/"${SVCNAME#*.}.pid" stat_append "${pidfile#.*} " kill $(cat "${pidfile}" 2>/dev/null) 2>/dev/null rm -f "${pidfile}" rm_daemon ${SVCNAME} stat_done ;; restart) $0 stop sleep 1 $0 start ;; status) stat_busy "Checking $SVCNAME status"; ck_status $SVCNAME ;; *) echo "usage: $0 {start|stop|restart|status}" esac exit 0