4 # Required-Start: $network $named $syslog
6 # Default-Start: 2 3 4 5
8 # Short-Description: Start anycast tunneling daemon at boot time
9 # Description: Enables networking over vpn tunnel interfaces
11 PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
12 DAEMON=/usr/sbin/anytun
13 ANYTUNCONFIG=/usr/bin/anytun-config
14 CONTROLDAEMON=/usr/bin/anytun-controld
17 CONFIG_DIR=/etc/anytun
18 VARCONFIG_DIR=/var/run/anytun-controld
19 VARRUN_DIR=/var/run/anytun
21 test -x $DAEMON || exit 0
23 # Include anytun defaults if available
24 if [ -f /etc/default/anytun ] ; then
30 if [ -f $CONFIG_DIR/$NAME/config ] ; then
32 test -f $CONFIG_DIR/$NAME/post-up.sh && POSTUP="-x $CONFIG_DIR/$NAME/post-up.sh"
33 CHROOTDIR=`grep '^chroot' < $CONFIG_DIR/$NAME/config | sed 's/chroot\s*//'`
34 if [ -n "$CHROOTDIR" ] ; then
35 test -d $CHROOTDIR || mkdir -p $CHROOTDIR
37 test -d $VARRUN_DIR || mkdir -p $VARRUN_DIR
38 DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e '\w' | sed 's/^/--/' | tr '\n' ' '`
39 $DAEMON --write-pid $VARRUN_DIR/$NAME.pid $POSTUP \
40 $DAEMONOPTS $DAEMONARG || STATUS="FAILED"
42 STATUS="no config found"
48 kill `cat $PIDFILE` || true
54 if [ -d $CONFIG_DIR/$NAME/conf.d ] ; then
55 test -d $VARCONFIG_DIR || mkdir -p $VARCONFIG_DIR
56 chmod 700 $VARCONFIG_DIR
57 rm -f $VARCONFIG_DIR/$NAME 2>/dev/null
58 for CLIENTNAME in `ls $CONFIG_DIR/$NAME/conf.d`; do
59 echo -n " ($CLIENTNAME)"
60 DAEMONARG=`sed 's/#.*//' < $CONFIG_DIR/$NAME/conf.d/$CLIENTNAME | grep -e '\w' | sed 's/^/ --/' | xargs echo`
61 $ANYTUNCONFIG $DAEMONARG >> $VARCONFIG_DIR/$NAME
63 CONTROLHOST=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e 'control-host' | sed 's/^/ --/'`
64 $CONTROLDAEMON -f $VARCONFIG_DIR/$NAME $DAEMONOPTS $CONTROLHOST \
65 --write-pid $VARCONFIG_DIR/$NAME.pid
66 # rm -f $VARCONFIG_DIR/$NAME
70 if [ -d $CONFIG_DIR/$NAME/conf.d ] ; then
72 kill `cat $VARCONFIG_DIR/$NAME.pid` || true
73 rm $VARCONFIG_DIR/$NAME.pid
80 echo -n "Starting $DESC:"
81 if test -z "$2" ; then
82 if [ -f $CONFIG_DIR/autostart ] ; then
83 for NAME in `sed 's/#.*//' < $CONFIG_DIR/autostart | grep -e '\w'`; do
88 echo "no config found"
102 echo -n "Stoping $DESC:"
103 if test -z "$2" ; then
104 for PIDFILE in `ls $VARRUN_DIR/*.pid 2> /dev/null`; do
105 NAME=`echo $PIDFILE | cut -c17-`
113 if test -e $VARRUN_DIR/$1.pid ; then
114 PIDFILE=`ls $VARRUN_DIR/$1.pid 2> /dev/null`
115 NAME=`echo $PIDFILE | cut -c17-`
120 echo -n " (failure: No such tunnel is running: $1)"
127 echo -n "Reloading $DESC:"
128 if test -z "$2" ; then
129 for PIDFILE in `ls $VARRUN_DIR/*.pid 2> /dev/null`; do
130 NAME=`echo $PIDFILE | cut -c17-`
133 if [ -d $CONFIG_DIR/$NAME/conf.d ] ; then
144 if test -e $VARRUN_DIR/$1.pid ; then
145 PIDFILE=`ls $VARRUN_DIR/$1.pid 2> /dev/null`
146 NAME=`echo $PIDFILE | cut -c17-`
149 if [ -d $CONFIG_DIR/$NAME/conf.d ] ; then
157 echo -n " (failure: No such tunnel is running: $1)"
164 echo -n "Restarting $DESC:"
165 if test -z "$2" ; then
166 for PIDFILE in `ls $VARRUN_DIR/*.pid 2> /dev/null`; do
167 NAME=`echo $PIDFILE | cut -c17-`
177 if test -e $VARRUN_DIR/$1.pid ; then
178 PIDFILE=`ls $VARRUN_DIR/$1.pid 2> /dev/null`
179 NAME=`echo $PIDFILE | cut -c17-`
186 echo -n " (failure: No such tunnel is running: $1)"
201 echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2