jw-pkg/scripts/systemctl-wrapper.sh
Jan Lindemann cecee8a842 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>
2026-03-14 14:15:04 +01:00

16 lines
363 B
Bash

#!/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 "$@"