a77cee821b
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.
32 lines
530 B
Bash
Executable File
32 lines
530 B
Bash
Executable File
#!/bin/bash
|
|
|
|
if [[ $EUID -ne 0 ]]; then
|
|
exec sudo "$0" "$@"
|
|
exit 0
|
|
fi
|
|
|
|
echo "systemctl restart nginx"
|
|
systemctl restart nginx
|
|
sleep 1
|
|
echo "systemctl restart vacuum-walld"
|
|
systemctl restart vacuum-walld
|
|
sleep 1
|
|
echo "systemctl restart vacuum-wall"
|
|
systemctl restart vacuum-wall
|
|
|
|
# Verify services are running
|
|
failed=0
|
|
for svc in nginx vacuum-walld vacuum-wall; do
|
|
if ! systemctl is-active --quiet "$svc"; then
|
|
echo "ERROR: $svc is not running" >&2
|
|
failed=1
|
|
fi
|
|
done
|
|
|
|
if [ "$failed" -eq 1 ]; then
|
|
exit 1
|
|
fi
|
|
|
|
exit 0
|
|
|