sabnzbd.initd 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #!/sbin/openrc-run
  2. # Copyright 1999-2016 Gentoo Foundation
  3. # Distributed under the terms of the GNU General Public License v2
  4. PIDFILE="/run/sabnzbd/sabnzbd.pid"
  5. depend() {
  6. need net
  7. }
  8. get_var() {
  9. grep -P -o -m 1 "(?<=^${1} = ).*" "${SABNZBD_CONFIGFILE}" || echo 0
  10. }
  11. start() {
  12. ebegin "Starting SABnzbd"
  13. checkpath -q -d -o ${SABNZBD_USER}:${SABNZBD_GROUP} -m 0770 "$(dirname "${PIDFILE}")"
  14. start-stop-daemon \
  15. --quiet \
  16. --start \
  17. --user ${SABNZBD_USER} \
  18. --group ${SABNZBD_GROUP} \
  19. --pidfile "${PIDFILE}" \
  20. --wait 1000 \
  21. --exec /usr/share/sabnzbd/SABnzbd.py \
  22. -- \
  23. --config-file "${SABNZBD_CONFIGFILE}" \
  24. --logging "${SABNZBD_LOGGING}" \
  25. --daemon \
  26. --pidfile "${PIDFILE}"
  27. eend $?
  28. }
  29. stop() {
  30. local protocol="http"
  31. local host="$(get_var "host")"
  32. local port="$(get_var "port")"
  33. if [ $(get_var "enable_https") -eq 1 ]; then
  34. protocol="https"
  35. port="$(get_var "https_port")"
  36. fi
  37. case "${host}" in
  38. *:*) host="[${host}]" ;;
  39. esac
  40. local url="${protocol}://${host}:${port}/sabnzbd/api?mode=shutdown"
  41. if [ $(get_var "disable_api_key") -eq 0 ]; then
  42. url="${url}&apikey=$(get_var "api_key")"
  43. fi
  44. local signals="TERM/1/KILL/1"
  45. ebegin "Stopping SABnzbd"
  46. if [ "$(wget -q -t 1 -O - -T 10 "${url}")" = "ok" ]; then
  47. signals="NULL/5/${signals}"
  48. fi
  49. start-stop-daemon \
  50. --stop \
  51. --pidfile "${PIDFILE}" \
  52. --retry "${signals}"
  53. eend $?
  54. }