mirror of
https://github.com/samrocketman/docker-compose-emby.git
synced 2026-05-01 09:06:23 +00:00
Add systemd integration for docker-compose service
This commit is contained in:
19
emby.service
Normal file
19
emby.service
Normal file
@@ -0,0 +1,19 @@
|
||||
# http://container-solutions.com/running-docker-containers-with-systemd/
|
||||
# install in /etc/systemd/system/emby.service
|
||||
[Unit]
|
||||
Description=Emby Media Server
|
||||
After=docker.service
|
||||
Requires=docker.service
|
||||
|
||||
[Service]
|
||||
WorkingDirectory=${EMBY_DOCKER_HOME}
|
||||
TimeoutStartSec=0
|
||||
Restart=always
|
||||
EnvironmentFile=-/etc/sysconfig/docker.emby
|
||||
# execstartpre is not necessary when using docker-compose
|
||||
#ExecStartPre=/usr/local/sbin/docker-compose pull
|
||||
ExecStart=/usr/local/sbin/docker-compose run --service-ports emby
|
||||
ExecStop=/usr/local/sbin/docker-compose down
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
88
install-emby-service.sh
Executable file
88
install-emby-service.sh
Executable file
@@ -0,0 +1,88 @@
|
||||
#!/bin/bash
|
||||
# Created by Sam Gleske
|
||||
# Installs the emby.service file as a systemd service
|
||||
|
||||
set -aueEo pipefail
|
||||
|
||||
#
|
||||
# ENVIRONMENT
|
||||
#
|
||||
|
||||
DESTINATION=/etc/systemd/system/emby.service
|
||||
export EMBY_DOCKER_HOME="${PWD}"
|
||||
|
||||
#
|
||||
# FUNCTIONS
|
||||
#
|
||||
|
||||
function msg() {
|
||||
echo "${@}" >&2
|
||||
}
|
||||
|
||||
function die() {
|
||||
msg "${@}"
|
||||
exit 1
|
||||
}; declare -rf die
|
||||
|
||||
function checksum() {
|
||||
envsubst < emby.service | sha256sum | awk '{ print $1 }'
|
||||
}; declare -rf checksum
|
||||
|
||||
function sha256sum() {
|
||||
if type -P sha256sum > /dev/null; then
|
||||
command sha256sum "${@}"
|
||||
elif type -P shasum > /dev/null; then
|
||||
command shasum -a 256 "${@}"
|
||||
else
|
||||
echo "ERROR: could not find a sha256sum program."
|
||||
exit 1
|
||||
fi
|
||||
}; declare -rf sha256sum
|
||||
|
||||
#
|
||||
# MAIN EXECUTION
|
||||
#
|
||||
|
||||
# pre-flight checks before modifying the system
|
||||
[ "${USER:-$(whoami)}" = root ] ||
|
||||
die 'ERROR: must be run as root to install the systemd service.'
|
||||
[ -d /lib/systemd ] && type -P systemctl > /dev/null ||
|
||||
die 'ERROR: must be run on a system which uses systemd for init.'
|
||||
type -P envsubst > /dev/null ||
|
||||
die 'ERROR: missing gettext package. "yum install gettext" or "apt install gettext"'
|
||||
[ -r emby.service ] ||
|
||||
die 'ERROR: no emby.service found. Are you in the right working directory?'
|
||||
|
||||
# Try to install the service.
|
||||
if [ -f "${DESTINATION}" ] && sha256sum -c - <<< "$(checksum) ${DESTINATION}"; then
|
||||
msg 'SKIPPED: emby.service is already installed.'
|
||||
else
|
||||
msg 'Installing systemd service.'
|
||||
envsubst < emby.service > "${DESTINATION}"
|
||||
systemctl daemon-reload
|
||||
fi
|
||||
|
||||
# Give the final help message.
|
||||
cat >&2 <<'EOF'
|
||||
With emby.service installed you are now ready to control the service. This
|
||||
script only installs the service and does not control the service for you.
|
||||
|
||||
This script is idempotent and can be safely run multiple times to see this
|
||||
message agin.
|
||||
|
||||
=== SERVICE CONTROL ===
|
||||
Start the service.
|
||||
systemctl start emby.service
|
||||
Stop the service.
|
||||
systemctl stop emby.service
|
||||
Ensure the service autostarts on reboot.
|
||||
systemctl enable emby.service
|
||||
Stop the service from autostarting on reboot.
|
||||
systemctl disable emby.service
|
||||
|
||||
=== DEBUGGING EMBY SERVICE ===
|
||||
View the current service status.
|
||||
systemctl status emby.service
|
||||
View the systemd logs for the service.
|
||||
journalctl -u emby.service
|
||||
EOF
|
||||
Reference in New Issue
Block a user