Add license of strlcat and strlcpy to debian/copyright
[tor.git] / contrib / tor.sh.in
blob151d1190139a56b18f627a2e8b665d5b265a3d68
1 #!/bin/sh
3 #tor The Onion Router
5 #chkconfig:2345 90 10
6 #description: Onion Router
8 TORUSER=
9 TORGROUP=
10 TORBIN=@BINDIR@/tor
11 TORPID=@LOCALSTATEDIR@/run/tor/tor.pid
12 TORLOG=@LOCALSTATEDIR@/log/tor/tor.log
13 TORCONF=@CONFDIR@/torrc
14 # Strictly speaking, we don't need to su if we have --user and --group.
15 # "Belt and suspenders," says jbash.
16 TORARGS="--pidfile $TORPID --logfile $TORLOG --runasdaemon 1"
17 if [ "x$TORUSER" != "x" ]; then
18 TORARGS="$TORARGS --user $TORUSER"
20 if [ "x$TORGROUP" != "x" ]; then
21 TORARGS="$TORARGS --group $TORGROUP"
23 RETVAL=0
25 case "$1" in
27 start)
28 if [ -f $TORPID ]; then
29 echo "tor appears to be already running (pid file exists)"
30 echo "Maybe you should run: $0 restart ?"
31 RETVAL=1
32 else
33 echo -n "Starting tor..."
34 if [ "x$TORUSER" = "x" ]; then
35 $TORBIN -f $TORCONF $TORARGS
36 else
37 /bin/su -c "$TORBIN -f $TORCONF $TORARGS" $TORUSER
39 RETVAL=$?
40 if [ $RETVAL -eq 0 ]; then
41 echo " ok"
42 else
43 echo " ERROR!"
48 stop)
49 if [ -f $TORPID ]; then
50 echo -n "Killing tor..."
51 kill `cat $TORPID`
52 RETVAL=$?
53 if [ $RETVAL -eq 0 ]; then
54 echo " ok"
55 else
56 echo " ERROR!"
58 else
59 echo "Unable to kill tor: $TORPID does not exist"
60 RETVAL=1
64 restart)
65 $0 stop
66 if [ -f $TORPID ]; then
67 rm -f $TORPID
69 $0 start
72 status)
73 PID=`cat $TORPID 2>/dev/null`
74 if [ "$PID" != "" ]; then
75 torstat=`ps -p $PID | grep -c "^$PID"`
76 if [ $torstat ]; then
77 echo "tor is running ($PID)"
78 else
79 echo "tor is not running (looks like it crashed, look for core? $PID)"
81 else
82 echo "tor is not running (exited gracefully)"
86 log)
87 cat $TORLOG
91 echo "Usage: $0 (start|stop|restart|status|log)"
92 exit 1
93 esac
95 exit $RETVAL