diff --git a/install_service_systemd.sh b/install_service_systemd.sh new file mode 100644 index 000000000..94470fac4 --- /dev/null +++ b/install_service_systemd.sh @@ -0,0 +1,78 @@ +#!/bin/bash + +#Setting up colors +BOLDRED="$(printf '\033[1;31m')" +BOLDGREEN="$(printf '\033[1;32m')" +NC="$(printf '\033[0m')" # No Color + +# Stop and unload the service if it's running +jackettservice="jackett.service" +systemctl stop ${jackettservice} + +# Move working directory to Jackett's +cd "$(dirname "$0")" + +# Check if we're running from Jackett's directory +if [ ! -f ./jackett ]; then +echo "${BOLDRED}ERROR${NC}: Couldn't locate jackett. Is the script in the right directory?" + exit 1 +fi +jackettdir="$(pwd)" + +# Check if Jackett's owner is root +jackettuser="$(stat -c "%U" ./jackett)" +if [ "${jackettuser}" == "root" ]; then +echo "${BOLDRED}ERROR${NC}: Jackett shouldn't run as root. Please, change the owner of the Jackett directory." + exit 1 +fi + +# Check that no other service called Jackett is already running +if [[ $(systemctl status ${jackettservice} | grep "active (running)") ]]; then + echo "${BOLDRED}ERROR${NC}: Jackett already seems to be running as a service. Please stop it before running this script again." + exit 1 +fi + +# Write the systemd service descriptor +cat >"/etc/systemd/system/${jackettservice}" <