Merge
    
        | author | Steve Losh <steve@stevelosh.com> | 
    
        | date | Thu, 31 Aug 2023 16:04:02 -0400 | 
    
        | parents | a8a82a63b876 | 
    
        | children | (none) | 
#!/usr/bin/env bash
# Usage:
#
#     sprint './some-command foo' pidfile
#
# Then another process can:
#
#     kill `cat pidfile`
#
# to refresh the underlying process.
set -euo pipefail
set -m
PROGRAM="$1"
shift
PIDFILE="$1"
shift
echo "Starting ${PROGRAM}"
while true; do
    ${PROGRAM} &
    echo $! > "${PIDFILE}"
    fg >/dev/null || true
    rm "${PIDFILE}"
    echo "Restarting ${PROGRAM}"
    sleep 1
done