3 # tinc tincd VPN setup script
5 # chkconfig: 2345 46 54
8 # authors: Lubomir Bulej <pallas@kadan.cz>
9 # Mads Kiilerich <mads@kiilerich.com>
11 # description: This script parses tinc configuration files for networks given \
12 # in /etc/tinc/nets.boot and for each of the networks it sets up \
13 # the interface and static routes and starts the tinc daemon.
17 # Source function library.
18 . /etc/rc.d/init.d/functions
20 # Source networking configuration.
21 . /etc/sysconfig/network
23 # Check that networking is up.
24 [ ${NETWORKING} = "no" ] && exit 0
26 #############################################################################
27 # configuration & sanity checks
34 NETSFILE=$TCONF/nets.boot
37 if [ ! -x $TINCD ]; then
38 echo "**tinc: $TINCD does not exist or is not executable!" >&2
42 # Check the configuration directory
43 if [ ! -d $TCONF ]; then
44 echo "**tinc: configuration directory ($TCONF) not found!" >&2
49 if [ ! -f $NETSFILE ]; then
50 echo "**tinc: file with list of VPNs to start ($NETSFILE) not found!" >&2
54 # Load names of networks to be started
55 NETS="$(sed -e 's/#.*//; s/[[:space:]]//g; /^$/ d' $NETSFILE)"
58 ##############################################################################
59 # vpn_start () starts specified VPN
65 $TINCD --net="$1" $DEBUG || \
66 { MSG="could not start daemon for network $1"; return 3; }
71 ##############################################################################
72 # vpn_stop () Stops specified VPN
77 # kill the tincd daemon
78 PID="$TPIDS/tinc.$1.pid"
80 $TINCD --net="$1" --kill &> /dev/null
83 if [ $RET -eq 0 ]; then
85 while [ $dly -le 5 ]; do
87 sleep 1; dly=$((dly + 1))
91 # remove stale PID file
92 [ -f $PID ] && rm -f $PID
98 # Check if there is anything to start
99 if [ ! -z "$1" -a "$1" != "status" -a -z "$NETS" ]; then
100 echo "**tinc: no networks found in $NETSFILE!" >&2
105 # See how we were called.
109 echo -n "Bringing up TINC network $vpn: "
111 success "startup of network $vpn" || \
112 failure "startup of network $vpn"
115 if [ ! -z "$MSG" ]; then
116 [ ! -z "$ERR" ] && echo "$ERR" >&2
117 echo "**tinc: $MSG" >&2
121 touch /var/lock/subsys/tinc
126 echo -n "Shutting down TINC network $vpn: "
128 success "shutdown of network $vpn" || \
129 failure "shutdown of network $vpn"
132 if [ ! -z "$MSG" ]; then
133 [ ! -z "$ERR" ] && echo "$ERR" >&2
134 echo "**tinc: $MSG" >&2
138 rm -f /var/lock/subsys/tinc
142 echo -n "Configured VPNs: "
144 PID="$TPIDS/tinc.$vpn.pid"
146 [ -f $PID ] && PID="$(cat $PID)" || PID="-dead-"
147 ps ax | grep "^[[:space:]]*$PID" && STS="OK" || STS="DEAD"
159 echo "Usage: tinc {start|stop|status|restart}"