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
15 CHROOTDIR
='/var/run/anytun'
16 # DAEMONOPTS="--chroot --username nobody --chroot-dir $CHROOTDIR"
19 CONFIG_DIR
=/etc
/anytun
20 VARCONFIG_DIR
=/var
/run
/anytun-controld
22 test -x $DAEMON ||
exit 0
24 # Include anytun defaults if available
25 if [ -f /etc
/default
/anytun
] ; then
31 if [ -f $CONFIG_DIR/$NAME/config
] ; then
33 test -f $CONFIG_DIR/$NAME/post-up.sh
&& POSTUP
="-x $CONFIG_DIR/$NAME/post-up.sh"
34 DAEMONARG
=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e '\w' | sed 's/^/ --/' | xargs echo`
35 $DAEMON --write-pid /var
/run
/anytun.
$NAME.pid
$POSTUP \
36 $DAEMONOPTS $DAEMONARG || STATUS
="FAILED"
38 STATUS
="no config found"
44 kill `cat $PIDFILE` || true
50 if [ -d $CONFIG_DIR/$NAME/conf.d
] ; then
51 test -d $VARCONFIG_DIR || mkdir
-p $VARCONFIG_DIR
52 chmod 700 $VARCONFIG_DIR
53 rm -f $VARCONFIG_DIR/$NAME 2>/dev
/null
54 for CLIENTNAME
in `ls $CONFIG_DIR/$NAME/conf.d`; do
55 echo -n " ($CLIENTNAME)"
56 DAEMONARG
=`sed 's/#.*//' < $CONFIG_DIR/$NAME/conf.d/$CLIENTNAME | grep -e '\w' | sed 's/^/ --/' | xargs echo`
57 $ANYTUNCONFIG $DAEMONARG >> $VARCONFIG_DIR/$NAME
59 CONTROLHOST
=`sed 's/#.*//' < $CONFIG_DIR/$NAME/config | grep -e 'control-host' | sed 's/^/ --/'`
60 $CONTROLDAEMON -f $VARCONFIG_DIR/$NAME $DAEMONOPTS $CONTROLHOST \
61 --write-pid $VARCONFIG_DIR/$NAME.pid
62 # rm -f $VARCONFIG_DIR/$NAME
66 if [ -d $CONFIG_DIR/$NAME/conf.d
] ; then
68 kill `cat $VARCONFIG_DIR/$NAME.pid` || true
69 rm $VARCONFIG_DIR/$NAME.pid
76 echo -n "Starting $DESC: "
77 test -d $CHROOTDIR || mkdir
-p $CHROOTDIR
78 if test -z "$2" ; then
79 if [ -f $CONFIG_DIR/autostart
] ; then
80 for NAME
in `sed 's/#.*//' < $CONFIG_DIR/autostart | grep -e '\w'`; do
85 echo "no config found"
100 echo -n "Stoping $DESC: "
101 if test -z "$2" ; then
102 for PIDFILE
in `ls /var/run/anytun.*.pid 2> /dev/null`; do
103 NAME
=`echo $PIDFILE | cut -c17-`
111 if test -e /var
/run
/anytun.
$1.pid
; then
112 PIDFILE
=`ls /var/run/anytun.$1.pid 2> /dev/null`
113 NAME
=`echo $PIDFILE | cut -c17-`
118 echo -n " (failure: No such tunnel is running: $1)"
125 if test -z "$2" ; then
126 for PIDFILE
in `ls /var/run/anytun.*.pid 2> /dev/null`; do
127 NAME
=`echo $PIDFILE | cut -c17-`
129 if [ -d $CONFIG_DIR/$NAME/conf.d
] ; then
141 if test -e /var
/run
/anytun.
$1.pid
; then
142 PIDFILE
=`ls /var/run/anytun.$1.pid 2> /dev/null`
143 NAME
=`echo $PIDFILE | cut -c17-`
146 if [ -d $CONFIG_DIR/$NAME/conf.d
] ; then
154 echo -n " (failure: No such tunnel is running: $1)"
160 echo -n "Restarting $DESC: "
161 if test -z "$2" ; then
162 for PIDFILE
in `ls /var/run/anytun.*.pid 2> /dev/null`; do
163 NAME
=`echo $PIDFILE | cut -c17-`
173 if test -e /var
/run
/anytun.
$1.pid
; then
174 PIDFILE
=`ls /var/run/anytun.$1.pid 2> /dev/null`
175 NAME
=`echo $PIDFILE | cut -c17-`
181 echo -n " (failure: No such tunnel is running: $1)"
196 echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2