3 ### Upstart control script for tripe.
5 ### (c) 2012 Mark Wooding
8 ###----- Licensing notice ---------------------------------------------------
10 ### This file is part of Trivial IP Encryption (TrIPE).
12 ### TrIPE is free software: you can redistribute it and/or modify it under
13 ### the terms of the GNU General Public License as published by the Free
14 ### Software Foundation; either version 3 of the License, or (at your
15 ### option) any later version.
17 ### TrIPE is distributed in the hope that it will be useful, but WITHOUT
18 ### ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19 ### FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 ### You should have received a copy of the GNU General Public License
23 ### along with TrIPE. If not, see <https://www.gnu.org/licenses/>.
25 ###--------------------------------------------------------------------------
28 description "TrIPE virtual private network server"
29 author "Mark Wooding <mdw@distorted.org.uk>"
31 ###--------------------------------------------------------------------------
32 ### Trigger conditions.
34 start on stopped pymaemo-optify
35 stop on starting shutdown
39 ###--------------------------------------------------------------------------
40 ### Process environment.
44 ###--------------------------------------------------------------------------
49 [ -f @initconfig@ ] && . @initconfig@
51 : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
52 : ${bindir=@bindir@} ${sbindir=@sbindir@}
53 : ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
54 : ${pidfile=@pidfile@}
55 : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
57 PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
58 export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
60 ## Give up if there's no binary.
61 if test ! -x "$tripe" || test ! -x "$tripectl"; then
62 echo >&2 "Not starting/stopping TrIPE: binary files missing"
66 ## Give up if there's no key.
67 if test ! -f "$TRIPEDIR/keyring" ||
68 test ! -f "$TRIPEDIR/keyring.pub"; then
69 echo >&2 "Not starting/stopping TrIPE: keyring files missing"
73 ## Check it will work, or at least stands a fighting chance.
75 ## (Having loads of different tunnel types doesn't help any.)
76 case ${tunnel-`$tripe --tunnels | head -1`},`uname -s` in
80 if { test -f /proc/misc && grep -q tun /proc/misc; } ||
84 echo >&2 "$tripe needs the Linux TUN/TAP driver to run."
87 if test -c /dev/net/tun; then
90 echo >&2 "$tripe needs /dev/net/tun, which is missing."
95 ## Linux Unet (obsolete).
97 if { test -f /proc/devices && grep -q unet /proc/devices; } ||
98 modprobe -q unet; then
101 echo >&2 "$tripe needs the Linux UNET driver to run."
104 if test -c /dev/unet; then
107 echo >&2 "$tripe needs /dev/unet, which is missing."
114 ## Don't know how to check the device is working. Check the
115 ## device file exists and hope for the best.
116 if test -c /dev/tun0; then
119 echo >&2 "$tripe needs /dev/tun0, which is missing."
126 if test "$TRIPE_SLIPIF" = ""; then
127 echo >&2 "$tripe needs SLIP interfaces set up!"
132 ## Various kinds of misconfiguration.
134 echo >&2 "CONFIGURATION ERROR"
135 echo >&2 " $tripe is compiled to use a Linux tunnel device, but"
136 echo >&2 " this system is `uname -s`"
140 echo >&2 "CONFIGURATION ERROR"
141 echo >&2 " $tripe is compiled to use a BSD tunnel device, but"
142 echo >&2 " this system is `uname -s`"
149 ###--------------------------------------------------------------------------
154 [ -f @initconfig@ ] && . @initconfig@
156 : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
157 : ${bindir=@bindir@} ${sbindir=@sbindir@}
158 : ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
159 : ${pidfile=@pidfile@}
160 : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
162 PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
163 export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
165 ## Start the server, passing lots of arguments.
167 case ${syslogp-nil} in nil) ;; *) logopt="$logopt -l" ;; esac
168 case ${logfile+t},${syslogp-nil} in
169 t,*) logopt="$logopt -f$logfile" ;;
170 ,nil) logopt="$logopt -f@logfile@" ;;
172 $tripectl -s -p$tripe \
175 ${keytag+-S-t$keytag} \
176 ${addr+-S-b$addr} ${port+-S-p$port} \
177 ${user+-U$user} ${group+-G$group} \
178 ${sockmode+-S-m$sockmode} \
179 ${trace+-S-T$trace} \
180 ${tunnel+-S-n$tunnel} \
187 [ -f @initconfig@ ] && . @initconfig@
189 : ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
190 : ${bindir=@bindir@} ${sbindir=@sbindir@}
191 : ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
192 : ${pidfile=@pidfile@}
193 : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
195 PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
196 export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
198 ## Wait for the server to start up. This doesn't usually take long.
199 for i in 1 2 3 4 give-up; do
200 $tripectl help >/dev/null 2>/dev/null && break
204 if [ $i = give-up ]; then
205 echo >&2 "Tripe server wouldn't start"
209 ## Start up the ancillary services.
210 [ -d $TRIPEDIR/services ] && for i in $TRIPEDIR/services/*; do
211 [ -x $i ] || continue
213 case $name in *~|\#*) continue;; esac
214 $i --daemon --startup || :
217 ## Start up the statically configured peers.
218 [ -d $TRIPEDIR/peers ] && for i in $TRIPEDIR/peers/*; do
219 [ -x $i ] || continue
221 case $name in *~|\#*) continue;; esac
227 ###--------------------------------------------------------------------------
232 [ -f /etc/default/tripe ] && . /etc/default/tripe
234 : ${prefix=/usr} ${exec_prefix=/usr}
235 : ${bindir=/usr/bin} ${sbindir=/usr/sbin}
236 : ${TRIPEDIR=/etc/tripe} ${TRIPESOCK=/var/run/tripesock}
237 : ${pidfile=/var/run/tripectl.pid}
238 : ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
240 PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
241 export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
243 ## If there's no socket, it must have quit (probably nonviolently).
244 if test ! -S $TRIPESOCK; then
247 ## Ask it to die nicely.
248 elif $tripectl quit >/dev/null 2>&1; then
251 ## If there's no pidfile then tripectl presumably deleted it.
252 elif test ! -f $pidfile; then
255 ## Otherwise kill the process unpleasantly.
256 elif kill `cat $pidfile`; then
264 ###------ That's all, folks -------------------------------------------------