If your task is...
- On Unix
- Stand alone
- Periodic
- Has an acceptable startup time
cron
will be better than rolling your own scheduler just for the one service. It will guarantee the process will always run at the correct time and has rudimentary error reporting. There's no need to add a watchdog in case your infinite loop has an error, cron
will run the process again in 5 minutes.
If cron
is insufficient, look into other job schedulers before rolling your own.
I have an uploader service which needs to run every 5minutes and it definitely finished within 5 minutes so there are never two parallel session.
These are famous last words. I would suggest adding in some form of locking. For example, write your PID to a file in /var/run
and check if that process is running. There's even a little pidfile library for Go.