]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/initscripts/init.d/tor
Merge branch 'master' into fifteen
[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 FILEDESCRIPTORS="65535"
13
14 eval $(/usr/local/bin/readhash /var/ipfire/tor/settings)
15
16 function tor_is_enabled() {
17 [ "${TOR_ENABLED}" = "on" ] || [ "${TOR_RELAY_ENABLED}" = "on" ]
18 }
19
20 function setup_firewall() {
21 # Flush all rules.
22 flush_firewall
23
24 if [ "${TOR_RELAY_ENABLED}" = "on" -a -n "${TOR_RELAY_PORT}" ]; then
25 iptables -A TOR_INPUT -p tcp --dport "${TOR_RELAY_PORT}" -j ACCEPT
26 fi
27
28 if [ "${TOR_RELAY_ENABLED}" = "on" -a -n "${TOR_RELAY_DIRPORT}" ] && [ "${TOR_RELAY_DIRPORT}" -ne 0 ]; then
29 iptables -A TOR_INPUT -p tcp --dport "${TOR_RELAY_DIRPORT}" -j ACCEPT
30 fi
31 }
32
33 function flush_firewall() {
34 # Flush all rules.
35 iptables -F TOR_INPUT
36 }
37
38 case "${1}" in
39 start)
40 tor_is_enabled || exit 0
41
42 # Setup firewall.
43 setup_firewall
44
45 # Increasing open file descriptors.
46 if [ -n "${FILEDESCRIPTORS}" ]; then
47 ulimit -n "${FILEDESCRIPTORS}"
48 fi
49
50 boot_mesg "Starting tor..."
51 loadproc /usr/bin/tor \
52 --runasdaemon 1 \
53 --defaults-torrc /usr/share/tor/defaults-torrc \
54 -f /etc/tor/torrc \
55 --quiet
56 ;;
57
58 stop)
59 # Flush firewall.
60 flush_firewall
61
62 boot_mesg "Stopping tor..."
63 killproc /usr/bin/tor
64 ;;
65
66 reload)
67 # Setup firewall.
68 setup_firewall
69
70 boot_mesg "Reloading tor..."
71 reloadproc /usr/bin/tor
72 ;;
73
74 restart)
75 ${0} stop
76 sleep 1
77 ${0} start
78 ;;
79
80 reload-or-restart)
81 # Reload the process if it is already running. Otherwise, restart.
82 if pidofproc -s /usr/bin/tor; then
83 $0 reload
84 else
85 $0 restart
86 fi
87 ;;
88
89 status)
90 statusproc /usr/bin/tor
91 ;;
92
93 *)
94 echo "Usage: ${0} {start|stop|reload|restart|reload-or-restart|status}"
95 exit 1
96 ;;
97 esac
98
99 # End $rc_base/init.d/tor