chiark / gitweb /
debian: Run the server as `tripe' rather than `root'.
[tripe] / init / tripe-init.in
CommitLineData
0fa31a96 1#! /bin/sh
2#
3# tripe init script
4# suitable for direct use in most SysV-style inits
5
0fa31a96 6set -e
7
ef4a1ab7 8# --- Setup ---
0fa31a96 9
ef4a1ab7 10[ -f @initconfig@ ] && . @initconfig@
11: ${prefix=@prefix@} ${exec_prefix=@exec_prefix@}
12: ${bindir=@bindir@} ${sbindir=@sbindir@}
797cf76b 13: ${TRIPEDIR=@configdir@} ${TRIPESOCK=@socketdir@/tripesock}
3cdc3f3a 14: ${pidfile=@pidfile@}
ef4a1ab7 15: ${tripe=$sbindir/tripe} ${tripectl=$bindir/tripectl}
0fa31a96 16PATH=/usr/bin:/usr/sbin:/bin:/sbin:$bindir
797cf76b 17export PATH TRIPEDIR TRIPESOCK
ef4a1ab7 18
3cdc3f3a 19# --- Give up if there's no key ---
20
21if test ! -f $TRIPEDIR/keyring || test ! -f $TRIPEDIR/keyring.pub; then
22 echo >&2 "Not starting/stopping TrIPE: keyring files missing"
23 exit 0
24fi
25
ef4a1ab7 26# --- Check it will work, or at least stands a fighting chance ---
27#
28# Having loads of different tunnel types doesn't help any.
29
30test -x $tripe -a -x $tripectl || exit 0
31
42da2a58 32case ${tunnel-`$tripe --tunnels | head -1`} in
ef4a1ab7 33 linux)
34 case `uname -s` in
35 Linux)
82c75bd9 36 if { test -f /proc/misc && grep -q tun /proc/misc; } ||
ef4a1ab7 37 modprobe -q tun; then
38 : good
39 else
40 echo >&2 "$tripe needs the Linux TUN/TAP driver to run."
41 exit 1
42 fi
43 if test -c /dev/net/tun; then
44 : good
45 else
46 echo >&2 "$tripe needs /dev/net/tun, which is missing."
47 exit 1
48 fi
49 ;;
50 *)
51 echo >&2 "CONFIGURATION ERROR"
52 echo >&2 " $tripe is compiled to use a Linux tunnel device, but"
53 echo >&2 " this system is `uname -s`"
54 exit 1
55 ;;
56 esac
57 ;;
58 unet)
59 case `uname -s` in
60 Linux)
61 if { test -f /proc/devices && grep -q unet /proc/devices; } ||
62 modprobe -q unet; then
63 : good
64 else
65 echo >&2 "$tripe needs the Linux UNET driver to run."
66 exit 1
67 fi
68 if test -c /dev/unet; then
69 : good
70 else
71 echo >&2 "$tripe needs /dev/unet, which is missing."
72 exit 1
73 fi
74 ;;
75 *)
76 echo >&2 "CONFIGURATION ERROR"
77 echo >&2 " $tripe is compiled to use a Linux tunnel device, but"
78 echo >&2 " this system is `uname -s`"
79 exit 1
80 ;;
81 esac
82 ;;
83 bsd)
84 case `uname -s` in
85 *BSD)
86 # Don't know how to check the device is working.
87 if test -c /dev/tun0; then
88 : good
89 else
90 echo >&2 "$tripe needs /dev/tun0, which is missing."
91 exit 1
92 fi
93 ;;
94 *)
95 echo >&2 "CONFIGURATION ERROR"
96 echo >&2 " $tripe is compiled to use a BSD tunnel device, but"
97 echo >&2 " this system is `uname -s`"
98 exit 1
99 ;;
100 esac
101 ;;
b9066fbb 102 slip)
103 if test "$TRIPE_SLIPIF" = ""; then
104 echo >&2 "$tripe needs SLIP interfaces set up!"
105 exit 1
106 fi
107 ;;
ef4a1ab7 108esac
e04c2d50 109
ef4a1ab7 110# --- Do what was wanted ---
0fa31a96 111
112case "$1" in
113 start)
114 echo -n "Starting TrIPE VPN daemon:"
3cdc3f3a 115 if $tripectl version >/dev/null 2>/dev/null; then
0fa31a96 116 echo " already running"
117 exit 0
118 fi
ef4a1ab7 119 $tripectl -D -s -p$tripe \
120 -f${logfile-@logfile@} \
3cdc3f3a 121 -P$pidfile \
52c03a2a 122 ${keytag+-S-t}$keytag \
0fa31a96 123 ${addr+-S-b}$addr \
124 ${port+-S-p}${port} \
ab46a787
MW
125 ${user+-U}${user} \
126 ${group+-G}${group} \
0fa31a96 127 ${trace+-S-T}${trace} \
42da2a58 128 ${tunnel+-S-n}${tunnel} \
0fa31a96 129 ${miscopts}
130 for i in 1 2 3 4 give-up; do
131 $tripectl help >/dev/null 2>/dev/null && break
132 sleep 1
133 done
134 if [ $i = give-up ]; then
135 echo " wouldn't start"
136 exit 1
137 fi
138 echo -n " tripe"
a62f8e8a
MW
139 sep=" services [" end=""
140 [ -d $TRIPEDIR/services ] && for i in $TRIPEDIR/services/*; do
141 [ -x $i ] || continue
142 name=`basename $i`
143 case $name in *~|\#*) continue;; esac
144 if $i --daemon --startup; then
145 echo -n "$sep$name"
146 else
147 echo -n "$sep($name failed)"
148 fi
149 sep=" " end="]"
150 done
151 echo -n "$end"
152 sep=" peers [" end=""
153 [ -d $TRIPEDIR/peers ] && for i in $TRIPEDIR/peers/*; do
595935b7 154 [ -x $i ] || continue
0fa31a96 155 name=`basename $i`
595935b7 156 case $name in *~|\#*) continue;; esac
e04c2d50 157 if $i; then
a62f8e8a 158 echo -n "$sep$name"
595935b7 159 else
a62f8e8a 160 echo -n "$sep($name failed)"
595935b7 161 fi
a62f8e8a 162 sep=" " end="]"
0fa31a96 163 done
a62f8e8a 164 echo "$end done"
0fa31a96 165 ;;
166 stop)
167 echo -n "Stopping TrIPE VPN daemon:"
797cf76b 168 if test ! -S $TRIPESOCK; then
3cdc3f3a 169 echo " not running"
170 elif $tripectl quit >/dev/null 2>&1; then
171 echo " done"
172 elif test ! -f $pidfile; then
173 echo " stale socket found: removing"
797cf76b 174 rm -f $TRIPESOCK
3cdc3f3a 175 elif kill `cat $pidfile`; then
176 echo " done (killed violently)"
177 else
819018a9 178 echo " it doesn't want to die!"
3cdc3f3a 179 exit 1
180 fi
0fa31a96 181 ;;
ef4a1ab7 182 status)
183 for i in `$tripectl list`; do
184 echo "Peer \`$i':"
185 $tripectl stats $i | sed 's/^/ /'
186 done
187 ;;
de014da6 188 reload)
189 $tripectl reload
190 echo "Keyrings reloaded OK."
191 ;;
0fa31a96 192 restart | force-reload)
193 sh $0 stop
194 sh $0 start
195 ;;
196 *)
de014da6 197 echo >&2 "usage: $0 start|stop|restart|status|reload|force-reload"
0fa31a96 198 exit 1
199 ;;
200esac