2

We have socket listener which listens on port 9000 so below is how we wrote the alert for monit. The listener runs via yajsw daemon tool. So currently when it fails on port 9000 we get an email. What we want to extend is that if it is not running to stop,uninstall, install and finally start programe. We have all the script to the processes stated but how to put in monit? All of it are in shell script files.

check process cs9000 with pidfile /var/run/wrappercs9000.pid # check your app pid

  start program  = 
  stop program  =
 if failed port 9000    # if you want to check your app that listen on port 9000
    then 
    restart
biz14
  • 371
  • 1
  • 3
  • 10

1 Answers1

1

With Monit, you won't get the ability to restart the program until you provide the start program and stop program directives. When you populate those options and restart Monit, you'll gain the ability to take actions based on process conditions.

An example:

check process nslcd
        with pidfile "/var/run/nslcd/nslcd.pid"
        start program = "/sbin/service nslcd start"
        stop program = "/sbin/service nslcd stop"
        if 10 restarts within 11 cycles then timeout
        if cpu usage > 95% for 11 cycles then restart
        if totalmemory > 472 MB then restart

If you want the "stop program" to run a script, give the full path to the script.

ewwhite
  • 194,921
  • 91
  • 434
  • 799
  • what I want to do is that to detect if my app is not running then I want to run the stop script followed by uninstall script. Then I want to run install and finally start script. How will the stop program take two script is that possible? – biz14 Feb 13 '13 at 03:44
  • Yes... or you can wrap the stop and uninstall script into one script. – ewwhite Feb 13 '13 at 04:02
  • ok let me understand it first the cs9000 with pidfile /var/run/wrappercs9000.pid will check the process with process id exist or not then it will run the start or stop first? So when will it then check failed port and restart should do wat ? Can you explain the sequence I am lost here. – biz14 Feb 13 '13 at 04:20
  • If the PID doesn't exist, the process will start using the command you specify. If the PID dies, the process will restart using the stop command and start command. – ewwhite Feb 13 '13 at 04:32
  • ok now I am clearer thank you. So how to have two scripts under the stop and start command accordingly. – biz14 Feb 13 '13 at 05:01
  • `start program = "/path/to/script1 && /path/to/script2"` – ewwhite Feb 13 '13 at 05:02