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:
export LD_LIBRARY_PATH=/usr/local/lib/:/CONFIDENTAL/CONFIDENTAL/Common/
cd PluginHandler/
./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 &)
return
Any help to write a proper Monit rules to resolve this issue would be greatly appreciated :)