gpt4 book ai didi

bash - Monit 无法启动进程

转载 作者:行者123 更新时间:2023-11-29 09:35:38 26 4
gpt4 key购买 nike

我写了一个可以很好地启动和停止服务器的脚本。

#!/bin/bash

PID_FILE='/var/run/rserve.pid'

start() {
touch $PID_FILE
eval "/usr/bin/R CMD Rserve"
PID=$(ps aux | grep Rserve | grep -v grep | awk '{print $2}')
echo "Starting Rserve with PID $PID"
echo $PID > $PID_FILE
}
stop () {
pkill Rserve
rm $PID_FILE
echo "Stopping Rserve"
}

case $1 in
start)
start
;;
stop)
stop
;;
*)
echo "usage: rserve {start|stop}" ;;
esac
exit 0

如果我通过运行来启动它

rserve start

然后启动monit 它将正确捕获 PID 和服务器:

The Monit daemon 5.3.2 uptime: 0m 

Remote Host 'localhost'
status Online with all services
monitoring status Monitored
port response time 0.000s to localhost:6311 [DEFAULT via TCP]
data collected Mon, 13 May 2013 20:03:50

System 'system_gauss'
status Running
monitoring status Monitored
load average [0.37] [0.29] [0.25]
cpu 0.0%us 0.2%sy 0.0%wa
memory usage 524044 kB [25.6%]
swap usage 4848 kB [0.1%]
data collected Mon, 13 May 2013 20:03:50

如果我停止它,它会正确地终止进程并解除对它的监控。但是,如果我再次启动它,它不会再次启动服务器:

ps ax | grep Rserve | grep -vc grep
1
monit stop localhost
ps ax | grep Rserve | grep -vc grep
0
monit start localhost

[UTC May 13 20:07:24] info : 'localhost' start on user request
[UTC May 13 20:07:24] info : monit daemon at 4370 awakened
[UTC May 13 20:07:24] info : Awakened by User defined signal 1
[UTC May 13 20:07:24] info : 'localhost' start: /usr/bin/rserve
[UTC May 13 20:07:24] info : 'localhost' start action done
[UTC May 13 20:07:34] error : 'localhost' failed, cannot open a connection to INET[localhost:6311] via TCP

这是监控器:

check host localhost with address 127.0.0.1
start = "/usr/bin/rserve start"
stop = "/usr/bin/rserve stop"
if failed host localhost port 6311 type tcp with timeout 15 seconds for 5 cycles
then restart

最佳答案

我也有通过 shell 启动或停止进程的问题。一种解决方案可能是在配置中添加“/bin/bash”,如下所示:

start program = "/bin/bash /urs/bin/rserv start"
stop program = "/bin/bash /urs/bin/rserv stop"

它对我有用。

关于bash - Monit 无法启动进程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16530235/

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