From c08c0272b5c801fecbb13b146b9e24429aa6df62 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Thu, 27 Jun 2019 18:05:03 -0400 Subject: [PATCH 1/3] Add nicer restart script The old restart script was buggy, as reported in #1320. This updated script seems to work far more reliably and conforms to the existing jellyfin-sudoers packages sudo configuration. --- .../debian-package-x64/pkg-src/bin/restart.sh | 48 ++++++++++++------- .../fedora-package-x64/pkg-src/restart.sh | 40 ++++++++++++++-- 2 files changed, 67 insertions(+), 21 deletions(-) diff --git a/deployment/debian-package-x64/pkg-src/bin/restart.sh b/deployment/debian-package-x64/pkg-src/bin/restart.sh index 738f86727c..acfb0c5a25 100644 --- a/deployment/debian-package-x64/pkg-src/bin/restart.sh +++ b/deployment/debian-package-x64/pkg-src/bin/restart.sh @@ -1,20 +1,36 @@ #!/bin/bash -NAME=jellyfin +# restart.sh - Jellyfin server restart script +# Part of the Jellyfin project (https://github.com/jellyfin) +# +# This script restarts the Jellyfin daemon on Linux when using +# the Restart button on the admin dashboard. It supports the +# systemctl, service, and traditional /etc/init.d (sysv) restart +# methods, chosen automatically by which one is found first (in +# that order). +# +# This script is used by the Debian/Ubuntu/Fedora/CentOS packages. -restart_cmds=( - "systemctl restart ${NAME}" - "service ${NAME} restart" - "/etc/init.d/${NAME} restart" - "s6-svc -t /var/run/s6/services/${NAME}" -) +get_service_command() { + for command in systemctl service; do + if which $command &>/dev/null; then + echo $command && return + fi + done + echo "sysv" +} -for restart_cmd in "${restart_cmds[@]}"; do - cmd=$(echo "$restart_cmd" | awk '{print $1}') - cmd_loc=$(command -v ${cmd}) - if [[ -n "$cmd_loc" ]]; then - restart_cmd=$(echo "$restart_cmd" | sed -e "s%${cmd}%${cmd_loc}%") - echo "sleep 2; sudo $restart_cmd > /dev/null 2>&1" | at now > /dev/null 2>&1 - exit 0 - fi -done +cmd="$( get_service_command )" +echo "Using system control command '$cmd' to restart Jellyfin..." +case $cmd in + 'systemctl') + echo "sleep 2; /usr/bin/sudo /usr/bin/systemctl restart jellyfin" | at now + ;; + 'service') + echo "sleep 2; /usr/bin/sudo /sbin/service jellyfin restart" | at now + ;; + 'sysv') + echo "sleep 2; /usr/bin/sudo /etc/init.d/jellyfin restart" | at now + ;; +esac +exit 0 diff --git a/deployment/fedora-package-x64/pkg-src/restart.sh b/deployment/fedora-package-x64/pkg-src/restart.sh index e84dca587f..acfb0c5a25 100644 --- a/deployment/fedora-package-x64/pkg-src/restart.sh +++ b/deployment/fedora-package-x64/pkg-src/restart.sh @@ -1,6 +1,36 @@ -#!/bin/sh +#!/bin/bash -NAME=jellyfin -restart_cmd="/usr/bin/systemctl restart ${NAME}" -echo "sleep 2; sudo $restart_cmd > /dev/null 2>&1" | at now > /dev/null 2>&1 -exit 0 \ No newline at end of file +# restart.sh - Jellyfin server restart script +# Part of the Jellyfin project (https://github.com/jellyfin) +# +# This script restarts the Jellyfin daemon on Linux when using +# the Restart button on the admin dashboard. It supports the +# systemctl, service, and traditional /etc/init.d (sysv) restart +# methods, chosen automatically by which one is found first (in +# that order). +# +# This script is used by the Debian/Ubuntu/Fedora/CentOS packages. + +get_service_command() { + for command in systemctl service; do + if which $command &>/dev/null; then + echo $command && return + fi + done + echo "sysv" +} + +cmd="$( get_service_command )" +echo "Using system control command '$cmd' to restart Jellyfin..." +case $cmd in + 'systemctl') + echo "sleep 2; /usr/bin/sudo /usr/bin/systemctl restart jellyfin" | at now + ;; + 'service') + echo "sleep 2; /usr/bin/sudo /sbin/service jellyfin restart" | at now + ;; + 'sysv') + echo "sleep 2; /usr/bin/sudo /etc/init.d/jellyfin restart" | at now + ;; +esac +exit 0 From a629f209b931e37a2e3e5db5ee9827460e5f3bbf Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 28 Jun 2019 11:06:55 -0400 Subject: [PATCH 2/3] Make message wording more consistent --- deployment/debian-package-x64/pkg-src/bin/restart.sh | 2 +- deployment/fedora-package-x64/pkg-src/restart.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/debian-package-x64/pkg-src/bin/restart.sh b/deployment/debian-package-x64/pkg-src/bin/restart.sh index acfb0c5a25..4c664d404e 100644 --- a/deployment/debian-package-x64/pkg-src/bin/restart.sh +++ b/deployment/debian-package-x64/pkg-src/bin/restart.sh @@ -21,7 +21,7 @@ get_service_command() { } cmd="$( get_service_command )" -echo "Using system control command '$cmd' to restart Jellyfin..." +echo "Detected service control platform '$cmd'; using it to restart Jellyfin..." case $cmd in 'systemctl') echo "sleep 2; /usr/bin/sudo /usr/bin/systemctl restart jellyfin" | at now diff --git a/deployment/fedora-package-x64/pkg-src/restart.sh b/deployment/fedora-package-x64/pkg-src/restart.sh index acfb0c5a25..4c664d404e 100644 --- a/deployment/fedora-package-x64/pkg-src/restart.sh +++ b/deployment/fedora-package-x64/pkg-src/restart.sh @@ -21,7 +21,7 @@ get_service_command() { } cmd="$( get_service_command )" -echo "Using system control command '$cmd' to restart Jellyfin..." +echo "Detected service control platform '$cmd'; using it to restart Jellyfin..." case $cmd in 'systemctl') echo "sleep 2; /usr/bin/sudo /usr/bin/systemctl restart jellyfin" | at now From 62105c249f59e4343a8db2ff6d2cb8af809745d5 Mon Sep 17 00:00:00 2001 From: "Joshua M. Boniface" Date: Fri, 28 Jun 2019 11:15:08 -0400 Subject: [PATCH 3/3] Use which to find the service binary path --- deployment/debian-package-x64/pkg-src/bin/restart.sh | 4 ++-- deployment/fedora-package-x64/pkg-src/restart.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/deployment/debian-package-x64/pkg-src/bin/restart.sh b/deployment/debian-package-x64/pkg-src/bin/restart.sh index 4c664d404e..9b64b6d728 100644 --- a/deployment/debian-package-x64/pkg-src/bin/restart.sh +++ b/deployment/debian-package-x64/pkg-src/bin/restart.sh @@ -24,10 +24,10 @@ cmd="$( get_service_command )" echo "Detected service control platform '$cmd'; using it to restart Jellyfin..." case $cmd in 'systemctl') - echo "sleep 2; /usr/bin/sudo /usr/bin/systemctl restart jellyfin" | at now + echo "sleep 2; /usr/bin/sudo $( which systemctl ) restart jellyfin" | at now ;; 'service') - echo "sleep 2; /usr/bin/sudo /sbin/service jellyfin restart" | at now + echo "sleep 2; /usr/bin/sudo $( which service ) jellyfin restart" | at now ;; 'sysv') echo "sleep 2; /usr/bin/sudo /etc/init.d/jellyfin restart" | at now diff --git a/deployment/fedora-package-x64/pkg-src/restart.sh b/deployment/fedora-package-x64/pkg-src/restart.sh index 4c664d404e..9b64b6d728 100644 --- a/deployment/fedora-package-x64/pkg-src/restart.sh +++ b/deployment/fedora-package-x64/pkg-src/restart.sh @@ -24,10 +24,10 @@ cmd="$( get_service_command )" echo "Detected service control platform '$cmd'; using it to restart Jellyfin..." case $cmd in 'systemctl') - echo "sleep 2; /usr/bin/sudo /usr/bin/systemctl restart jellyfin" | at now + echo "sleep 2; /usr/bin/sudo $( which systemctl ) restart jellyfin" | at now ;; 'service') - echo "sleep 2; /usr/bin/sudo /sbin/service jellyfin restart" | at now + echo "sleep 2; /usr/bin/sudo $( which service ) jellyfin restart" | at now ;; 'sysv') echo "sleep 2; /usr/bin/sudo /etc/init.d/jellyfin restart" | at now