【问题标题】:monit removes quotes from start program commandsmonit 从启动程序命令中删除引号
【发布时间】:2013-07-30 09:35:12
【问题描述】:

我正在调试 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'""

我已经在 shell 中测试过

$ 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 文档中找不到任何关于此的内容。文档here 似乎是最终参考,但由于缺少源代码,我不确定下一步该做什么。

我的命令在没有删除引号的情况下完美运行,所以我只需要解决这个问题。欢迎所有想法和可能的修复。

【问题讨论】:

    标签: linux bash amazon-ec2 monit


    【解决方案1】:

    这是一个很晚的答案,但我觉得它很重要,因为它会引起一些误解(所以我被误导了)

    您不需要转义单引号字符。试试看:

    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 以捕获进程并检查其属性。

    该问题可能是由某些特定于环境的问题引起的。

    【讨论】:

      【解决方案2】:

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

      另外,尝试使用斜杠将其转义为单引号

      \'

      (我没有尝试过,所以我不知道它是否有效)。

      【讨论】:

        猜你喜欢
        • 2013-10-28
        • 1970-01-01
        • 2022-11-30
        • 2020-07-03
        • 1970-01-01
        • 1970-01-01
        • 2013-04-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多