Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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/ # check your app pid

  start program  = 
  stop program  =
 if failed port 9000    # if you want to check your app that listen on port 9000
share|improve this question
up vote 1 down vote accepted

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/"
        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.

share|improve this answer
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 3:44
Yes... or you can wrap the stop and uninstall script into one script. – ewwhite Feb 13 '13 at 4:02
ok let me understand it first the cs9000 with pidfile /var/run/ 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 4: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 4: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 5:01

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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