bash Monit 无法启动进程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16530235/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Monit fails to start process
提问by Jo?o Daniel
I've written a scrip that works fine to start and stop a server.
我写了一个可以很好地启动和停止服务器的脚本。
#!/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 }')
echo "Starting Rserve with PID $PID"
echo $PID > $PID_FILE
}
stop () {
pkill Rserve
rm $PID_FILE
echo "Stopping Rserve"
}
case in
start)
start
;;
stop)
stop
;;
*)
echo "usage: rserve {start|stop}" ;;
esac
exit 0
If I start it by running
如果我通过运行来启动它
rserve start
and then start monitit will correctly capture the PID and the server:
然后启动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
If I stop it, it will properly kill the process and unmonitor it. However if I start it again, it won't start the server again:
如果我停止它,它将正确终止进程并取消监视它。但是,如果我再次启动它,它将不会再次启动服务器:
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
Here is the 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
回答by Green Su
I had problem start or stop process via shell too. One solution might be add "/bin/bash" in the config like this:
我也有通过 shell 启动或停止进程的问题。一种解决方案可能是在配置中添加“/bin/bash”,如下所示:
start program = "/bin/bash /urs/bin/rserv start"
stop program = "/bin/bash /urs/bin/rserv stop"
It worked for me.
它对我有用。
回答by dminer
monit is a silent killer. It does not tell you anything. Here are things I would check which monit won't help you identify
monit 是一个沉默的杀手。它不会告诉你任何事情。以下是我会检查哪些监视器无法帮助您识别的内容
- Check permissions of all the files you are reading / writing. If you are redirecting output to a file, make sure that file is writable by uid and gid you are using to execute the program
- Again check exec permission on the program you are trying to run
- Specify full path to any program you are trying to execute ( not strictly necessary, but you don't have to worry about path not being set if you always specify full path )
- Make sure you can run the program outside of monit without any error before trying to investigate why monit is not starting.
- 检查您正在读/写的所有文件的权限。如果要将输出重定向到文件,请确保该文件可由用于执行程序的 uid 和 gid 写入
- 再次检查您尝试运行的程序的 exec 权限
- 指定您尝试执行的任何程序的完整路径(并非绝对必要,但如果您始终指定完整路径,则不必担心未设置路径)
- 在尝试调查 monit 未启动的原因之前,请确保您可以在 monit 之外运行该程序而不会出现任何错误。
回答by jevon
If the Monit log is displaying
如果 Monit 日志显示
failed to start (exit status -1) -- no output
Then it may be that you're trying to run a script without any of the Bash infrastructure. You can run such a command by wrapping it in /bin/bash -c, like so:
那么可能是您试图在没有任何 Bash 基础设施的情况下运行脚本。您可以通过将其包装在 中来运行这样的命令/bin/bash -c,如下所示:
check process my-process
matching "my-process-name"
start program = "/bin/bash -c '/etc/init.d/my-init-script'"
回答by xmaster
For me, the issue was that the stop command was not being run, even though I specifically specified "then restart" on the configuration. The solution was just to change: start program = "/etc/init.d/.... restart"
对我来说,问题是停止命令没有运行,即使我在配置上特别指定了“然后重新启动”。解决方案只是更改: start program = "/etc/init.d/.... restart"
回答by Sam
When monit starts it checks for its own pidfile and checks if the process with matching PID is running already - if it does, then it just wakes up this process.
当 monit 启动时,它会检查自己的 pidfile 并检查具有匹配 PID 的进程是否已经在运行——如果已经运行,那么它只是唤醒这个进程。
in your case, check if this pid is being used by some other process: ps -ef |grep 4370
在你的情况下,检查这个 pid 是否被其他进程使用:ps -ef |grep 4370
if yes, then you need to remove the below file(usually under /run directory) and start monit again: monit.pid
如果是,那么您需要删除以下文件(通常在 /run 目录下)并再次启动 monit:monit.pid

