Re: shed init independient user services
Reply #4 –
I'd write it as
steptime=$(awk -v tt="$totaltime" 'BEGIN {printf "%.2f", tt/20}')
This way, it works as intended even if $totaltime is empty or somehow contains awk code.
Seconding /run/user/$UID, it'd automatically clean the PID files on logout. (also, how it'd be more resilent?)
The simple way to implement auto-restart in sysv-rc style inits is polling the PID, which eats far more CPU than runit/s6/dinit's approach of just not letting daemons go into the background, as well as being less reliable as PIDs could be reused between the monitored program dying and the script doing another round of polling.
Implementing the latter in shell script and still being responsive to user commands gets quite tricky, though, speaking from experience.