2018-08-08 05:18:59 +00:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2018-12-09 23:45:08 +00:00
|
|
|
NAME=emby-server
|
2018-08-08 05:18:59 +00:00
|
|
|
CONF_FILE=/etc/${NAME}.conf
|
|
|
|
DEFAULT_FILE=/etc/default/${NAME}
|
|
|
|
|
2018-12-09 23:45:08 +00:00
|
|
|
# Source Emby server default configuration
|
2018-08-08 05:18:59 +00:00
|
|
|
if [[ -f $DEFAULT_FILE ]]; then
|
|
|
|
. $DEFAULT_FILE
|
|
|
|
fi
|
|
|
|
|
2018-12-09 23:45:08 +00:00
|
|
|
# Source Emby server user configuration overrides
|
2018-08-08 05:18:59 +00:00
|
|
|
if [[ -f $CONF_FILE ]]; then
|
|
|
|
. $CONF_FILE
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Data directory where Emby database, cache and logs are stored
|
2018-12-09 23:45:08 +00:00
|
|
|
PROGRAMDATA=${EMBY_DATA-/var/lib/$NAME}
|
2018-08-08 05:18:59 +00:00
|
|
|
|
|
|
|
# In case this system is running systemd, we make systemd reload the unit files
|
|
|
|
# to pick up changes.
|
|
|
|
if [[ -d /run/systemd/system ]] ; then
|
|
|
|
systemctl --system daemon-reload >/dev/null || true
|
|
|
|
fi
|
|
|
|
|
|
|
|
case "$1" in
|
|
|
|
install|upgrade)
|
|
|
|
# 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
|
2018-12-09 23:45:08 +00:00
|
|
|
# try and figure out if emby is running
|
|
|
|
PIDFILE=$(find /var/run/ -maxdepth 1 -mindepth 1 -name "emby*.pid" -print -quit)
|
|
|
|
[[ -n "$PIDFILE" ]] && [[ -s "$PIDFILE" ]] && EMBY_PID=$(cat ${PIDFILE})
|
2018-08-08 05:18:59 +00:00
|
|
|
# if its running, let's stop it
|
2018-12-09 23:45:08 +00:00
|
|
|
if [[ -n "$EMBY_PID" ]]; then
|
|
|
|
echo "Stopping Emby Server!"
|
|
|
|
# if emby is still running, kill it
|
|
|
|
if [[ -n "$(ps -p $EMBY_PID -o pid=)" ]]; then
|
|
|
|
CPIDS=$(pgrep -P $EMBY_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 23:45:08 +00:00
|
|
|
if [[ -n "$(ps -p $EMBY_PID -o pid=)" ]]; then
|
2018-08-08 05:18:59 +00:00
|
|
|
echo "Could not successfully stop EmbyServer, please do so before uninstalling."
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
[[ -f $PIDFILE ]] && rm $PIDFILE
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
;;
|
|
|
|
abort-upgrade)
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "preinst called with unknown argument \`$1'" >&2
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
#DEBHELPER#
|
|
|
|
|
|
|
|
exit 0
|