我需要使用 monit 启动 pm2 应用程序。我无法重新启动它或执行将消息发送到松弛通道的脚本。有人可以帮忙吗。
在 monit 日志上,它说正在尝试重新启动,但它给出了
[UTC Jan 6 10:19:01] error : 'server' failed to start (exit status 1) -- no output
我的监控配置是这样的
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"
这里只有其他用户可以运行 pm2 命令。
不知道为什么这不起作用,因为失败的主机检查没有触发 shell 文件。
这是shell文件
#!/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
```