]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/initscripts/init.d/tor
tor: Increase number of max. open file descriptors.
[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
29 function flush_firewall() {
30 # Flush all rules.
31 iptables -F TOR_INPUT
32 }
33
34 case "${1}" in
35 start)
36 tor_is_enabled || exit 0
37
38 # Setup firewall.
39 setup_firewall
40
41 # Increasing open file descriptors.
42 if [ -n "${FILEDESCRIPTORS}" ]; then
43 ulimit -n "${FILEDESCRIPTORS}"
44 fi
45
46 boot_mesg "Starting tor..."
47 loadproc /usr/bin/tor \
48 --runasdaemon 1 \
49 --defaults-torrc /usr/share/tor/defaults-torrc \
50 -f /etc/tor/torrc \
51 --quiet
52 ;;
53
54 stop)
55 # Flush firewall.
56 flush_firewall
57
58 boot_mesg "Stopping tor..."
59 killproc /usr/bin/tor
60 ;;
61
62 reload)
63 # Setup firewall.
64 setup_firewall
65
66 boot_mesg "Reloading tor..."
67 reloadproc /usr/bin/tor
68 ;;
69
70 restart)
71 ${0} stop
72 sleep 1
73 ${0} start
74 ;;
75
76 reload-or-restart)
77 # Reload the process if it is already running. Otherwise, restart.
78 if pidofproc -s /usr/bin/tor; then
79 $0 reload
80 else
81 $0 restart
82 fi
83 ;;
84
85 status)
86 statusproc /usr/bin/tor
87 ;;
88
89 *)
90 echo "Usage: ${0} {start|stop|reload|restart|reload-or-restart|status}"
91 exit 1
92 ;;
93 esac
94
95 # End $rc_base/init.d/tor