我正在调试 monit start/stop 程序语句。在我的/etc/monit.conf
文件中,我的start program
声明如下所示:
check process node with pidfile /home/ec2-user/blah/node.pid
start program = "/bin/su -c 'export APP_ENV=development; /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js start &> /tmp/monit.out ' "
stop program = "/bin/su -c '/home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js stop'""
我已经在外壳中测试过
$ sudo su
# env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/sh
# /bin/su -c '/usr/bin/env APP_ENV=development; /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js start &> /tmp/monit.out '
运行它会在/tmp/monit.out
文件中返回正确的输出:
Starting nodejs daemon...
nodejs daemon started. PID: 16408
但是当我运行时sudo monit -v monitor node
,它会显示一个不同的命令,除了删除了内部单引号外,其他命令相同:
The service list contains the following entries:
Process Name = node
Pid file = /home/ec2-user/blah/node.pid
Monitoring mode = active
Start program = '/bin/su -c export APP_ENV=development; /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js start &> /tmp/monit.out ' timeout 30 second(s)
Stop program = '/bin/su -c /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js stop' timeout 30 second(s)
Existence = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert
Pid = if changed 1 times within 1 cycle(s) then alert
Ppid = if changed 1 times within 1 cycle(s) then alert
System Name = system_ip-xx-xx-xx-xx.ec2.internal
Monitoring mode = active
我在 monit 文档中找不到任何关于此的内容。这里的文档似乎是最终的参考,但缺少源代码,我不确定下一步该做什么。
我的命令在没有删除引号的情况下完美运行,所以我只需要解决这个问题。欢迎所有想法和可能的修复。