summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'net-nntp/sabnzbd/files/sabnzbd.initd')
-rwxr-xr-x[-rw-r--r--]net-nntp/sabnzbd/files/sabnzbd.initd130
1 files changed, 51 insertions, 79 deletions
diff --git a/net-nntp/sabnzbd/files/sabnzbd.initd b/net-nntp/sabnzbd/files/sabnzbd.initd
index 9b6a94192381..ad11573f5498 100644..100755
--- a/net-nntp/sabnzbd/files/sabnzbd.initd
+++ b/net-nntp/sabnzbd/files/sabnzbd.initd
@@ -1,99 +1,71 @@
#!/sbin/openrc-run
-# Copyright 1999-2014 Gentoo Foundation
+# Copyright 1999-2016 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-RUNDIR=/var/run/sabnzbd
+PIDFILE="/run/sabnzbd/sabnzbd.pid"
depend() {
- need net
+ need net
}
get_var() {
- echo $(sed -n \
- '/^\[misc]/,/^'$1'/ s/^'$1' = \([[:alnum:].]\+\)[\r|\n|\r\n]*$/\1/p' \
- "${SABNZBD_CONFIGFILE}")
+ grep -P -o -m 1 "(?<=^${1} = ).*" "${SABNZBD_CONFIGFILE}" || echo 0
}
-get_port() {
- if [ "$(get_var 'enable_https')" -eq 1 ]; then
- echo $(get_var 'https_port')
- else
- echo $(get_var 'port')
- fi
+start() {
+ ebegin "Starting SABnzbd"
+
+ checkpath -q -d -o ${SABNZBD_USER}:${SABNZBD_GROUP} -m 0770 "$(dirname "${PIDFILE}")"
+
+ start-stop-daemon \
+ --quiet \
+ --start \
+ --user ${SABNZBD_USER} \
+ --group ${SABNZBD_GROUP} \
+ --pidfile "${PIDFILE}" \
+ --wait 1000 \
+ --exec /usr/bin/sabnzbd \
+ -- \
+ --config-file "${SABNZBD_CONFIGFILE}" \
+ --logging "${SABNZBD_LOGGING}" \
+ --daemon \
+ --pidfile "${PIDFILE}"
+
+ eend $?
}
-get_addr() {
- local host=$(get_var 'host')
- local protocol='http'
+stop() {
+ local protocol="http"
+ local host="$(get_var "host")"
+ local port="$(get_var "port")"
- [ "${host}" == "0.0.0.0" ] && host=localhost
- [ "$(get_var 'enable_https')" -eq 1 ] && protocol='https'
+ if [ $(get_var "enable_https") -eq 1 ]; then
+ protocol="https"
+ port="$(get_var "https_port")"
+ fi
- echo "${protocol}://${host}:$(get_port)"
-}
+ case "${host}" in
+ *:*) host="[${host}]" ;;
+ esac
-get_pidfile() {
- echo "${RUNDIR}/sabnzbd-$(get_port).pid"
-}
+ local url="${protocol}://${host}:${port}/sabnzbd/api?mode=shutdown"
-start() {
- ebegin "Starting SABnzbd"
-
- checkpath -q -d -o ${SABNZBD_USER}:${SABNZBD_GROUP} -m 0770 "${RUNDIR}"
-
- start-stop-daemon \
- --quiet \
- --start \
- --user ${SABNZBD_USER} \
- --group ${SABNZBD_GROUP} \
- --name sabnzbd \
- --background \
- --pidfile "$(get_pidfile)" \
- --exec /usr/bin/sabnzbd \
- -- \
- --config-file "${SABNZBD_CONFIGFILE}" \
- --logging "${SABNZBD_LOGGING}" \
- --daemon \
- --pid "${RUNDIR}"
-
- eend $?
-}
+ if [ $(get_var "disable_api_key") -eq 0 ]; then
+ url="${url}&apikey=$(get_var "api_key")"
+ fi
-start_pre() {
- if [ "$RC_CMD" == "restart" ]; then
- local pidfile=$(get_pidfile)
- while [ -e ${pidfile} ]; do
- sleep 1
- done
- fi
+ local signals="TERM/1/KILL/1"
- return 0
-}
+ ebegin "Stopping SABnzbd"
-stop() {
- local api_key=$(get_var 'api_key')
- local addr=$(get_addr)
- 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
-
- 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 $(get_pidfile) \
- --retry SIGTERM/1/SIGKILL/5
- rc=$?
- fi
-
- eend ${rc}
+ if [ "$(wget -q -t 1 -O - -T 10 "${url}")" = "ok" ]; then
+ signals="CONT/5/${signals}"
+ fi
+
+ start-stop-daemon \
+ --stop \
+ --pidfile "${PIDFILE}" \
+ --retry "${signals}"
+
+ eend $?
}