From a77cee821bd3cd386ae3c826228f6e8e56e3b193 Mon Sep 17 00:00:00 2001 From: Mike Teehan Date: Thu, 20 Aug 2026 23:05:54 +0000 Subject: [PATCH] Restart script re-execs itself with sudo when not run as root The script restarts system services via systemctl, which requires root. Previously it would only fail per-command when run by an unprivileged user. Add an EUID guard at the top that re-execs the script through sudo, preserving the original path and arguments. --- scripts/restart-services.sh | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/restart-services.sh b/scripts/restart-services.sh index eac5494..00ec8d8 100755 --- a/scripts/restart-services.sh +++ b/scripts/restart-services.sh @@ -1,5 +1,10 @@ #!/bin/bash +if [[ $EUID -ne 0 ]]; then + exec sudo "$0" "$@" + exit 0 +fi + echo "systemctl restart nginx" systemctl restart nginx sleep 1 @@ -22,3 +27,5 @@ if [ "$failed" -eq 1 ]; then exit 1 fi +exit 0 +