prerm 1.8 KB

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