1 |
jsbronder 14/06/19 16:50:52 |
2 |
|
3 |
Modified: sabnzbd.initd |
4 |
Log: |
5 |
Check that api is not disabled before attempting to use it for shutdown. Thanks to eponymous, #494640 |
6 |
|
7 |
(Portage version: 2.2.8-r1/cvs/Linux x86_64, signed Manifest commit with key 4D7043C9) |
8 |
|
9 |
Revision Changes Path |
10 |
1.8 net-nntp/sabnzbd/files/sabnzbd.initd |
11 |
|
12 |
file : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-nntp/sabnzbd/files/sabnzbd.initd?rev=1.8&view=markup |
13 |
plain: http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-nntp/sabnzbd/files/sabnzbd.initd?rev=1.8&content-type=text/plain |
14 |
diff : http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-nntp/sabnzbd/files/sabnzbd.initd?r1=1.7&r2=1.8 |
15 |
|
16 |
Index: sabnzbd.initd |
17 |
=================================================================== |
18 |
RCS file: /var/cvsroot/gentoo-x86/net-nntp/sabnzbd/files/sabnzbd.initd,v |
19 |
retrieving revision 1.7 |
20 |
retrieving revision 1.8 |
21 |
diff -u -r1.7 -r1.8 |
22 |
--- sabnzbd.initd 11 Oct 2013 15:27:14 -0000 1.7 |
23 |
+++ sabnzbd.initd 19 Jun 2014 16:50:52 -0000 1.8 |
24 |
@@ -1,5 +1,5 @@ |
25 |
#!/sbin/runscript |
26 |
-# Copyright 1999-2013 Gentoo Foundation |
27 |
+# Copyright 1999-2014 Gentoo Foundation |
28 |
# Distributed under the terms of the GNU General Public License v2 |
29 |
|
30 |
RUNDIR=/var/run/sabnzbd |
31 |
@@ -11,11 +11,11 @@ |
32 |
get_var() { |
33 |
echo $(sed -n \ |
34 |
'/^\[misc]/,/^'$1'/ s/^'$1' = \([[:alnum:].]\+\)[\r|\n|\r\n]*$/\1/p' \ |
35 |
- ${SABNZBD_CONFIGFILE}) |
36 |
+ "${SABNZBD_CONFIGFILE}") |
37 |
} |
38 |
|
39 |
get_port() { |
40 |
- if [ "$(get_var 'enable_https')" == "1" ]; then |
41 |
+ if [ "$(get_var 'enable_https')" -eq 1 ]; then |
42 |
echo $(get_var 'https_port') |
43 |
else |
44 |
echo $(get_var 'port') |
45 |
@@ -24,22 +24,16 @@ |
46 |
|
47 |
get_addr() { |
48 |
local host=$(get_var 'host') |
49 |
- local port=$(get_port) |
50 |
- local protocol |
51 |
+ local protocol='http' |
52 |
|
53 |
[ "${host}" == "0.0.0.0" ] && host=localhost |
54 |
- if [ "$(get_var 'enable_https')" == "1" ]; then |
55 |
- protocol="https" |
56 |
- else |
57 |
- protocol="http" |
58 |
- fi |
59 |
+ [ "$(get_var 'enable_https')" -eq 1 ] && protocol='https' |
60 |
|
61 |
- echo ${protocol}://${host}:${port} |
62 |
+ echo "${protocol}://${host}:$(get_port)" |
63 |
} |
64 |
|
65 |
get_pidfile() { |
66 |
- local port=$(get_port) |
67 |
- echo "${RUNDIR}/sabnzbd-${port}.pid" |
68 |
+ echo "${RUNDIR}/sabnzbd-$(get_port).pid" |
69 |
} |
70 |
|
71 |
start() { |
72 |
@@ -54,13 +48,13 @@ |
73 |
--group ${SABNZBD_GROUP} \ |
74 |
--name sabnzbd \ |
75 |
--background \ |
76 |
- --pidfile $(get_pidfile) \ |
77 |
+ --pidfile "$(get_pidfile)" \ |
78 |
--exec /usr/bin/sabnzbd \ |
79 |
-- \ |
80 |
- --config-file ${SABNZBD_CONFIGFILE} \ |
81 |
- --logging ${SABNZBD_LOGGING} \ |
82 |
+ --config-file "${SABNZBD_CONFIGFILE}" \ |
83 |
+ --logging "${SABNZBD_LOGGING}" \ |
84 |
--daemon \ |
85 |
- --pid ${RUNDIR} |
86 |
+ --pid "${RUNDIR}" |
87 |
|
88 |
eend $? |
89 |
} |
90 |
@@ -79,20 +73,24 @@ |
91 |
stop() { |
92 |
local api_key=$(get_var 'api_key') |
93 |
local addr=$(get_addr) |
94 |
- local pidfile=$(get_pidfile) |
95 |
local rc=1 |
96 |
|
97 |
ebegin "Stopping SABnzbd @ ${addr}" |
98 |
+ # This can only work if we have enabled the API |
99 |
+ if [ -n "${api_key}" -a "$(get_var 'disable_api_key')" -ne 1 ]; then |
100 |
+ local ret |
101 |
+ einfo "Attempting web-based shutdown @ ${addr}" |
102 |
+ |
103 |
+ # SABnzbd will return "ok" if shutdown is successful |
104 |
+ ret=$(/usr/bin/curl -k -s "${addr}/sabnzbd/api?mode=shutdown&apikey=${api_key}") |
105 |
+ [ "${ret}" == "ok" ] && rc=0 |
106 |
+ fi |
107 |
|
108 |
- # SABnzbd will return "ok" if shutdown is successful |
109 |
- rc=$(/usr/bin/curl -k -s "${addr}/sabnzbd/api?mode=shutdown&apikey=${api_key}") |
110 |
- if [ "${rc}" == "ok" ]; then |
111 |
- rc=0 |
112 |
- else |
113 |
+ if [ "${rc}" -ne 0 ]; then |
114 |
einfo "Falling back to SIGTERM, this may not work if you restarted via the web interface" |
115 |
start-stop-daemon \ |
116 |
--stop \ |
117 |
- --pidfile ${pidfile} \ |
118 |
+ --pidfile $(get_pidfile) \ |
119 |
--retry SIGTERM/1/SIGKILL/5 |
120 |
rc=$? |
121 |
fi |