Centos

使用 supervisord 執行(和監控)nginx

  • November 26, 2014

我將從我的案例開始,因為我很可能沒有使用正確的工具來完成這項工作。請讓我知道我是否以錯誤的方式去做這件事

案例:我有一個託管多個 Web 應用程序的 CentOS 伺服器。我希望能夠相信我的 Web 伺服器和應用程序伺服器將執行。我的堆棧看起來像

  • 網路伺服器:nginx
  • 應用伺服器:uWSGI
  • 網路框架:燒瓶/python

我想使用 supervisord 來監控 nginx 和 uWSGI。在我的 /etc/supervisor.conf 中,我有

[program:nginxgo]
command = /usr/sbin/nginx
autostart=true
autorestart=unexpected
exitcodes=0
stdout_logfile=/home/webdev/nginxgo.log
stderr_logfile=/home/webdev/nginxgoerr.log

[program:uwsgi_emperor_go]
command = uwsgi --emperor /etc/uwsgi/emperor.ini
autostart=true
autorestart=unexpected
stopsignal=INT
stdout_logfile=/home/webdev/emp.log
stderr_logfile=/home/webdev/emperr.log
directory=/home/webdev/
user=webdev

我啟動了 uWSGI 程序。當我進入[root@mymachine]# /usr/local/bin/supervisord -n -c /etc/supervisord.conf

輸出是

2014-11-26 14:07:56,917 CRIT Supervisor running as root (no user in config file)
2014-11-26 14:07:56,951 CRIT Server 'inet_http_server' running without any HTTP authentication checking
2014-11-26 14:07:56,952 INFO supervisord started with pid 31068
2014-11-26 14:07:57,957 INFO spawned: 'nginxgo' with pid 31071
2014-11-26 14:07:57,970 INFO spawned: 'uwsgi_emperor_go' with pid 31072
2014-11-26 14:07:59,095 INFO success: nginxgo entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:07:59,095 INFO success: uwsgi_emperor_go entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:00,601 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:01,607 INFO spawned: 'nginxgo' with pid 31079
2014-11-26 14:08:02,684 INFO success: nginxgo entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:04,189 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:05,194 INFO spawned: 'nginxgo' with pid 31080
2014-11-26 14:08:06,264 INFO success: nginxgo entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:07,771 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:08,775 INFO spawned: 'nginxgo' with pid 31081
2014-11-26 14:08:09,808 INFO success: nginxgo entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:11,314 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:12,319 INFO spawned: 'nginxgo' with pid 31082
2014-11-26 14:08:13,381 INFO success: nginxgo entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:14,886 INFO exited: nginxgo (exit status 1; not expected)
^C2014-11-26 14:08:15,601 INFO spawned: 'nginxgo' with pid 31083
2014-11-26 14:08:15,603 WARN received SIGINT indicating exit request
2014-11-26 14:08:15,611 INFO waiting for nginxgo, uwsgi_emperor_go to die
2014-11-26 14:08:16,738 INFO success: nginxgo entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:08:18,242 INFO exited: nginxgo (exit status 1; not expected)
2014-11-26 14:08:19,244 INFO waiting for uwsgi_emperor_go to die
2014-11-26 14:08:21,607 INFO stopped: uwsgi_emperor_go (exit status 0)

看看它怎麼說

2014-11-26 14:07:59,095 INFO success: nginxgo entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)
2014-11-26 14:07:59,095 INFO success: uwsgi_emperor_go entered RUNNING state, process has stayed up for > than 1 seconds (startsecs)

但隨後它開始循環 nginxgo 程序。我用 殺死了 supervisord 實例CTRL-C,我看到htopnginx master processworker process處於活動狀態。

我想要的只是啟動nginx和我uWSGI emperor的伺服器啟動/重新啟動或任一程序失敗

supervisord 只能處理前台程序。nginx 的預設設置是作為守護程序在後台執行。

為確保您的 nginx 與 supervisord 一起執行,您必須在 nginx.conf 中設置“關閉守護程序”(另請參閱http://nginx.org/en/docs/ngx_core_module.html#daemon上的 nginx 文件)。

引用自:https://serverfault.com/questions/647357