From 79fafa3c6aa574f641d634fd3e136f29ec0ee9cf Mon Sep 17 00:00:00 2001 From: Cem Keylan Date: Wed, 16 Sep 2020 15:55:20 +0300 Subject: respawn: add seperate shell utility instead of running while loops Technically, these are the same shell commands, but since they are run by a separate shell, they are easier to predict and easier to kill. --- contrib/respawn | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 contrib/respawn (limited to 'contrib/respawn') diff --git a/contrib/respawn b/contrib/respawn new file mode 100644 index 0000000..1b914ea --- /dev/null +++ b/contrib/respawn @@ -0,0 +1,23 @@ +#!/bin/sh -e +# POSIX shell variant for ubase respawn + +usage() { + printf 'usage: %s [-d N] cmd [args...]\n' "${0##*/}" + exit "${1:-0}" +} + +die() { printf '%s\n' "$@" >&2; exit 1;} + +case "$1" in + -d) [ "$3" ] || usage 1 + [ "$2" -gt 0 ] || die "Not a number: $2" + delay=$2; shift 2 + ;; + --help|-h|'') usage ;; + -*) usage 1 +esac + +while :; do + "$@" + [ "$delay" ] && sleep "$delay" +done -- cgit v1.2.3