I have a daemon running on my server. It has been running smoothly for a while, and I keep logging every occurrence of an event in the daemon.
Yesterday I noticed something strange. The daemon had stopped running, but there was no error entry in the logs.
It is very important for my system that this daemon keeps running and that if it is stopped for any reason, it is reinitiated.
Is there a way in which I can detect at regular intervals if a particular process is running or not in Ubuntu?? If I can detect that I can easily reinitiate it, but the detection is the major problem
use cron.
let it run a script every x minutes
in your script use a line something like
and check the output.
this will always return at least one (the process of checking for the process itself)
so maybe if your count is greater than 1 you could assume your process is running and do nothing, otherwise restart the daemon.
https://help.ubuntu.com/community/CronHowto
if your process needs to be run by a particular user (e.g. wwwrun) make sure you start the process as that user