Closed iblessedi closed 2 years ago
it depends on your goals and skill. The easiest way would probably be to wrap it in a loop like this https://www.cyberciti.biz/faq/bash-infinite-loop/
more complex approach would use something like custom runit or systemd service
Ok, so here is my script, maybe will be useful for somebody:
#!/bin/bash
NUMBER_OF_PROCESSES=$(ps aux | grep db1000n | grep -v grep | wc -l)
if (($NUMBER_OF_PROCESSES < 1)); then
nohup /path/to/db1000n &>>/dev/null &
fi
In NUMBER_OF_PROCESSES < 1 - you can change 1 to number of processes you'd like to run. You can change /dev/null to any other file if you want to store logs (f.e. ~/log.log) /path/to/db1000n - path to your db1000n executable file
chmod +x run.sh
* * * * * /path/to/run.sh
That's all. Cron daemon will check if the script is alive and relaunch it if not. I purchased a VPS server and leave it with running script. I set NUMBER_OF_PROCESSES to 5 and I don't worry, I know that it will be running.
I have a VPS server and I run the script there. However for some reason after some time of running the script stops working with the error message 2022/04/11 19:22:47.306448 main.go:137: Terminating
I use the Ubuntu server and run the script with the command
nohup ./db100n > log.log &
What's the best way to keep the script up and running? How to relaunch it if it fails? Thanks.