SHA256
1
0
forked from pool/openvpn
openvpn/openvpn.init

161 lines
3.9 KiB
Plaintext
Raw Normal View History

#! /bin/sh
# Copyright (c) 2003 SuSE Linux AG
#
# Author: Peter Poeml <poeml@suse.de>
#
# inspired by the init script contributed to the OpenVPN project by
# Douglas Keller <doug@voidstar.dyndns.org>
#
# /etc/init.d/openvpn
# and its symbolic link
# /usr/sbin/rcopenvpn
#
### BEGIN INIT INFO
# Provides: openvpn
# Required-Start: $local_fs $remote_fs $network
# Should-Start: $syslog
# Required-Stop: $local_fs $remote_fs $network
# Should-Stop: $syslog
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: OpenVPN tunnel
# Description: Start OpenVPN tunnel
### END INIT INFO
# test -s /etc/sysconfig/openvpn && \
# . /etc/sysconfig/openvpn
DAEMON="OpenVPN"
openvpn=/usr/sbin/openvpn
confdir=/etc/openvpn
piddir=/var/run/openvpn
test -d $piddir || mkdir $piddir
test -x $openvpn || {
echo 1>&2 "$openvpn not installed"
if test "$1" == "stop" ; then exit 0 ; else exit 5 ; fi
}
# Shell functions sourced from /etc/rc.status:
# rc_check check and set local and overall rc status
# rc_status check and set local and overall rc status
# rc_status -v ditto but be verbose in local rc status
# rc_status -v -r ditto and clear the local rc status
# rc_failed set local and overall rc status to failed
# rc_failed <num> set local and overall rc status to <num><num>
# rc_reset clear local rc status (overall remains)
# rc_exit exit appropriate to overall rc status
. /etc/rc.status
# First reset status of this service
rc_reset
# Return values acc. to LSB for all commands but status:
# 0 - success
# 1 - generic or unspecified error
# 2 - invalid or excess argument(s)
# 3 - unimplemented feature (e.g. "reload")
# 4 - insufficient privilege
# 5 - program is not installed
# 6 - program is not configured
# 7 - program is not running
#
# Note that starting an already running service, stopping
# or restarting a not-running service as well as the restart
# with force-reload (in case signalling is not supported) are
# considered a success.
shopt -s nullglob
ret=true
case "$1" in
start)
echo -n "Starting $DAEMON "
/sbin/modprobe tun &>/dev/null
for conf in $confdir/*.conf; do
pidfile=$(basename ${conf%%.conf}).pid
startproc -p $piddir/$pidfile $openvpn --daemon \
--writepid $piddir/$pidfile \
--config $conf \
--cd $confdir \
|| ret=false
done
# Remember status and be verbose
$ret
rc_status -v
;;
stop)
echo -n "Shutting down $DAEMON "
## Stop daemon with killproc(8) and if this fails
## set echo the echo return value.
for i in $piddir/*.pid; do
killproc -p $i -TERM $openvpn || ret=false
done
# Remember status and be verbose
$ret
rc_status -v
;;
try-restart)
## Do a restart only if the service was active before.
## Note: try-restart is now part of LSB (as of 1.9).
## RH has a similar command named condrestart.
$0 status
if test $? = 0; then
$0 restart
else
rc_reset # Not running is not a failure.
fi
# Remember status and be quiet
rc_status
;;
restart)
## Stop the service and regardless of whether it was
## running or not, start it again.
$0 stop
sleep 3
$0 start
# Remember status and be quiet
rc_status
;;
reload)
for i in $piddir/*.pid; do
killproc -p $i -HUP $openvpn || ret=false
done
rc_status -v
;;
reopen)
for i in $piddir/*.pid; do
killproc -p $i -USR1 $openvpn || ret=false
done
rc_status -v
;;
status)
echo -n "Checking for $DAEMON: "
running=false
for i in $piddir/*.pid; do
running=true
killproc -p $i -USR2 $openvpn || { rv=$?; ret=false; }
done
if $running; then
$ret
rc_status -v
echo Status written to /var/log/messages
else
rc_failed 3
rc_status -v
fi
;;
*)
echo "Usage: $0 {start|stop|status|try-restart|restart|reload|reopen}"
exit 1
esac
rc_exit