]> git.ipfire.org Git - people/teissler/ipfire-2.x.git/blame - src/initscripts/init.d/tor
tor: Increase number of max. open file descriptors.
[people/teissler/ipfire-2.x.git] / src / initscripts / init.d / tor
CommitLineData
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
12FILEDESCRIPTORS="65535"
13
dea39917
MT
14eval $(/usr/local/bin/readhash /var/ipfire/tor/settings)
15
3765eb61
MT
16function tor_is_enabled() {
17 [ "${TOR_ENABLED}" = "on" ] || [ "${TOR_RELAY_ENABLED}" = "on" ]
18}
19
c60301c0 20function 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
27}
28
29function flush_firewall() {
30 # Flush all rules.
31 iptables -F TOR_INPUT
32}
33
b312967c
MT
34case "${1}" in
35 start)
3765eb61
MT
36 tor_is_enabled || exit 0
37
c60301c0
MT
38 # Setup firewall.
39 setup_firewall
40
6adacba0
MT
41 # Increasing open file descriptors.
42 if [ -n "${FILEDESCRIPTORS}" ]; then
43 ulimit -n "${FILEDESCRIPTORS}"
44 fi
45
b312967c
MT
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)
c60301c0
MT
55 # Flush firewall.
56 flush_firewall
57
b312967c
MT
58 boot_mesg "Stopping tor..."
59 killproc /usr/bin/tor
60 ;;
61
62 reload)
c60301c0
MT
63 # Setup firewall.
64 setup_firewall
65
b312967c
MT
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
27cb7805
MT
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
b312967c
MT
85 status)
86 statusproc /usr/bin/tor
87 ;;
88
89 *)
27cb7805 90 echo "Usage: ${0} {start|stop|reload|restart|reload-or-restart|status}"
b312967c
MT
91 exit 1
92 ;;
93esac
94
95# End $rc_base/init.d/tor