gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:58:00 26 4
gpt4 key购买 nike

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

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com