What you need is a process manager, a utility that manages your daemon and decides when to start / stop it by the way.
There are several of them, such as supervisord, upstart, runit, etc. You will have to research them and find the one that best suits your needs.
Hope this helps.
source
share