]>
Commit | Line | Data |
---|---|---|
b312967c MT |
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 | ||
6adacba0 MT |
12 | FILEDESCRIPTORS="65535" |
13 | ||
dea39917 MT |
14 | eval $(/usr/local/bin/readhash /var/ipfire/tor/settings) |
15 | ||
3765eb61 MT |
16 | function tor_is_enabled() { |
17 | [ "${TOR_ENABLED}" = "on" ] || [ "${TOR_RELAY_ENABLED}" = "on" ] | |
18 | } | |
19 | ||
c60301c0 | 20 | function setup_firewall() { |
c60301c0 MT |
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 | |
e122dd63 JPT |
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 | |
c60301c0 MT |
31 | } |
32 | ||
33 | function flush_firewall() { | |
34 | # Flush all rules. | |
35 | iptables -F TOR_INPUT | |
36 | } | |
37 | ||
b312967c MT |
38 | case "${1}" in |
39 | start) | |
3765eb61 MT |
40 | tor_is_enabled || exit 0 |
41 | ||
c60301c0 MT |
42 | # Setup firewall. |
43 | setup_firewall | |
44 | ||
6adacba0 MT |
45 | # Increasing open file descriptors. |
46 | if [ -n "${FILEDESCRIPTORS}" ]; then | |
47 | ulimit -n "${FILEDESCRIPTORS}" | |
48 | fi | |
49 | ||
b312967c MT |
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) | |
c60301c0 MT |
59 | # Flush firewall. |
60 | flush_firewall | |
61 | ||
b312967c MT |
62 | boot_mesg "Stopping tor..." |
63 | killproc /usr/bin/tor | |
64 | ;; | |
65 | ||
66 | reload) | |
c60301c0 MT |
67 | # Setup firewall. |
68 | setup_firewall | |
69 | ||
b312967c MT |
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 | ||
27cb7805 MT |
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 | ||
b312967c MT |
89 | status) |
90 | statusproc /usr/bin/tor | |
91 | ;; | |
92 | ||
93 | *) | |
27cb7805 | 94 | echo "Usage: ${0} {start|stop|reload|restart|reload-or-restart|status}" |
b312967c MT |
95 | exit 1 |
96 | ;; | |
97 | esac | |
98 | ||
99 | # End $rc_base/init.d/tor |