2013-07-30 26 views
6

我正在调试monit启动/停止程序语句。在我/etc/monit.conf文件,我start program声明是这样的:monit从启动程序命令中删除引号

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,它显示一个不同的命令,完全相同的exce PT与内单引号去掉

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的文档中的任何东西。文档here似乎是最终的参考,但通过源代码很短,我不知道接下来要做什么。

我的命令完美地工作,没有删除引号,所以我只需要解决这个问题。欢迎所有的想法和可能的修复。

回答

2

这是一个很迟的答案,但我觉得很重要的,因为它会导致一些误解(所以我的误导)

你不需要逃脱单引号字符。试试看:

check process fake_proc 
    with pidfile /tmp/test_pid 
    start = "/bin/bash -c 'echo $$ > /tmp/test_pid'" 
    stop = "echo stop > /tmp/test_pid" 

它不会显示为一个启动的过程中,创建但是test_pid文件。添加; sleep xx来捕捉进程并检查其属性。

这个问题可能是由一些env特定的问题造成的。

0

将有关“启动程序”和“停止程序”的命令放入shell脚本中,使其可执行,然后将其地址发送给monit。

也设法逃脱它的单引号用斜线

\”

(我还没有尝试过,所以我不知道,如果它的工作原理)。

+3

单引号转义不起作用 – dubeegee