This + VPN idle killing sessions has forced me to get much better at tmux. I highly recommend for others who use SSH often, especially with WFH, to give it a try. The pane structure has made me much more efficient at my work nowadays.
When my company started, we used tmux in PROD as a process supervisor. We had tons of lines like:
while true; do ./runserver; sleep 10; done
in a shell script that would start a new server with one window per process. It got called from /etc/rc.local on boot IIRC.
Deploys meant pulling the new code on the server (or maybe just editing it in vim right there), then just Ctrl-C in every terminal (or when I got lazier, `killall runserver`).
This was back in 2010 or so... I have professionally come a long way in the intervening decade, and no longer have any PROD services running in tmux panes, but I definitely learned to love that tool.
I've done things similar and do it for quick and dirty. Currently I have something like that on a RPi but instead of
while true;
I have,
while [[ ! -f "$DIRECTORY"/backup_exit.stop ]]; do
sleep 3600 # sleep an hour
time /home/ubuntu/.pyenv/versions/backup/bin/python main.py
done
Whenever I want the process to stop, `touch backup_exit.stop` . This waits until the run finishes and exists on the next loop.
Anyway, that is saved to a 'backup.sh'
Then I have also,
#!/bin/bash
session="test"
backup="/path/to/backup.sh"
#create detached session named test
tmux new-session -d -s ${session}
# Create windows
tmux rename-window -t :0 'backup' #rename the first one
tmux new-window -n 'htop'
# Run processes
tmux send-keys -t 'backup' "$backup" ENTER
tmux send-keys -t 'htop' 'htop' ENTER
And this is run automatically on @reboot via cron.