linux - monit 从启动程序命令中删除引号

标签 linux bash amazon-ec2 monit

我正在调试 monit 启动/停止程序语句。在我的 /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似乎是最终引用,但由于没有查看源代码,我不确定下一步该怎么做。

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

最佳答案

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

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

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

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

关于linux - monit 从启动程序命令中删除引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17943357/

相关文章:

linux - 如何查找和停止/终止从 shell 脚本启动的进程?

python-3.x - 在 AWS Ubuntu EC2 实例中使用 Python 进行 IP 切换

linux - tar 命令后 Docker 运行时错误

MySql 文件大小限制选项

c - 使用路由表查找目标地址的接口(interface)名称

mysql - 结合 bash 和 SQL 脚本来创建 wordpress 站点

linux - 删除 bash 脚本中除最新 3 个以外的所有文件

linux - 删除 ls -l 输出中的多个空格

oracle - 在 aws ec2 实例上获取 ORA-01882 : timezone region not found with Oracle UCP,?

python - 使用 python boto 删除 Amazon EC2 实例