#!/bin/sh
#
# tincd - A virtual private network daemon
#
# chkconfig:   - 24 76
# description: tinc is a Virtual Private Network (VPN) daemon \
#              that uses tunnelling and encryption to create a \
#              secure private network between hosts on the \
#              Internet. Because the tunnel appears to the IP \
#              level network code as a normal network device, \
#              there is no need to adapt any existing software. \
#              This tunnelling allows VPN sites to share \
#              information with each other over the Internet \
#              without exposing any information to others.

# http://fedoraproject.org/wiki/FCNewInit/Initscripts
### BEGIN INIT INFO
# Provides: tincd
# Required-Start: $network
# Required-Stop: $network
# Short-Description: start and stop tincd
# Description: tinc is a Virtual Private Network (VPN) daemon \
#              that uses tunnelling and encryption to create a \
#              secure private network between hosts on the \
#              Internet. Because the tunnel appears to the IP \
#              level network code as a normal network device, \
#              there is no need to adapt any existing software. \
#              This tunnelling allows VPN sites to share \
#              information with each other over the Internet \
#              without exposing any information to others.
### END INIT INFO

# Source function library.
. /etc/rc.d/init.d/functions

exec="/usr/sbin/tincd"
prog="tincd"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

lockfile=/var/lock/subsys/$prog

start() {
    echo -n $"Starting $prog: "
    /sbin/modprobe tun
    daemon $exec -n $NETNAME -D
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() {
    echo -n $"Stopping $prog: "
    killproc $prog
    /sbin/rmmod tun
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}

restart() {
    stop
    start
}

case "$1" in
    start|stop|restart)
        $1
        ;;
    force-reload)
        restart
        ;;
    status)
        status $prog
        ;;
    try-restart|condrestart)
        if status $prog >/dev/null ; then
            restart
        fi
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|try-restart|force-reload}"
        exit 2
esac
