2013-07-30 22 views
6

我正在調試monit啓動/停止程序語句。在我/etc/monit.conf文件,我start program聲明是這樣的:monit從啓動程序命令中刪除引號

check process node with pidfile /home/ec2-user/blah/node.pid 
    start program = "/bin/su -c 'export APP_ENV=development; /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js start &> /tmp/monit.out ' " 
    stop program = "/bin/su -c '/home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js stop'"" 

我已經在一個外殼,

$ sudo su 
# env -i PATH=/bin:/usr/bin:/sbin:/usr/sbin /bin/sh 
# /bin/su -c '/usr/bin/env APP_ENV=development; /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js start &> /tmp/monit.out ' 

運行這個返回的/tmp/monit.out文件的正確輸出測試:

Starting nodejs daemon... 
nodejs daemon started. PID: 16408 

但是當我運行sudo monit -v monitor node,它顯示一個不同的命令,完全相同的exce PT與內單引號去掉

The service list contains the following entries: 

Process Name   = node 
Pid file    = /home/ec2-user/blah/node.pid 
Monitoring mode  = active 
Start program  = '/bin/su -c export APP_ENV=development; /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js start &> /tmp/monit.out ' timeout 30 second(s) 
Stop program   = '/bin/su -c /home/ec2-user/local/bin/node /home/ec2-user/example.com/current/api.js stop' timeout 30 second(s) 
Existence   = if does not exist 1 times within 1 cycle(s) then restart else if succeeded 1 times within 1 cycle(s) then alert 
Pid     = if changed 1 times within 1 cycle(s) then alert 
Ppid     = if changed 1 times within 1 cycle(s) then alert 

System Name   = system_ip-xx-xx-xx-xx.ec2.internal 
Monitoring mode  = active 

我無法找到有關這個monit的文檔中的任何東西。文檔here似乎是最終的參考,但通過源代碼很短,我不知道接下來要做什麼。

我的命令完美地工作,沒有刪除引號,所以我只需要解決這個問題。歡迎所有的想法和可能的修復。

回答

2

這是一個很遲的答案,但我覺得很重要的,因爲它會導致一些誤解(所以我的誤導)

你不需要逃脫單引號字符。試試看:

check process fake_proc 
    with pidfile /tmp/test_pid 
    start = "/bin/bash -c 'echo $$ > /tmp/test_pid'" 
    stop = "echo stop > /tmp/test_pid" 

它不會顯示爲一個啓動的過程中,創建但是test_pid文件。添加; sleep xx來捕捉進程並檢查其屬性。

這個問題可能是由一些env特定的問題造成的。

0

將有關「啓動程序」和「停止程序」的命令放入shell腳本中,使其可執行,然後將其地址發送給monit。

也設法逃脫它的單引號用斜線

\」

(我還沒有嘗試過,所以我不知道,如果它的工作原理)。

+3

單引號轉義不起作用 – dubeegee