jsbronder    14/06/19 16:50:52

  Modified:             sabnzbd.initd
  Log:
  Check that api is not disabled before attempting to use it for shutdown.  
Thanks to eponymous, #494640
  
  (Portage version: 2.2.8-r1/cvs/Linux x86_64, signed Manifest commit with key 
4D7043C9)

Revision  Changes    Path
1.8                  net-nntp/sabnzbd/files/sabnzbd.initd

file : 
http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-nntp/sabnzbd/files/sabnzbd.initd?rev=1.8&view=markup
plain: 
http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-nntp/sabnzbd/files/sabnzbd.initd?rev=1.8&content-type=text/plain
diff : 
http://sources.gentoo.org/viewvc.cgi/gentoo-x86/net-nntp/sabnzbd/files/sabnzbd.initd?r1=1.7&r2=1.8

Index: sabnzbd.initd
===================================================================
RCS file: /var/cvsroot/gentoo-x86/net-nntp/sabnzbd/files/sabnzbd.initd,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- sabnzbd.initd       11 Oct 2013 15:27:14 -0000      1.7
+++ sabnzbd.initd       19 Jun 2014 16:50:52 -0000      1.8
@@ -1,5 +1,5 @@
 #!/sbin/runscript
-# Copyright 1999-2013 Gentoo Foundation
+# Copyright 1999-2014 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 RUNDIR=/var/run/sabnzbd
@@ -11,11 +11,11 @@
 get_var() {
     echo $(sed -n \
         '/^\[misc]/,/^'$1'/ s/^'$1' = \([[:alnum:].]\+\)[\r|\n|\r\n]*$/\1/p' \
-        ${SABNZBD_CONFIGFILE})
+        "${SABNZBD_CONFIGFILE}")
 }
 
 get_port() {
-    if [ "$(get_var 'enable_https')" == "1" ]; then
+    if [ "$(get_var 'enable_https')" -eq 1 ]; then
         echo $(get_var 'https_port')
     else
         echo $(get_var 'port')
@@ -24,22 +24,16 @@
 
 get_addr() {
     local host=$(get_var 'host')
-    local port=$(get_port)
-    local protocol
+    local protocol='http'
 
     [ "${host}" == "0.0.0.0" ] && host=localhost
-    if [ "$(get_var 'enable_https')" == "1" ]; then
-        protocol="https"
-    else
-        protocol="http"
-    fi
+    [ "$(get_var 'enable_https')" -eq 1 ] && protocol='https'
 
-    echo ${protocol}://${host}:${port}
+    echo "${protocol}://${host}:$(get_port)"
 }
 
 get_pidfile() {
-    local port=$(get_port)
-    echo "${RUNDIR}/sabnzbd-${port}.pid"
+    echo "${RUNDIR}/sabnzbd-$(get_port).pid"
 }
 
 start() {
@@ -54,13 +48,13 @@
         --group ${SABNZBD_GROUP} \
         --name sabnzbd \
         --background \
-        --pidfile $(get_pidfile) \
+        --pidfile "$(get_pidfile)" \
         --exec /usr/bin/sabnzbd \
         -- \
-        --config-file ${SABNZBD_CONFIGFILE} \
-        --logging ${SABNZBD_LOGGING} \
+        --config-file "${SABNZBD_CONFIGFILE}" \
+        --logging "${SABNZBD_LOGGING}" \
         --daemon \
-        --pid ${RUNDIR}
+        --pid "${RUNDIR}"
 
     eend $?
 }
@@ -79,20 +73,24 @@
 stop() {
     local api_key=$(get_var 'api_key')
     local addr=$(get_addr)
-    local pidfile=$(get_pidfile)
     local rc=1
 
     ebegin "Stopping SABnzbd @ ${addr}"
+    # This can only work if we have enabled the API
+    if [ -n "${api_key}" -a "$(get_var 'disable_api_key')" -ne 1 ]; then
+        local ret
+        einfo "Attempting web-based shutdown @ ${addr}"
+
+        # SABnzbd will return "ok" if shutdown is successful
+        ret=$(/usr/bin/curl -k -s 
"${addr}/sabnzbd/api?mode=shutdown&apikey=${api_key}")
+        [ "${ret}" == "ok" ] && rc=0
+    fi
 
-    # SABnzbd will return "ok" if shutdown is successful
-    rc=$(/usr/bin/curl -k -s 
"${addr}/sabnzbd/api?mode=shutdown&apikey=${api_key}")
-    if [ "${rc}" == "ok" ]; then
-               rc=0
-       else
+    if [ "${rc}" -ne 0 ]; then
         einfo "Falling back to SIGTERM, this may not work if you restarted via 
the web interface"
         start-stop-daemon \
             --stop \
-            --pidfile ${pidfile} \
+            --pidfile $(get_pidfile) \
             --retry SIGTERM/1/SIGKILL/5
         rc=$?
     fi




Reply via email to