linux - 无法在监视器中启动脚本
问题描述
我有一个脚本必须在后台运行另一个脚本:
#!/bin/bash
( cd /var/lib/docker/volumes/hostcontrol-pipe/_data/ && ./run-pipe.sh ) &
首先,它更改目录并运行脚本。run-pipe.sh 在其目录中创建命名管道。我有一个 monit 配置文件来监控这个脚本,如果它没有运行就重新启动它:
check program check-pipe with path /bin/bash -c "echo 'ping' > /var/lib/docker/volumes/hostcontrol-pipe/_data/host-pipe" with timeout 1 seconds
if status != 0 then
restart
start program = "/var/lib/docker/volumes/hostcontrol-pipe/_data/monit.sh"
第一行检查脚本正在运行写入其管道,它可以工作。“启动程序”行不起作用 - 脚本不运行并且它在“ps ax”中不存在。但我在“sudo monit -vI”中看到:
'check-pipe' start: '/var/lib/docker/volumes/hostcontrol-pipe/_data/monit.sh'
'check-pipe' started
'check-pipe' program started
那么,为什么 monit 不能运行脚本呢?我尝试了不同的变体,但无法运行它。我可以在不更改目录 (cd) 的情况下运行它,但这是必要的。
解决方案
实际上 monit 无法在后台运行脚本,因为 where 没有输出。添加输出文件后,它开始工作。
start program = "/bin/bash -c 'cd /var/lib/docker/volumes/hostcontrol-pipe/_data && ./run-pipe.sh > 1.log &'"
否则 /dev/null 作为输出流。
推荐阅读
- istio - 如何通过 Minikube/Windows 上的 Istio 中的 Gateway 或 Ingress 访问 hello world Java 微服务?我被困了几个小时/几天/几周
- reactjs - 尝试通过 Apollo Query 和 Formik 在 React 渲染道具中使用函数时的 Typescript TS2349
- three.js - 如何以编程方式撤消到枢轴点的位置转换?
- java - 是否可以在不使用 JavaMail api 对端口进行硬编码的情况下连接到邮件服务器,基本上代码应该独立于端口。?
- c# - 如何在异步函数中发送参数值
- mysql - 创建kafka连接器时,使用localhost:8083,总是报错:curl(7) connection denied
- vb.net - Visual Studio 2010 @ 高 DPI
- reactjs - 如何从子组件中获取父级中的值(来自输入)
- php - 从两个不同的多维数组中获取唯一值
- cmake - 在柯南 cmake 配置中包含路径错误