prerm 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. set -e
  3. NAME=jellyfin
  4. CONF_FILE=/etc/${NAME}.conf
  5. DEFAULT_FILE=/etc/default/${NAME}
  6. # Source Jellyfin default configuration
  7. if [[ -f $DEFAULT_FILE ]]; then
  8. . $DEFAULT_FILE
  9. fi
  10. # Source Jellyfin user configuration overrides
  11. if [[ -f $CONF_FILE ]]; then
  12. . $CONF_FILE
  13. fi
  14. # Data directory where Jellyfin database, cache and logs are stored
  15. PROGRAMDATA=${JELLYFIN_DATA-/var/lib/$NAME}
  16. case "$1" in
  17. remove|upgrade|deconfigure)
  18. echo "Stopping Jellyfin!"
  19. # try graceful termination;
  20. if [[ -d /run/systemd/system ]]; then
  21. deb-systemd-invoke stop ${NAME}.service > /dev/null 2>&1 || true
  22. elif [ -x "/etc/init.d/${NAME}" ] || [ -e "/etc/init/${NAME}.conf" ]; then
  23. invoke-rc.d ${NAME} stop > /dev/null 2>&1 || true
  24. fi
  25. # Ensure that it is shutdown
  26. PIDFILE=$(find /var/run/ -maxdepth 1 -mindepth 1 -name "jellyfin*.pid" -print -quit)
  27. [[ -n "$PIDFILE" ]] && [[ -s "$PIDFILE" ]] && JELLYFIN_PID=$(cat ${PIDFILE})
  28. # if its running, let's stop it
  29. if [[ -n "$JELLYFIN_PID" ]]; then
  30. # if jellyfin is still running, kill it
  31. if [[ -n "$(ps -p $JELLYFIN_PID -o pid=)" ]]; then
  32. CPIDS=$(pgrep -P $JELLYFIN_PID)
  33. sleep 2 && kill -KILL $CPIDS
  34. kill -TERM $CPIDS > /dev/null 2>&1
  35. fi
  36. sleep 1
  37. # if it's still running, show error
  38. if [[ -n "$(ps -p $JELLYFIN_PID -o pid=)" ]]; then
  39. echo "Could not successfully stop Jellyfin, please do so before uninstalling."
  40. exit 1
  41. else
  42. [[ -f $PIDFILE ]] && rm $PIDFILE
  43. fi
  44. fi
  45. if [[ -f /usr/lib/jellyfin/bin/MediaBrowser.Server.Mono.exe.so ]]; then
  46. rm /usr/lib/jellyfin/bin/MediaBrowser.Server.Mono.exe.so
  47. fi
  48. ;;
  49. failed-upgrade)
  50. ;;
  51. *)
  52. echo "prerm called with unknown argument \`$1'" >&2
  53. exit 1
  54. ;;
  55. esac
  56. #DEBHELPER#
  57. exit 0