【问题标题】:Monit fails to start processMonit 无法启动进程
【发布时间】:2013-05-13 20:05:21
【问题描述】:

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

#!/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

【问题讨论】:

  • 您的程序是否需要超过 10 秒才能启动?
  • 我也试过timeout 30,开机不到5秒。即使我将原始命令“R CMD Rserve”与“\bin\bash -c”放在monitrc上,它也不起作用。似乎无法从 monit daemon 启动它。
  • 你有没有想过这个问题?我也有类似的问题。
  • 我也有同样的问题。无法弄清楚为什么它不会启动

标签: bash monit


【解决方案1】:

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

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

它对我有用。

【讨论】:

【解决方案2】:

monit 是一个沉默的杀手。它什么也没告诉你。以下是我会检查哪些监视器无法帮助您识别的内容

  1. 检查您正在读/写的所有文件的权限。如果要将输出重定向到文件,请确保该文件可由您用于执行程序的 uid 和 gid 写入
  2. 再次检查您尝试运行的程序的 exec 权限
  3. 为您尝试执行的任何程序指定完整路径(并非绝对必要,但如果您始终指定完整路径,则不必担心未设置路径)
  4. 在尝试调查 monit 未启动的原因之前,请确保您可以在 monit 之外运行程序而不会出现任何错误。

【讨论】:

    【解决方案3】:

    如果正在显示监控日志

    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】:

      当 monit 启动时,它会检查自己的 pidfile 并检查进程是否使用 匹配的 PID 已经在运行 - 如果它运行,那么它只是唤醒这个 过程。

      在你的情况下,检查这个 pid 是否被其他进程使用: ps -ef |grep 4370

      如果是,那么您需要删除以下文件(通常在 /run 目录下)并重新启动监控: 监控.pid

      【讨论】:

        【解决方案5】:

        对我来说,问题是停止命令没有运行,即使我在配置中特别指定了“然后重新启动”。 解决方案就是改变: 启动程序 = "/etc/init.d/....重启"

        【讨论】:

          猜你喜欢
          • 2022-11-30
          • 2016-01-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-07-07
          • 1970-01-01
          • 2016-11-24
          • 2018-12-11
          相关资源
          最近更新 更多