diff options
author | Justin Bronder <jsbronder@gentoo.org> | 2014-06-19 16:50:52 +0000 |
---|---|---|
committer | Justin Bronder <jsbronder@gentoo.org> | 2014-06-19 16:50:52 +0000 |
commit | beac22e1b3aa9e9a828cd56cb3d25d6425391c4d (patch) | |
tree | c5a7f6e3b62e44f70e68ccf7e654d905839b0f65 /net-nntp | |
parent | old (diff) | |
download | gentoo-2-beac22e1b3aa9e9a828cd56cb3d25d6425391c4d.tar.gz gentoo-2-beac22e1b3aa9e9a828cd56cb3d25d6425391c4d.tar.bz2 gentoo-2-beac22e1b3aa9e9a828cd56cb3d25d6425391c4d.zip |
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)
Diffstat (limited to 'net-nntp')
-rw-r--r-- | net-nntp/sabnzbd/ChangeLog | 6 | ||||
-rw-r--r-- | net-nntp/sabnzbd/files/sabnzbd.initd | 46 |
2 files changed, 27 insertions, 25 deletions
diff --git a/net-nntp/sabnzbd/ChangeLog b/net-nntp/sabnzbd/ChangeLog index 93ad3031d21d..894dfe9d75e5 100644 --- a/net-nntp/sabnzbd/ChangeLog +++ b/net-nntp/sabnzbd/ChangeLog @@ -1,6 +1,10 @@ # ChangeLog for net-nntp/sabnzbd # Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2 -# $Header: /var/cvsroot/gentoo-x86/net-nntp/sabnzbd/ChangeLog,v 1.21 2014/04/26 19:59:46 jsbronder Exp $ +# $Header: /var/cvsroot/gentoo-x86/net-nntp/sabnzbd/ChangeLog,v 1.22 2014/06/19 16:50:52 jsbronder Exp $ + + 19 Jun 2014; Justin Bronder <jsbronder@gentoo.org> files/sabnzbd.initd: + Check that api is not disabled before attempting to use it for shutdown. + Thanks to eponymous, #494640 *sabnzbd-0.7.17 (26 Apr 2014) diff --git a/net-nntp/sabnzbd/files/sabnzbd.initd b/net-nntp/sabnzbd/files/sabnzbd.initd index 238748d68157..5cfc91b9e70a 100644 --- a/net-nntp/sabnzbd/files/sabnzbd.initd +++ b/net-nntp/sabnzbd/files/sabnzbd.initd @@ -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 @@ depend() { 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_port() { 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 @@ start() { --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 @@ start_pre() { 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 |