Systemd vs SysVinit vs OpenRC in Scripts
Systemd vs SysVinit vs OpenRC in Scripts
Abstracting service restarts across different distributions:
restart_service() {
local svc="$1"
if command -v systemctl >/dev/null 2>&1; then
systemctl restart "$svc"
elif command -v rc-service >/dev/null 2>&1; then
rc-service "$svc" restart
elif [ -x "/etc/init.d/$svc" ]; then
"/etc/init.d/$svc" restart
else
echo "No supported init system found" >&2
return 1
fi
}