tor: Fix initscript (again).
[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
ae650f95
MT
12eval $(/usr/local/bin/readhash /var/ipfire/tor/settings)
13
529ac19c
MT
14function tor_is_enabled() {
15 [ "${TOR_ENABLED}" = "on" ] || [ "${TOR_RELAY_ENABLED}" = "on" ]
16}
17
c60301c0 18function setup_firewall() {
c60301c0
MT
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
27function flush_firewall() {
28 # Flush all rules.
29 iptables -F TOR_INPUT
30}
31
b312967c
MT
32case "${1}" in
33 start)
529ac19c
MT
34 tor_is_enabled || exit 0
35
c60301c0
MT
36 # Setup firewall.
37 setup_firewall
38
b312967c
MT
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)
c60301c0
MT
48 # Flush firewall.
49 flush_firewall
50
b312967c
MT
51 boot_mesg "Stopping tor..."
52 killproc /usr/bin/tor
53 ;;
54
55 reload)
c60301c0
MT
56 # Setup firewall.
57 setup_firewall
58
b312967c
MT
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
27cb7805
MT
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
b312967c
MT
78 status)
79 statusproc /usr/bin/tor
80 ;;
81
82 *)
27cb7805 83 echo "Usage: ${0} {start|stop|reload|restart|reload-or-restart|status}"
b312967c
MT
84 exit 1
85 ;;
86esac
87
88# End $rc_base/init.d/tor