我已经编写了一个可以正常启动和停止服务器的脚本。
#!/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
这是monitrc:
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
答案 0 :(得分:6)
我也有问题通过shell启动或停止进程。 一种解决方案可能是添加" / bin / bash"在这样的配置中:
start program = "/bin/bash /urs/bin/rserv start"
stop program = "/bin/bash /urs/bin/rserv stop"
它对我有用。
答案 1 :(得分:3)
答案 2 :(得分:0)
当monit启动时,它会检查自己的pidfile并检查进程是否正常 匹配PID已经运行 - 如果是,那么它只是唤醒它 过程
在您的情况下,检查其他进程是否正在使用此pid: ps -ef | grep 4370
如果是,那么你需要删除下面的文件(通常在/ run目录下)并再次启动monit: monit.pid
答案 3 :(得分:0)
如果监视日志正在显示
failed to start (exit status -1) -- no output
然后可能是您正在尝试在没有任何Bash基础结构的情况下运行脚本。您可以通过将其包装在/bin/bash -c
中来运行这样的命令,如下所示:
check process my-process
matching "my-process-name"
start program = "/bin/bash -c '/etc/init.d/my-init-script'"
答案 4 :(得分:0)
对我来说,问题是即使我在配置上特别指定了“然后重新启动”,也没有运行stop命令。 解决方案只是更改: 启动程序=“ /etc/init.d / ....重新启动”