首页 > 解决方案 > 无法在监视器中启动脚本

问题描述

我有一个脚本必须在后台运行另一个脚本:

#!/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) 的情况下运行它,但这是必要的。

标签: linuxmonit

解决方案


实际上 monit 无法在后台运行脚本,因为 where 没有输出。添加输出文件后,它开始工作。

start program = "/bin/bash -c 'cd /var/lib/docker/volumes/hostcontrol-pipe/_data && ./run-pipe.sh > 1.log &'"

否则 /dev/null 作为输出流。


推荐阅读