tor: Only start tor when it has been enabled.
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / tor
1 #!/bin/sh
2 ########################################################################
3 # Begin $rc_base/init.d/tor
4 #
5 # Description : Anonymizing overlay network for TCP
6 #
7 ########################################################################
8
9 . /etc/sysconfig/rc
10 . ${rc_functions}
11
12 function tor_is_enabled() {
13 [ "${TOR_ENABLED}" = "on" ] || [ "${TOR_RELAY_ENABLED}" = "on" ]
14 }
15
16 function setup_firewall() {
17 eval $(/usr/local/bin/readhash /var/ipfire/tor/settings)
18
19 # Flush all rules.
20 flush_firewall
21
22 if [ "${TOR_RELAY_ENABLED}" = "on" -a -n "${TOR_RELAY_PORT}" ]; then
23 iptables -A TOR_INPUT -p tcp --dport "${TOR_RELAY_PORT}" -j ACCEPT
24 fi
25 }
26
27 function flush_firewall() {
28 # Flush all rules.
29 iptables -F TOR_INPUT
30 }
31
32 case "${1}" in
33 start)
34 tor_is_enabled || exit 0
35
36 # Setup firewall.
37 setup_firewall
38
39 boot_mesg "Starting tor..."
40 loadproc /usr/bin/tor \
41 --runasdaemon 1 \
42 --defaults-torrc /usr/share/tor/defaults-torrc \
43 -f /etc/tor/torrc \
44 --quiet
45 ;;
46
47 stop)
48 # Flush firewall.
49 flush_firewall
50
51 boot_mesg "Stopping tor..."
52 killproc /usr/bin/tor
53 ;;
54
55 reload)
56 # Setup firewall.
57 setup_firewall
58
59 boot_mesg "Reloading tor..."
60 reloadproc /usr/bin/tor
61 ;;
62
63 restart)
64 ${0} stop
65 sleep 1
66 ${0} start
67 ;;
68
69 reload-or-restart)
70 # Reload the process if it is already running. Otherwise, restart.
71 if pidofproc -s /usr/bin/tor; then
72 $0 reload
73 else
74 $0 restart
75 fi
76 ;;
77
78 status)
79 statusproc /usr/bin/tor
80 ;;
81
82 *)
83 echo "Usage: ${0} {start|stop|reload|restart|reload-or-restart|status}"
84 exit 1
85 ;;
86 esac
87
88 # End $rc_base/init.d/tor