BastionGuard/data/init/common/bastionguard-periodic
specialworld83 588e87590d add multi-init support and Gentoo/Alpine packaging
* add support for systemd, OpenRC, SysVinit, and Dinit
* add automatic init-system detection through CMake
* make libsystemd optional for non-systemd builds
* add native service definitions for all supported init systems
* add Gentoo ebuild and Alpine APKBUILD packaging support
* publish the official BastionGuard source repository
* update the README with supported distributions, init systems, repository information, and build documentation
2026-07-21 14:15:32 +02:00

69 lines
1.1 KiB
Bash
Executable file

#!/bin/sh
# Run a command repeatedly without depending on systemd timers or cron.
set -u
interval=7200
delay=0
usage() {
echo "usage: $0 [--delay SECONDS] [--interval SECONDS] -- command [args...]" >&2
exit 64
}
while [ "$#" -gt 0 ]; do
case "$1" in
--delay)
[ "$#" -ge 2 ] || usage
delay=$2
shift 2
;;
--interval)
[ "$#" -ge 2 ] || usage
interval=$2
shift 2
;;
--)
shift
break
;;
*) usage ;;
esac
done
[ "$#" -gt 0 ] || usage
case "$delay:$interval" in
*[!0-9:]*|:*|*:0) usage ;;
esac
running=1
child=""
terminate() {
running=0
if [ -n "$child" ]; then
kill "$child" 2>/dev/null || true
fi
}
trap terminate INT TERM HUP
sleep_interruptible() {
seconds=$1
[ "$seconds" -eq 0 ] && return 0
sleep "$seconds" &
child=$!
wait "$child" 2>/dev/null || true
child=""
}
sleep_interruptible "$delay"
while [ "$running" -eq 1 ]; do
"$@" || true
[ "$running" -eq 1 ] || break
sleep_interruptible "$interval"
done
exit 0