aboutsummaryrefslogtreecommitdiffstats
path: root/community/tor/tor.initd
blob: 16faa64bc6626271ce5f3b7f9ffcab571ca7d5d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/sbin/openrc-run

conffile="/etc/tor/torrc"
pidfile="/run/tor/tor.pid"
graceful_timeout=${GRACEFUL_TIMEOUT:-60}

command="/usr/bin/tor"
command_args="-f $conffile"
command_background="yes"
start_stop_daemon_args="
	--chdir /var/lib/tor
	--env HOME=/var/lib/tor"

# See bug #523552, and https://trac.torproject.org/projects/tor/ticket/5525
# Graceful = wait 30 secs or so until all connections are properly closed.
extra_commands="checkconfig"
extra_started_commands="graceful gracefulstop reload"

description="Anonymizing overlay network for TCP"
description_checkconfig="Check if config file is valid."
description_reload="Reload the configuration."
description_gracefulstop="Gracefully stop."


depend() {
	need net
}

checkconfig() {
	# First check that it exists.
	if [ ! -f "$conffile" ] ; then
		eerror "You need to setup $conffile first, see $conffile.sample for example"
		return 1
	fi

	# Now verify whether the configuration is valid.
	if ! $command --verify-config -f "$conffile" 2>&1 1>/dev/null; then
		eerror "Tor configuration (${conffile}) not valid"
		$command --verify-config -f "$conffile"
		return 1
	fi
}

start_pre() {
	checkconfig || return 1
	checkpath -d -m 0755 -o tor "$(dirname "$pidfile")"
}

gracefulstop() {
	ebegin "Gracefully stopping Tor, this can take up to $graceful_timeout seconds"
	start-stop-daemon --stop \
		--progress \
		--signal INT \
		--retry $graceful_timeout \
		--pidfile "$pidfile" \
		--exec $command -- $command_args
	eend $?
}

reload() {
	start_pre || return 1

	ebegin "Reloading Tor configuration"
	start-stop-daemon --signal HUP --pidfile "$pidfile"
	eend $?
}