I have a number of Python-based services on a Linux server that I start by running a .py file via a python3 bash command and that are supposed keep running indefinitely. One is a flask app, another is a watchdog script that will keep watching a directory and execute actions whenever a new file is added.
What's the most robust way of running these scripts on the server independently of a user session? I imagined creating a job in crontab that will run the respective Python commands every morning; but in case the processes are still running - won't this create more and more instances of the process each day?
What's the best practice for this? Is there an easy way to terminate the existing process first and then restart it?
cronhas option@rebootwhich can start program only when computer is restarting. It can be useful when you run own server - because it can restart your program when you have to restart your server.