2018-08-08 05:18:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2018-12-09 21:41:49 +00:00
|
|
|
NAME=jellyfin
|
2018-08-08 05:18:59 +00:00
|
|
|
DEFAULT_FILE=/etc/default/${NAME}
|
|
|
|
|
2018-12-09 21:41:49 +00:00
|
|
|
# Source Jellyfin default configuration
|
2018-08-08 05:18:59 +00:00
|
|
|
if [[ -f $DEFAULT_FILE ]]; then
|
|
|
|
. $DEFAULT_FILE
|
|
|
|
fi
|
|
|
|
|
2019-01-06 00:55:55 +00:00
|
|
|
# Data directories for program data (cache, db), configs, and logs
|
|
|
|
PROGRAMDATA=${JELLYFIN_DATA_DIRECTORY-/var/lib/$NAME}
|
|
|
|
CONFIGDATA=${JELLYFIN_CONFIG_DIRECTORY-/etc/$NAME}
|
|
|
|
LOGDATA=${JELLYFIN_DATA_DIRECTORY-/var/log/$NAME}
|
2018-08-08 05:18:59 +00:00
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
remove|upgrade|deconfigure)
|
2018-12-09 21:41:49 +00:00
|
|
|
echo "Stopping Jellyfin!"
|
2018-08-08 05:18:59 +00:00
|
|
|
# try graceful termination;
|
|
|
|
if [[ -d /run/systemd/system ]]; then
|
|
|
|
deb-systemd-invoke stop ${NAME}.service > /dev/null 2>&1 || true
|
|
|
|
elif [ -x "/etc/init.d/${NAME}" ] || [ -e "/etc/init/${NAME}.conf" ]; then
|
|
|
|
invoke-rc.d ${NAME} stop > /dev/null 2>&1 || true
|
|
|
|
fi
|
|
|
|
# Ensure that it is shutdown
|
2018-12-09 21:41:49 +00:00
|
|
|
PIDFILE=$(find /var/run/ -maxdepth 1 -mindepth 1 -name "jellyfin*.pid" -print -quit)
|
|
|
|
[[ -n "$PIDFILE" ]] && [[ -s "$PIDFILE" ]] && JELLYFIN_PID=$(cat ${PIDFILE})
|
2018-08-08 05:18:59 +00:00
|
|
|
# if its running, let's stop it
|
2018-12-09 21:41:49 +00:00
|
|
|
if [[ -n "$JELLYFIN_PID" ]]; then
|
|
|
|
# if jellyfin is still running, kill it
|
|
|
|
if [[ -n "$(ps -p $JELLYFIN_PID -o pid=)" ]]; then
|
|
|
|
CPIDS=$(pgrep -P $JELLYFIN_PID)
|
2018-08-08 05:18:59 +00:00
|
|
|
sleep 2 && kill -KILL $CPIDS
|
|
|
|
kill -TERM $CPIDS > /dev/null 2>&1
|
|
|
|
fi
|
|
|
|
sleep 1
|
|
|
|
# if it's still running, show error
|
2018-12-09 21:41:49 +00:00
|
|
|
if [[ -n "$(ps -p $JELLYFIN_PID -o pid=)" ]]; then
|
2018-12-10 00:09:43 +00:00
|
|
|
echo "Could not successfully stop Jellyfin, please do so before uninstalling."
|
2018-08-08 05:18:59 +00:00
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
[[ -f $PIDFILE ]] && rm $PIDFILE
|
|
|
|
fi
|
|
|
|
fi
|
2018-12-09 21:41:49 +00:00
|
|
|
if [[ -f /usr/lib/jellyfin/bin/MediaBrowser.Server.Mono.exe.so ]]; then
|
|
|
|
rm /usr/lib/jellyfin/bin/MediaBrowser.Server.Mono.exe.so
|
2018-08-08 05:18:59 +00:00
|
|
|
fi
|
|
|
|
;;
|
|
|
|
failed-upgrade)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "prerm called with unknown argument \`$1'" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
#DEBHELPER#
|
|
|
|
|
|
|
|
exit 0
|