Monit无法重新启动nginx

我已经开始在Ubuntu 12.04服务器上运行,监视nginx,但是我无法再次成功启动nginx。 我的设置是:monitconfiguration文件是:

-rwx------ 1 root root 10329 2015-07-31 09:39 /etc/monit/monitrc 

和monitrc文件的内容(非注释)是

 set daemon 60 set logfile /var/www/apps/myapp/log/monit.log set httpd port 2812 use address mysite.com allow username:password 'password' check system mysite.com if loadavg (1min) > 4 then alert if loadavg (5min) > 2 then alert if memory usage > 75% then alert if cpu usage (user) > 70% then alert if cpu usage (system) > 30% then alert if cpu usage (wait) > 20% then alert check process nginx with pidfile /opt/nginx/logs/nginx.pid start program = "/etc/init.d/nginx restart; touch /var/www/apps/myapp/tmp/restart.txt" stop program = "/etc/init.d/nginx stop" 

我开始与sudo monit

如果我杀了nginx,然后等待monit尝试启动它,我可以在日志文件中看到:

 [UTC Jul 31 09:39:26] info : Reinitializing monit daemon [UTC Jul 31 09:39:26] info : Starting monit HTTP server at [mysite.com:2812] [UTC Jul 31 09:39:26] info : monit HTTP server started [UTC Jul 31 09:39:26] info : 'myhost.mydomain.tld' Monit reloaded [UTC Jul 31 09:40:26] error : 'nginx' process is not running [UTC Jul 31 09:40:26] info : 'nginx' trying to restart [UTC Jul 31 09:40:26] info : 'nginx' start: /etc/init.d/nginx [UTC Jul 31 09:40:56] error : 'nginx' failed to start 

当我在terminal自己运行nginx restart命令时,它工作正常:

 sudo /etc/init.d/nginx restart; touch /var/www/apps/myapp/tmp/restart.txt 

这将重新启动它的罚款( touch命令是重新加载在Passenger下运行的ruby应用程序 – 触摸重新启动文件触发应用程序的重新启动。

在monitconfiguration中将touch命令取出不起作用没有任何区别。 当我尝试通过monit的Web界面重新启动nginx时,也会失败。

我认为,如果我能以某种方式将STDERR和STDOUTstream写入日志文件,那么当monit尝试启动nginx时,至less会有所帮助。

有什么build议么?

monit不接受start program / stop program shell脚本。 你需要这样写:

 check process nginx with pidfile /opt/nginx/logs/nginx.pid start program = "/bin/sh -c '/etc/init.d/nginx restart; touch /var/www/apps/myapp/tmp/restart.txt'" stop program = "/etc/init.d/nginx stop"