restart.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/bin/bash
  2. # restart.sh - Jellyfin server restart script
  3. # Part of the Jellyfin project (https://github.com/jellyfin)
  4. #
  5. # This script restarts the Jellyfin daemon on Linux when using
  6. # the Restart button on the admin dashboard. It supports the
  7. # systemctl, service, and traditional /etc/init.d (sysv) restart
  8. # methods, chosen automatically by which one is found first (in
  9. # that order).
  10. #
  11. # This script is used by the Debian/Ubuntu/Fedora/CentOS packages.
  12. # This is the Right Way(tm) to check if we are booted with
  13. # systemd, according to sd_booted(3)
  14. if [ -d /run/systemd/system ]; then
  15. cmd=systemctl
  16. else
  17. # Everything else is really hard to figure out, so we just use
  18. # service(8) if it's available - that works with most init
  19. # systems/distributions I know of, including FreeBSD
  20. if type service >/dev/null 2>&1; then
  21. cmd=service
  22. else
  23. # If even service(8) isn't available, we just try /etc/init.d
  24. # and hope for the best
  25. if [ -d /etc/init.d ]; then
  26. cmd=sysv
  27. else
  28. echo "Unable to detect a way to restart Jellyfin; bailing out" 1>&2
  29. echo "Please report this bug to https://github.com/jellyfin/jellyfin/issues" 1>&2
  30. exit 1
  31. fi
  32. fi
  33. fi
  34. if type sudo >/dev/null 2>&1; then
  35. sudo_command=sudo
  36. else
  37. sudo_command=
  38. fi
  39. echo "Detected service control platform '$cmd'; using it to restart Jellyfin..."
  40. case $cmd in
  41. 'systemctl')
  42. # Without systemd-run here, `jellyfin.service`'s shutdown terminates this process too
  43. $sudo_command systemd-run systemctl restart jellyfin
  44. ;;
  45. 'service')
  46. echo "sleep 0.5; $sudo_command service jellyfin start" | at now
  47. ;;
  48. 'sysv')
  49. echo "sleep 0.5; /usr/bin/sudo /etc/init.d/jellyfin start" | at now
  50. ;;
  51. esac
  52. exit 0