2013-05-13 119 views
2

我寫了一個可以正常啓動和停止服務器的腳本。Monit無法啓動進程

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

難道你的程序需要10秒以上才能啓動? – Wrikken 2013-05-13 20:13:28

+0

我也試過超時30,啓動時間不到5秒。即使我將原始命令「R CMD Rserve」與monitrc中的「\ bin \ bash -c」一起使用,它也不起作用。它似乎無法從monit守護進程啓動它。 – 2013-05-13 20:25:25

+0

你有沒有想過這個?我有類似的問題。 – StFS 2013-10-11 11:50:27

回答

6

我有問題開始或通過殼停止過程了。 一種解決方案可能會在這樣的配置可以添加「/斌/慶典」:

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

它爲我工作。

+0

順便說一句,我從這個http://lists.gnu.org/archive/html/monit-general/2008-12/msg00004.html – 2013-10-25 08:27:11

+0

得到的信息也看到這個http:///lists.gnu.org/archive/html/monit-general/2010-01/msg00035。html – 2013-10-25 08:29:08

+3

此解決方案在monit的FAQ中更詳細地描述了爲什麼它需要以及如何使用它http://mmonit.com/wiki/Monit/FAQ#execution – LeoR 2014-03-20 13:56:58

3

monit是一個沉默的殺手。它沒有告訴你任何事情。這裏是我會檢查哪些監視不會幫助您識別的東西

  1. 檢查您正在讀/寫的所有文件的權限。如果要重定向輸出到文件,確保文件是UID寫入和gid您使用的是執行程序
  2. 再次檢查該程序的exec允許你嘗試運行
  3. 指定任何程序的完整路徑你正在嘗試執行(不是絕對必要的,但是如果你總是指定完整路徑,你不必擔心路徑沒有被設置)
  4. 確保你可以在沒有任何錯誤的情況下運行monit之外的程序,然後嘗試調查monit爲什麼沒有開始。
0

monit的時候就開始檢查自己的和了pidfile檢查是否有 匹配PID的進程已經在運行 - 如果確實如此,那麼它只是喚醒這 過程。

你的情況

,檢查這個PID正被其他進程: PS英法| grep的4370

如果是,那麼你需要刪除以下文件(通常在/運行目錄)和再次啓動監視: monit.pid