PM2 under Monit

Discussion in 'Server Operation' started by Poliman, Dec 22, 2017.

  1. Poliman

    Poliman Member

    I try monitor web apps based on nodejs using monit software. I did (works perfectly - mail notification, auto restart if process not working) in /etc/monit/monitrc file:
    Code:
    check process test matching /root/test.js       #test.js file inside root folder
    start program = "/bin/bash -c 'cd /root && PM2_HOME=/root/.pm2 /usr/local/bin/pm2 start test'"
    stop program = "/bin/bash -c 'cd /root && PM2_HOME=/root/.pm2 /usr/local/bin/pm2 stop test'"
    
    but I need to make working not only test nodejs server but whole app:
    Code:
    check process kreacja_test matching /var/www/clients/client4/web4/web/tkreacja/kreacja_server.js
    start program = "/bin/bash -c 'cd /var/www/clients/client4/web4/web/tkreacja && PM2_HOME=/root/.pm2 /usr/local/bin/PORT=3003 pm2 start kreacja_server.js'"
    stop program = "/bin/bash -c 'cd /var/www/clients/client4/web4/web/tkreacja && PM2_HOME=/root/.pm2 /usr/local/bin/pm2 stop kreacja_server.js'"
    
    and it is not working. In log file I got:
    Code:
    [CET Dec 22 11:12:59] error    : 'kreacja_test' process is not running
    [CET Dec 22 11:12:59] info     : 'kreacja_test' trying to restart
    [CET Dec 22 11:12:59] info     : 'kreacja_test' start: /bin/bash
    [CET Dec 22 11:13:29] error    : 'kreacja_test' failed to start (exit status 0) -- /bin/bash: mesg: ttyname failed: Inappropriate ioctl for device
    
    There is only one difference. Test server has port (in this example 3002 - works fine) put manually inside file. Web app has PORT as an environment variable put to pm2 (this variable is reading inside file) -> PORT=3003 pm2 start kreacja_server.js. Does anybody know to fix it?
     
    Last edited: Dec 22, 2017
  2. Poliman

    Poliman Member

    I fixed it by adding "-- -p 3003":
    Code:
    check process kreacja_test matching /var/www/clients/client4/web4/web/tkreacja/kreacja_server.js
    start program = "/bin/bash -lc 'cd /var/www/clients/client4/web4/web/tkreacja && PM2_HOME=/root/.pm2 /usr/local/bin/pm2 start kreacja_server -- -p 3003'"
    stop program = "/bin/bash -lc 'cd /var/www/clients/client4/web4/web/tkreacja && PM2_HOME=/root/.pm2 /usr/local/bin/pm2 stop kreacja_server'"
    
     

Share This Page