systemctl-wrapper.sh: Add script to check for systemd

Maintainer scripts often mess with systemd services via systemctl. In
Docker containers, chroot environments or other environments not
governed by Systemd, systemctl will not exist or complain. This is a
frequent use case, worthy of providing a wrapper to catch and ignore
these cases conveniently.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-03-14 14:04:10 +01:00
commit cecee8a842

View file

@ -0,0 +1,16 @@
#!/bin/bash
reason=""
systemctl="/usr/bin/systemctl"
[ "$(ps -p 1 -o comm=)" = "systemd" ] || reason="Trying to run $exe in an environment not controlled by Systemd"
[ -x $systemctl ] || reason="Can't run $exe."
if [ "$reason" ]; then
title="$reason. Ignoring."
echo ",-- $title -- >"
echo "| $0 $@"
echo "\`-- $title -- <"
exit 0
fi
exec $systemctl "$@"