chiark / gitweb /
General overhaul of tunnelling: allow multiple tunnel drivers in one daemon,
[tripe] / tripe-init.in
index db9cb35f63351eaf0e2aa60ddf5a811696d69c03..b4c5e6d7336a10d35b857f96e887cb85155fce5e 100755 (executable)
@@ -10,18 +10,26 @@ set -e
 [ -f @initconfig@ ] && . @initconfig@
 : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
 : ${bindir=@bindir@} ${sbindir=@sbindir@}
-: ${TRIPEDIR=@configdir@}
+: ${TRIPEDIR=@configdir@} ${tripesock=@socketdir@/tripesock}
+: ${pidfile=@pidfile@}
 : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
 PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
 export PATH TRIPEDIR
 
+# --- Give up if there's no key ---
+
+if test ! -f $TRIPEDIR/keyring || test ! -f $TRIPEDIR/keyring.pub; then
+  echo >&2 "Not starting/stopping TrIPE: keyring files missing"
+  exit 0
+fi
+
 # --- Check it will work, or at least stands a fighting chance ---
 #
 # Having loads of different tunnel types doesn't help any.
 
 test -x $tripe -a -x $tripectl || exit 0
 
-case `$tripe --tunnel` in
+case ${tunnel-`$tripe --tunnels | head -1`} in
   linux)
     case `uname -s` in
       Linux)
@@ -91,6 +99,12 @@ case `$tripe --tunnel` in
        ;;
     esac
     ;;
+  slip)
+    if test "$TRIPE_SLIPIF" = ""; then
+      echo >&2 "$tripe needs SLIP interfaces set up!"
+      exit 1
+    fi
+    ;;
 esac
   
 # --- Do what was wanted ---
@@ -98,18 +112,20 @@ esac
 case "$1" in
   start)
     echo -n "Starting TrIPE VPN daemon:"
-    if $tripectl help >/dev/null 2>/dev/null; then
+    if $tripectl version >/dev/null 2>/dev/null; then
       echo " already running"
       exit 0
     fi
     $tripectl -D -s -p$tripe \
       -f${logfile-@logfile@} \
-      -P${pidfile-@pidfile@} \
+      -P$pidfile \
+      ${keytag+-S-t}$keytag \
       ${addr+-S-b}$addr \
       ${port+-S-p}${port} \
       ${user+-S-u}${user} \
       ${group+-S-g}${group} \
       ${trace+-S-T}${trace} \
+      ${tunnel+-S-n}${tunnel} \
       ${miscopts}
     for i in 1 2 3 4 give-up; do
       $tripectl help >/dev/null 2>/dev/null && break
@@ -134,8 +150,19 @@ case "$1" in
     ;;
   stop)
     echo -n "Stopping TrIPE VPN daemon:"
-    $tripectl quit
-    echo " done"
+    if test ! -S $tripesock; then
+      echo " not running"
+    elif $tripectl quit >/dev/null 2>&1; then
+      echo " done"
+    elif test ! -f $pidfile; then
+      echo " stale socket found: removing"
+      rm -f $tripesock
+    elif kill `cat $pidfile`; then
+      echo " done (killed violently)"
+    else
+      echo " it doesn't want do die!"
+      exit 1
+    fi
     ;;
   status)
     for i in `$tripectl list`; do