preinst 1.8 KB

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