I have a Python script which runs in multiple instances with different parameters, for instance:
python3 proc.py -s -v -l proc_one.log python3 proc.py -c -v -l proc_two.log
I usually start these in
tmux sessions with a script on boot and manually check in on these, to restart if they crashed.
tmux new-session -d -s proct 'cd /opt/proct/ && python3 proc.py -s -v -l proc_one.log; bash' tmux split-window -t proct 'cd /opt/proct/ && python3 proc.py -c -v -l proc_two.log; bash'
This is rather tedious and should be automated. I recently came across this solution, which offers kind of what I look for. A cronjob running the following bash script every couple of minutes:
if [[ ! $(pgrep -f '^python3 proc.py -s -v -l proc_one.log') ]]; then python3 proc.py -s -v -l proc_one.log fi
While this would keep my script running, it would also prevent me form checking in on the process.
My question is, how can I have a script check if my process is running, like the one above, but if it is not running, start it in a
tmux session. I wouldn't mind separate
tmux sessions for the different instances.