chiark / gitweb /
server/tests.at, t/keyring-*: New tests for key management.
[tripe] / init / tripe-init.in
... / ...
CommitLineData
1#! /bin/sh
2###
3### tripe init script
4### suitable for direct use in most SysV-style inits
5
6### BEGIN INIT INFO
7# Provides: tripe
8# Required-Start: $local_fs $remote_fs $named $network
9# Required-Stop: $local_fs $remote_fs $network
10# Default-Start: 2 3 4 5
11# Default-Stop: 0 1 6
12# Short-Description: tripe Virtual Private Network server
13### END INIT INFO
14
15set -e
16
17###--------------------------------------------------------------------------
18### Configuration.
19
20[ -f @initconfig@ ] && . @initconfig@
21
22: ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
23: ${bindir=@bindir@} ${sbindir=@sbindir@}
24: ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
25: ${pidfile=@pidfile@}
26: ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
27
28PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
29export PATH TRIPEDIR TRIPESOCK TRIPE_SLIPIF
30
31###--------------------------------------------------------------------------
32### Pre-flight checks.
33
34## Give up if there's no binary.
35if test ! -x "$tripe" || test ! -x "$tripectl"; then
36 echo >&2 "Not starting/stopping TrIPE: binary files missing"
37 exit 0
38fi
39
40## Give up if there's no key.
41if test ! -f "$TRIPEDIR/keyring" || test ! -f "$TRIPEDIR/keyring.pub"; then
42 echo >&2 "Not starting/stopping TrIPE: keyring files missing"
43 exit 0
44fi
45
46## Check it will work, or at least stands a fighting chance.
47##
48## (Having loads of different tunnel types doesn't help any.)
49case ${tunnel-`$tripe --tunnels | head -1`},`uname -s` in
50
51 ## Linux TUN/TAP.
52 linux,Linux)
53 if { test -f /proc/misc && grep -q tun /proc/misc; } ||
54 modprobe -q tun; then
55 : good
56 else
57 echo >&2 "$tripe needs the Linux TUN/TAP driver to run."
58 exit 1
59 fi
60 if test -c /dev/net/tun; then
61 : good
62 else
63 echo >&2 "$tripe needs /dev/net/tun, which is missing."
64 exit 1
65 fi
66 ;;
67
68 ## Linux Unet (obsolete).
69 unet,Linux)
70 if { test -f /proc/devices && grep -q unet /proc/devices; } ||
71 modprobe -q unet; then
72 : good
73 else
74 echo >&2 "$tripe needs the Linux UNET driver to run."
75 exit 1
76 fi
77 if test -c /dev/unet; then
78 : good
79 else
80 echo >&2 "$tripe needs /dev/unet, which is missing."
81 exit 1
82 fi
83 ;;
84
85 ## BSD tun.
86 bsd,*BSD)
87 ## Don't know how to check the device is working. Check the device file
88 ## exists and hope for the best.
89 if test -c /dev/tun0; then
90 : good
91 else
92 echo >&2 "$tripe needs /dev/tun0, which is missing."
93 exit 1
94 fi
95 ;;
96
97 ## SLIP.
98 slip,*)
99 if test "$TRIPE_SLIPIF" = ""; then
100 echo >&2 "$tripe needs SLIP interfaces set up!"
101 exit 1
102 fi
103 ;;
104
105 ## Various kinds of misconfiguration.
106 linux,* | unet,*)
107 echo >&2 "CONFIGURATION ERROR"
108 echo >&2 " $tripe is compiled to use a Linux tunnel device, but"
109 echo >&2 " this system is `uname -s`"
110 exit 1
111 ;;
112 bsd,*)
113 echo >&2 "CONFIGURATION ERROR"
114 echo >&2 " $tripe is compiled to use a BSD tunnel device, but"
115 echo >&2 " this system is `uname -s`"
116 exit 1
117 ;;
118esac
119
120###--------------------------------------------------------------------------
121### Do what was wanted.
122
123case "$1" in
124
125 start)
126 echo -n "Starting TrIPE VPN daemon:"
127
128 ## Check to see whether the daemon is already going. If it can respond
129 ## to a simple request, we'll assume that it is.
130 if $tripectl version >/dev/null 2>/dev/null; then
131 echo " already running"
132 exit 0
133 fi
134
135 ## Start the server, passing lots of arguments.
136 $tripectl -D -s -p$tripe \
137 -f${logfile-@logfile@} \
138 -P$pidfile \
139 ${keytag+-S-t}$keytag \
140 ${addr+-S-b}$addr \
141 ${port+-S-p}${port} \
142 ${user+-U}${user} \
143 ${group+-G}${group} \
144 ${sockmode+-S-m}${sockmode} \
145 ${trace+-S-T}${trace} \
146 ${tunnel+-S-n}${tunnel} \
147 ${miscopts}
148
149 ## Wait for the server to start up. This doesn't usually take long.
150 for i in 1 2 3 4 give-up; do
151 $tripectl help >/dev/null 2>/dev/null && break
152 sleep 1
153 done
154
155 if [ $i = give-up ]; then
156 echo " wouldn't start"
157 exit 1
158 fi
159
160 echo -n " tripe"
161
162 ## Start up the ancillary services.
163 sep=" services [" end=""
164 [ -d $TRIPEDIR/services ] && for i in $TRIPEDIR/services/*; do
165 [ -x $i ] || continue
166 name=`basename $i`
167 case $name in *~|\#*) continue;; esac
168 if $i --daemon --startup; then
169 echo -n "$sep$name"
170 else
171 echo -n "$sep($name failed)"
172 fi
173 sep=" " end="]"
174 done
175 echo -n "$end"
176
177 ## Start up the statically configured peers.
178 sep=" peers [" end=""
179 [ -d $TRIPEDIR/peers ] && for i in $TRIPEDIR/peers/*; do
180 [ -x $i ] || continue
181 name=`basename $i`
182 case $name in *~|\#*) continue;; esac
183 if $i; then
184 echo -n "$sep$name"
185 else
186 echo -n "$sep($name failed)"
187 fi
188 sep=" " end="]"
189 done
190
191 ## Happy.
192 echo "$end done"
193 ;;
194
195 stop)
196 echo -n "Stopping TrIPE VPN daemon:"
197
198 ## If there's no socket, it must have quit (probably nonviolently).
199 if (cd $TRIPEDIR && test ! -S $TRIPESOCK); then
200 echo " not running"
201
202 ## Ask it to die nicely.
203 elif $tripectl quit >/dev/null 2>&1; then
204 echo " done"
205
206 ## If there's no pidfile then tripectl presumably deleted it.
207 elif test ! -f $pidfile; then
208 echo " stale socket found: removing"
209 rm -f $TRIPESOCK
210
211 ## Otherwise kill the process unpleasantly.
212 elif kill `cat $pidfile`; then
213 echo " done (killed violently)"
214 else
215 echo " it doesn't want to die!"
216 exit 1
217 fi
218 ;;
219
220 status)
221 for i in `$tripectl list`; do
222 echo "Peer \`$i':"
223 $tripectl stats $i | sed 's/^/ /'
224 done
225 ;;
226
227 reload)
228 $tripectl reload
229 echo "Keyrings reloaded OK."
230 ;;
231
232 restart | force-reload)
233 sh $0 stop
234 sh $0 start
235 ;;
236
237 *)
238 echo >&2 "usage: $0 start|stop|restart|status|reload|force-reload"
239 exit 1
240 ;;
241
242esac
243
244###----- That's all, folks --------------------------------------------------