I need to start pm2 apps using monit. Im not able to restart it or exec a script which sends messages to slack channel. Can some one help.
On monit logs it says trying to restart, but it gives
[UTC Jan 6 10:19:01] error : 'server' failed to start (exit status 1) -- no output
My monit config is this
check process server with pidfile /home/otheruser/.pm2/pids/server-0.pid
start program = "/home/otheruser/.nvm/versions/node/v5.2.0/bin/pm2 start 0" as uid "otheruser" and gid "otheruser"
stop program = "/home/otheruser/.nvm/versions/node/v5.2.0/bin/pm2 stop 0" as "otheruser" and gid "otheruser"
if failed host 127.0.0.1 port 3002 then restart
if failed host 127.0.0.1 port 3002 then exec "/etc/monit/slack_notifications.sh"
if failed host 127.0.0.1 port 3002 for 2 cycles then exec "/etc/monit/slack_notifications.sh" else if succeeded then exec "/etc/monit/slack_notifications.sh"
#only this line works, above lines are not working
if 5 restarts within 5 cycles then exec "/etc/monit/slack_notifications.sh"
Only otheruser can run pm2 commands here.
Dont know why this is not working as well as the failed host check is not triggering the shell file.
This is the shell file
#!/bin/sh
/usr/bin/curl
-X POST
-s
--data-urlencode "payload={
"channel": "my-channel",
"username": "Monit",
"pretext": "servername | $MONIT_DATE",
"color": "danger",
"icon_emoji": ":ghost:",
"text": "$MONIT_SERVICE - $MONIT_DESCRIPTION"
}"
my slack webhook
```