chiark / gitweb /
contrib: Add the Maemo init config for upstart.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 16 Mar 2012 00:01:55 +0000 (00:01 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 16 Mar 2012 00:19:43 +0000 (00:19 +0000)
contrib/Makefile.am
contrib/README
contrib/tripe-upstart.in [new file with mode: 0644]

index 5d71313..8802b62 100644 (file)
@@ -43,4 +43,13 @@ ipif-peers: ipif-peers.in Makefile
        $(SUBST) $(srcdir)/ipif-peers.in >$@.new $(SUBSTITUTIONS) && \
                mv $@.new $@
 
+## Upstart fragment.  This forks with Maemo's ancient upstart.
+noinst_DATA            += tripe-upstart
+EXTRA_DIST             += tripe-upstart.in
+CLEANFILES             += tripe-upstart
+
+tripe-upstart: tripe-upstart.in Makefile
+       $(SUBST) $(srcdir)/tripe-upstart.in >$@.new $(SUBSTITUTIONS) && \
+               mv $@.new $@
+
 ###----- That's all, folks --------------------------------------------------
index c055145..deeba1f 100644 (file)
@@ -8,3 +8,8 @@ What is there?
 tripe-ipif
 ipif-peers
        Glue for attaching tripe to Ian Jackson's `userv-ipif' service.
+
+tripe-upstart
+       A configuration fragmwnt for starting Tripe under Maemo's ancient
+       version of upstart.  It might work with other versions but it hasn't
+       been tested.
diff --git a/contrib/tripe-upstart.in b/contrib/tripe-upstart.in
new file mode 100644 (file)
index 0000000..aa6e419
--- /dev/null
@@ -0,0 +1,239 @@
+### -*-conf-*-
+###
+### Upstart control script for tripe.
+
+###--------------------------------------------------------------------------
+### Identification.
+
+description "TrIPE virtual private network server"
+author "Mark Wooding <mdw@distorted.org.uk>"
+
+###--------------------------------------------------------------------------
+### Trigger conditions.
+
+start on stopped pymaemo-optify
+stop on starting shutdown
+
+respawn
+
+###--------------------------------------------------------------------------
+### Process environment.
+
+console none
+
+###--------------------------------------------------------------------------
+### Pre-flight check.
+
+pre-start script
+
+       [ -f @initconfig@ ] && . @initconfig@
+
+       : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
+       : ${bindir=@bindir@} ${sbindir=@sbindir@}
+       : ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
+       : ${pidfile=@pidfile@}
+       : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
+
+       PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
+       export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
+
+       ## Give up if there's no binary.
+       if test ! -x "$tripe" || test ! -x "$tripectl"; then
+         echo >&2 "Not starting/stopping TrIPE: binary files missing"
+         exit 1
+       fi
+
+       ## 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 1
+       fi
+
+       ## Check it will work, or at least stands a fighting chance.
+       ##
+       ## (Having loads of different tunnel types doesn't help any.)
+       case ${tunnel-`$tripe --tunnels | head -1`},`uname -s` in
+
+         ## Linux TUN/TAP.
+         linux,Linux)
+           if { test -f /proc/misc && grep -q tun /proc/misc; } ||
+              modprobe -q tun; then
+             : good
+           else
+             echo >&2 "$tripe needs the Linux TUN/TAP driver to run."
+             exit 1
+           fi
+           if test -c /dev/net/tun; then
+             : good
+           else
+             echo >&2 "$tripe needs /dev/net/tun, which is missing."
+             exit 1
+           fi
+           ;;
+
+         ## Linux Unet (obsolete).
+         unet,Linux)
+           if { test -f /proc/devices && grep -q unet /proc/devices; } ||
+              modprobe -q unet; then
+             : good
+           else
+             echo >&2 "$tripe needs the Linux UNET driver to run."
+             exit 1
+           fi
+           if test -c /dev/unet; then
+             : good
+           else
+             echo >&2 "$tripe needs /dev/unet, which is missing."
+             exit 1
+           fi
+           ;;
+
+         ## BSD tun.
+         bsd,*BSD)
+           ## Don't know how to check the device is working.  Check the
+           ## device file exists and hope for the best.
+           if test -c /dev/tun0; then
+             : good
+           else
+             echo >&2 "$tripe needs /dev/tun0, which is missing."
+             exit 1
+           fi
+           ;;
+
+         ## SLIP.
+         slip,*)
+           if test "$TRIPE_SLIPIF" = ""; then
+             echo >&2 "$tripe needs SLIP interfaces set up!"
+             exit 1
+           fi
+           ;;
+
+         ## Various kinds of misconfiguration.
+         linux,* | unet,*)
+           echo >&2 "CONFIGURATION ERROR"
+           echo >&2 "  $tripe is compiled to use a Linux tunnel device, but"
+           echo >&2 "  this system is `uname -s`"
+           exit 1
+           ;;
+         bsd,*)
+           echo >&2 "CONFIGURATION ERROR"
+           echo >&2 "  $tripe is compiled to use a BSD tunnel device, but"
+           echo >&2 "  this system is `uname -s`"
+           exit 1
+           ;;
+       esac
+
+end script
+
+###--------------------------------------------------------------------------
+### Main startup.
+
+script
+
+       [ -f @initconfig@ ] && . @initconfig@
+
+       : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
+       : ${bindir=@bindir@} ${sbindir=@sbindir@}
+       : ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
+       : ${pidfile=@pidfile@}
+       : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
+
+       PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
+       export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
+
+       ## Start the server, passing lots of arguments.
+       $tripectl -s -p$tripe \
+         -f${logfile-/var/log/tripe.log} \
+         -P$pidfile \
+         ${keytag+-S-t}$keytag \
+         ${addr+-S-b}$addr \
+         ${port+-S-p}${port} \
+         ${user+-U}${user} \
+         ${group+-G}${group} \
+         ${trace+-S-T}${trace} \
+         ${tunnel+-S-n}${tunnel} \
+         ${miscopts}
+
+end script
+
+post-start script
+
+       [ -f @initconfig@ ] && . @initconfig@
+
+       : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
+       : ${bindir=@bindir@} ${sbindir=@sbindir@}
+       : ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
+       : ${pidfile=@pidfile@}
+       : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
+
+       PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
+       export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
+
+       ## Wait for the server to start up.  This doesn't usually take long.
+       for i in 1 2 3 4 give-up; do
+         $tripectl help >/dev/null 2>/dev/null && break
+         sleep 1
+       done
+
+       if [ $i = give-up ]; then
+         echo >&2 "Tripe server wouldn't start"
+         exit 1
+       fi
+
+       ## Start up the ancillary services.
+       [ -d $TRIPEDIR/services ] && for i in $TRIPEDIR/services/*; do
+         [ -x $i ] || continue
+         name=`basename $i`
+         case $name in *~|\#*) continue;; esac
+         $i --daemon --startup || :
+       done
+
+       ## Start up the statically configured peers.
+       [ -d $TRIPEDIR/peers ] && for i in $TRIPEDIR/peers/*; do
+         [ -x $i ] || continue
+         name=`basename $i`
+         case $name in *~|\#*) continue;; esac
+         $i || :
+       done
+
+end script
+
+###--------------------------------------------------------------------------
+### Shutdown.
+
+pre-stop script
+
+       [ -f /etc/default/tripe ] && . /etc/default/tripe
+
+       : ${prefix=/usr} ${exec_prefix=/usr}
+       : ${bindir=/usr/bin} ${sbindir=/usr/sbin}
+       : ${TRIPEDIR=/etc/tripe} ${TRIPESOCK=/var/run/tripesock}
+       : ${pidfile=/var/run/tripectl.pid}
+       : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
+
+       PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
+       export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
+
+       ## If there's no socket, it must have quit (probably nonviolently).
+       if test ! -S $TRIPESOCK; then
+         :
+
+       ## Ask it to die nicely.
+       elif $tripectl quit >/dev/null 2>&1; then
+         :
+
+       ## If there's no pidfile then tripectl presumably deleted it.
+       elif test ! -f $pidfile; then
+         rm -f $TRIPESOCK
+
+       ## Otherwise kill the process unpleasantly.
+       elif kill `cat $pidfile`; then
+         :
+       else
+         exit 1
+       fi
+
+end script
+
+###------ That's all, folks -------------------------------------------------