From cecee8a8420a144452e722d0ea763ebbbfd44183 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Sat, 14 Mar 2026 14:04:10 +0100 Subject: [PATCH] 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 --- scripts/systemctl-wrapper.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 scripts/systemctl-wrapper.sh diff --git a/scripts/systemctl-wrapper.sh b/scripts/systemctl-wrapper.sh new file mode 100644 index 00000000..1a570f8b --- /dev/null +++ b/scripts/systemctl-wrapper.sh @@ -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 "$@"