I'm writing my own generic init script, I've taken strategies from here and there and come up with
trap 'kill $(jobs -p)' EXIT;
until $DAEMON $DAEMONOPTS > /var/log/${NAME}.log 2>&1 & wait ; do
echo "Server '$NAME' crashed with exit code $?. Respawning.." > /var/log/${NAME}.log 2>&1 & echo $!
sleep 1
done
It kills the child process correctly on stop, it restart the service if dies etc.
Now I have to run that piece of code as a background job instead of directly in start)
The easy solution that works and I tested already would be to move this part in its own script and & it.
However I was wondering if there was a way to group these commands and send them in background, without having a second shell script to move around. Ideally I wanted to make this a gist so it should all be in a single file.
Is it even possible?