Gentoo Archives: gentoo-commits

From: "Anthony G. Basile (blueness)" <blueness@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in net-misc/tor/files: tor.initd-r7
Date: Tue, 23 Sep 2014 23:14:05
Message-Id: 20140923231400.CF4986137@oystercatcher.gentoo.org
1 blueness 14/09/23 23:14:00
2
3 Added: tor.initd-r7
4 Log:
5 Add graceful stop for testing, bug #523552
6
7 (Portage version: 2.2.8-r1/cvs/Linux x86_64, signed Manifest commit with key 0xF52D4BBA)
8
9 Revision Changes Path
10 1.1 net-misc/tor/files/tor.initd-r7
11
12 file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-misc/tor/files/tor.initd-r7?rev=1.1&view=markup
13 plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-misc/tor/files/tor.initd-r7?rev=1.1&content-type=text/plain
14
15 Index: tor.initd-r7
16 ===================================================================
17 #!/sbin/runscript
18 # Copyright 1999-2014 Gentoo Foundation
19 # Distributed under the terms of the GNU General Public License v2
20 # $Header: /var/cvsroot/gentoo-x86/net-misc/tor/files/tor.initd-r7,v 1.1 2014/09/23 23:14:00 blueness Exp $
21
22 PIDFILE=/var/run/tor/tor.pid
23 CONFFILE=/etc/tor/torrc
24 GRACEFUL_TIMEOUT=${GRACEFUL_TIMEOUT:-60}
25
26 # See bug #523552, and https://trac.torproject.org/projects/tor/ticket/5525
27 # Graceful = wait 30 secs or so until all connections are properly closed.
28 extra_commands="checkconfig"
29 extra_started_commands="graceful gracefulstop reload"
30 description="Anonymizing overlay network for TCP"
31 description_checkconfig="Check for valid config file."
32 description_reload="Reload the configuration."
33 description_graceful="Gracefully restart."
34 description_gracefulstop="Gracefully stop."
35
36 depend() {
37 need net
38 }
39
40 checkconfig() {
41 # first check that it exists
42 if [ ! -f ${CONFFILE} ] ; then
43 eerror "You need to setup ${CONFFILE} first"
44 eerror "Example is in ${CONFFILE}.sample"
45 return 1
46 fi
47
48 # now verify whether the configuration is valid
49 /usr/bin/tor --verify-config -f ${CONFFILE} > /dev/null 2>&1
50 if [ $? -eq 0 ] ; then
51 einfo "Tor configuration (${CONFFILE}) is valid."
52 return 0
53 else
54 eerror "Tor configuration (${CONFFILE}) not valid."
55 /usr/bin/tor --verify-config -f ${CONFFILE}
56 return 1
57 fi
58 }
59
60 start() {
61 checkconfig || return 1
62 checkpath -d -m 0755 -o tor:tor /var/run/tor
63 ebegin "Starting Tor"
64 HOME=/var/lib/tor
65 start-stop-daemon --start --pidfile "${PIDFILE}" --quiet --exec /usr/bin/tor -- -f "${CONFFILE}" --runasdaemon 1 --PidFile "${PIDFILE}" > /dev/null 2>&1
66 eend $?
67 }
68
69 stop() {
70 ebegin "Stopping Tor"
71 start-stop-daemon --stop --pidfile "${PIDFILE}" --exec /usr/bin/tor -- --PidFile "${PIDFILE}"
72 eend $?
73 }
74
75 graceful() {
76 gracefulstop
77 start
78 eend $?
79 }
80
81 gracefulstop() {
82 ebegin "Gracefully stopping Tor"
83 ebegin "This can take up to ${GRACEFUL_TIMEOUT} seconds"
84 start-stop-daemon -P --stop --signal INT -R ${GRACEFUL_TIMEOUT} --pidfile "${PIDFILE}" --exec /usr/bin/tor -- --PidFile "${PIDFILE}"
85 eend $?
86 }
87
88 reload() {
89 if [ ! -f ${PIDFILE} ]; then
90 eerror "${SVCNAME} isn't running"
91 return 1
92 fi
93 checkconfig || return 1
94 ebegin "Reloading Tor configuration"
95 start-stop-daemon --signal HUP --pidfile ${PIDFILE}
96 eend $?
97 }