无法在monit中启动脚本

问题描述 投票:0回答:1

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

#!/bin/bash
( cd /var/lib/docker/volumes/hostcontrol-pipe/_data/ && ./run-pipe.sh ) &

首先,它更改目录并运行脚本。 run-pipe.sh在其目录中创建命名管道。而且我有一个监视配置文件来监视此脚本,并在未运行时重新启动它:

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),但这是必要的。

linux monit
1个回答
0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.