Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I want to use monit for ability to reload pm2 node.js site if response is longer than 2 seconds.

This is my monit config /etc/monit/monitrc:

check process pm2 with pidfile "/root/.pm2/pids/siteName9000.pid" 
        start program = "/usr/local/bin/pm2 start ~/pathToNodeApp/9000/app.js --name siteName9000" 
        stop program  = "/usr/local/bin/pm2 stop siteName9000" 
        if failed port 9000 protocol HTTP 
            request / 
            with timeout 2 seconds 
            then restart

Then in console I run:

# monit restart pm2

Then in console I run:

# monit -d 10 -c /etc/monit/monitrc

to make this checking every 10 seconds.

Then in monit log /var/log/monit.log I see:

[MSK May 18 06:57:05] info     : 'pm2' restart on user request
[MSK May 18 06:57:05] info     : monit daemon with PID 22480 awakened
[MSK May 18 06:57:05] info     : Awakened by User defined signal 1
[MSK May 18 06:57:05] info     : 'pm2' trying to restart
[MSK May 18 06:57:05] info     : 'pm2' start: /usr/local/bin/pm2
[MSK May 18 06:57:36] error    : 'pm2' failed to start
[MSK May 18 06:57:36] info     : 'pm2' restart action done
[MSK May 18 06:58:27] info     : Awakened by User defined signal 1
[MSK May 18 06:58:27] error    : 'pm2' process is not running
[MSK May 18 06:58:27] info     : 'pm2' trying to restart
[MSK May 18 06:58:27] info     : 'pm2' start: /usr/local/bin/pm2
[MSK May 18 06:58:27] info     : monit daemon with PID 22480 awakened
[MSK May 18 06:58:58] error    : 'pm2' failed to start
[MSK May 18 07:00:58] error    : 'pm2' process is not running
[MSK May 18 07:00:58] info     : 'pm2' trying to restart
[MSK May 18 07:00:58] info     : 'pm2' start: /usr/local/bin/pm2

So my monit config not working.

share|improve this question
    
I think your check interval is too small. What happens at 30 seconds? 60 seconds? –  ewwhite May 18 at 3:19
    
changed 10 seconds to 60: the same result –  efr May 18 at 3:23
    
In start program directive, what happens if you replace ~ by /full/path/to/pathToNodeApp/9000/app.js........ ? –  krisFR May 18 at 23:50

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.