I have a small python script that creates a graph of data pulled from MySQL. I’m trying to figure out a way to run the script in the background all time on a regular basis. I’ve tried a number of things:
- A Cron Job that runs the script
- A loop timer
- Using the & command to run the script in the background
These all have there pluses and minuses:
- The Cron Job running more then every half hour seems to eat up more resources then it’s worth.
- The Loop timer put into the script doesn’t actually put the script in the background it just keeps it running.
- The Linux & command backgrounds the process but unlike a real Linux service I can’t restart/stop it without killing it.
Can someone point me to a way to get the best out of all of these methods?
Why don’t you try to make your script into a proper daemon. This link is a good place to start.
You can start/stop/restart this script just like any other linux service.