aboutsummaryrefslogtreecommitdiff
path: root/contrib/suse/tor.sh.in
blob: b7e9005eb5efa8f2c14105be79193c2997e754b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
#
# Copyright (c) 2006-2007 Andrew Lewman
#
# tor    The Onion Router
#
# Startup/shutdown script for tor. This is a wrapper around torctl;
# torctl does the actual work in a relatively system-independent, or at least
# distribution-independent, way, and this script deals with fitting the
# whole thing into the conventions of the particular system at hand.
#
# These next couple of lines "declare" tor for the "chkconfig" program,
# originally from SGI, used on Red Hat/Fedora and probably elsewhere.
#
# chkconfig: 2345 90 10
# description: Onion Router - A low-latency anonymous proxy
#

### BEGIN INIT INFO
# Provides: tor
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 3 5
# Default-Stop: 0 1 2 6
# Short-Description: Start the tor daemon
# Description:  Start the tor daemon:  the anon-proxy server
### END INIT INFO

. /etc/rc.status

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     ditto but be verbose in local rc status
#      rc_status -v -r  ditto and clear the local rc status
#      rc_failed        set local and overall rc status to failed
#      rc_reset         clear local rc status (overall remains)
#      rc_exit          exit appropriate to overall rc status

# First reset status of this service
rc_reset

# Increase open file descriptors a reasonable amount
ulimit -n 8192

TORCTL=@BINDIR@/torctl

# torctl will use these environment variables
TORUSER=@TORUSER@
export TORUSER
TORGROUP=@TORGROUP@
export TORGROUP

TOR_DAEMON_PID_DIR="@LOCALSTATEDIR@/run/tor"

if [ -x /bin/su ] ; then
    SUPROG=/bin/su
elif [ -x /sbin/su ] ; then
    SUPROG=/sbin/su
elif [ -x /usr/bin/su ] ; then
    SUPROG=/usr/bin/su
elif [ -x /usr/sbin/su ] ; then
    SUPROG=/usr/sbin/su
else
    SUPROG=/bin/su
fi

case "$1" in

    start)
    echo "Starting tor daemon"

    if [ ! -d $TOR_DAEMON_PID_DIR ] ; then
        mkdir -p $TOR_DAEMON_PID_DIR
        chown $TORUSER:$TORGROUP $TOR_DAEMON_PID_DIR
    fi

    ## Start daemon with startproc(8). If this fails
    ## the echo return value is set appropriate.

    startproc -f $TORCTL start
    # Remember status and be verbose
    rc_status -v
    ;;

    stop)
    echo "Stopping tor daemon" 
    startproc -f $TORCTL stop
    # Remember status and be verbose
    rc_status -v
    ;;

    restart)
    echo "Restarting tor daemon" 
    startproc -f $TORCTL restart
    # Remember status and be verbose
    rc_status -v
    ;;

    reload)
    echo "Reloading tor daemon" 
    startproc -f $TORCTL reload
    # Remember status and be verbose
    rc_status -v
    ;;

    status)
    startproc -f $TORCTL status
    # Remember status and be verbose
    rc_status -v
    ;;

    *)
    echo "Usage: $0 (start|stop|restart|reload|status)"
    RETVAL=1
esac

rc_exit