I have a shell script that runs a C++ backend mail system (PluginHandler). I need to monitor this process in Monit and restart it if it fails.

The script:

cd PluginHandler/

This script does not have a PID file and we run this script by executing

./rundaemon.sh &disown

./pluginhandler starts the process and starts logging into /etc/output/output.log I stop the process by identifying the process ID with [ps -f | grep PluginHandler] and then killing the process.

I can check the process in Monit just fine, but I think Monit is starting the process if it is not running but it can't do &disown so the process ends as soon as it starts.

This is the code in the monitrc file for checking this process:

check process Backend
matching "PluginHandler"
if not exist
then alert
start "PATH/TO/SCRIPT/rundaemon.sh &disown"
alert example@gmail.com only on {timeout} with mail-format {subject: "[BLAH"}

I tried to stop the script from terminating by modifying the script like the following but this does not work either.

export LD_LIBRARY_PATH=/usr/local/lib/:/home/CONFIDENTAL/production/CONFIDENTAL/Common/
cd PluginHandler/
(nohup ./PluginHandler &)

Any help to write a proper Monit rules to resolve this issue would be greatly appreciated :)


Don't use disown...

I don't know the full contents of the script, but you should really try to use a PID file if possible. But you can use Monit to start and stop the process regardless.

check process Backend
        matching "PluginHandler"
        start program = "/path/to/rundaemon.sh" as uid user
        stop program = "/usr/bin/pkill -f PluginHandler"

This alone will make sure the process is working. You'll probably want something more specific in the "matching" string. Test with monit procmatch <string> to see what Monit will detect. It will only monitor the first occurrence of the matched process.

You can start the process with monit start Backend and stop it with monit stop Backend, provided there's a graceful method to stop the script.

  • Hi, thanks for the quick reply. I tried your suggestion but this does not work. The monit log states "'Backend' failed to start". It attempts to restart the Backend but keeps failing. – Solas Admin Aug 25 '14 at 15:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.