prerm 1.8 KB

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