aboutsummaryrefslogtreecommitdiffstats
path: root/community/tor/tor.initd
diff options
context:
space:
mode:
authorJakub Jirutka <jakub@jirutka.cz>2016-08-25 16:48:13 +0200
committerJakub Jirutka <jakub@jirutka.cz>2016-08-25 21:56:02 +0200
commitbd84b03391292e67b44989744a3ff28691fcddeb (patch)
treeb112d4fecda390f958a7ea53b02cc63d53f3f90f /community/tor/tor.initd
parentb6e190d074dbab4fffb28834b253a0ee681963a4 (diff)
downloadaports-bd84b03391292e67b44989744a3ff28691fcddeb.tar.bz2
aports-bd84b03391292e67b44989744a3ff28691fcddeb.tar.xz
community/tor: improve abuild and runscript
Diffstat (limited to 'community/tor/tor.initd')
-rw-r--r--community/tor/tor.initd93
1 files changed, 49 insertions, 44 deletions
diff --git a/community/tor/tor.initd b/community/tor/tor.initd
index 95d02db5d7..16faa64bc6 100644
--- a/community/tor/tor.initd
+++ b/community/tor/tor.initd
@@ -1,61 +1,66 @@
#!/sbin/openrc-run
-# Copyright 1999-2011 Gentoo Foundation
-# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/net-misc/tor/files/Attic/tor.initd-r6,v 1.7 2015/03/20 12:46:13 blueness dead $
+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="reload"
+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."
-PIDFILE=/var/run/tor/tor.pid
-CONFFILE=/etc/tor/torrc
depend() {
- need net
+ need net
}
checkconfig() {
- # first check that it exists
- if [ ! -f ${CONFFILE} ] ; then
- eerror "You need to setup ${CONFFILE} first"
- eerror "Example is in ${CONFFILE}.sample"
- return 1
- fi
-
- # now verify whether the configuration is valid
- /usr/bin/tor --verify-config -f ${CONFFILE} > /dev/null 2>&1
- if [ $? -eq 0 ] ; then
- einfo "Tor configuration (${CONFFILE}) is valid."
- return 0
- else
- eerror "Tor configuration (${CONFFILE}) not valid."
- /usr/bin/tor --verify-config -f ${CONFFILE}
- return 1
- fi
+ # 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() {
- checkconfig || return 1
- checkpath -d -m 0755 -o tor /var/run/tor
- ebegin "Starting Tor"
- HOME=/var/lib/tor
- start-stop-daemon --start --pidfile "${PIDFILE}" --quiet --exec /usr/bin/tor -- -f "${CONFFILE}" --runasdaemon 1 --PidFile "${PIDFILE}" > /dev/null 2>&1
- eend $?
+start_pre() {
+ checkconfig || return 1
+ checkpath -d -m 0755 -o tor "$(dirname "$pidfile")"
}
-stop() {
- ebegin "Stopping Tor"
- start-stop-daemon --stop --pidfile "${PIDFILE}" --exec /usr/bin/tor -- --PidFile "${PIDFILE}"
- eend $?
+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() {
- if [ ! -f ${PIDFILE} ]; then
- eerror "${SVCNAME} isn't running"
- return 1
- fi
- checkconfig || return 1
- ebegin "Reloading Tor configuration"
- start-stop-daemon --signal HUP --pidfile ${PIDFILE}
- eend $?
-}
+ start_pre || return 1
+ ebegin "Reloading Tor configuration"
+ start-stop-daemon --signal HUP --pidfile "$pidfile"
+ eend $?
+}