<code>1、安裝</code>
<code>wget https:</code><code>//bitbucket</code><code>.org</code><code>/pypa/setuptools/raw/bootstrap/ez_setup</code><code>.py -O - | python</code>
<code>easy_install supervisor</code>
<code>或者</code>
<code>yum </code><code>install</code> <code>python-pip</code>
<code>pip </code><code>install</code> <code>supervisor</code>
<code>2、配置檔案:</code>
<code># echo_supervisord_conf > /etc/supervisord.conf \</code>
<code>&& </code><code>mkdir</code> <code>/etc/supervisor</code><code>.d \</code>
<code>&& </code><code>/usr/bin/echo_supervisord_conf</code> <code>></code><code>/etc/supervisord</code><code>.conf \</code>
<code>&& </code><code>echo</code> <code>-e </code><code>'[include]\nfiles=/etc/supervisor.d/*.ini'</code> <code>>></code><code>/etc/supervisord</code><code>.conf \</code>
<code>&& </code><code>grep</code> <code>^[^\;] </code><code>/etc/supervisord</code><code>.conf</code>
<code>3、啟動supervisord服務:</code>
<code># whereis supervisord</code>
<code>supervisord: </code><code>/etc/supervisord</code><code>.conf </code><code>/usr/local/bin/supervisord</code>
<code># /usr/local/bin/supervisord -c /etc/supervisord.conf</code>
<code>并增加到開機啟動</code><code>/etc/rc</code><code>.</code><code>local</code><code>中</code>
<code># echo '/usr/local/bin/supervisord -c /etc/supervisord.conf' >>/etc/rc.local</code>
<code>4、配置服務</code>
<code># cd /etc/supervisor.d</code>
<code># cat sshd.ini</code>
<code>[program:sshd]</code>
<code>command</code><code>=</code><code>/usr/sbin/sshd</code> <code>-D</code>
<code># cat test.ini</code>
<code>[program:</code><code>test</code><code>]</code>
<code>command</code><code>=</code><code>/usr/bin/php</code> <code>xxx.php</code>
<code>process_name=%(program_name)s_%(process_num)02d</code>
<code>numprocs=5</code>
<code>user=nobody</code>
<code># cat uwsgi.ini</code>
<code>[program:uwsgi]</code>
<code>command</code><code>=</code><code>/usr/local/bin/uwsgi</code> <code>--http 127.0.0.1:8090 --chdir </code><code>/opt/test-django/www</code> <code>--module www.wsgi ></code><code>/var/log/nginx/uwsgi</code><code>.log 2>&1</code>
<code>重新加載supervisord服務:</code>
<code># supervisorctl reload</code>
<code>Restarted supervisord</code>
<code>驗證</code>
<code># supervisorctl status</code>
<code>uwsgi RUNNING pid 15041, uptime 0:00:17</code>
<code># ss -antp src :8090</code>
<code>State Recv-Q Send-Q Local Address:Port Peer Address:Port</code>
<code>LISTEN 0 100 127.0.0.1:8090 *:* </code><code>users</code><code>:((</code><code>"uwsgi"</code><code>,15041,4),(</code><code>"uwsgi"</code><code>,15042,4))</code>
<code>調整user1增加</code><code>sudo</code><code>的權限:</code>
<code>user1 ALL=NOPASSWD: </code><code>/usr/bin/supervisorctl</code>
<code>然後通過這樣的方式來管理:</code>
<code>$ </code><code>sudo</code> <code>supervisorctl status|stop|start|restart</code>
<code>5、新增一個服務的正确姿勢</code>
<code>總結下來就2個指令:</code>
<code>supervisorctl reread</code>
<code>supervisorctl update</code>
<code>執行個體:</code>
<code>[root@tvm001 supervisor.d]</code><code># pwd</code>
<code>/etc/supervisor</code><code>.d</code>
<code>[root@tvm001 supervisor.d]</code><code># ls</code>
<code>gogogo.ini uwsgi_asset.ini uwsgi.ini</code>
<code>[root@tvm001 supervisor.d]</code><code># cat gogogo.ini</code>
<code>[program:gogogo]</code>
<code>command</code><code>=</code><code>/bin/cat</code>
<code>autostart=</code><code>true</code>
<code>autorestart=</code><code>true</code>
<code>stdout_logfile=</code><code>/tmp/gogogo</code><code>.stdout.log</code>
<code>stderr_logfile=</code><code>/tmp/gogogo</code><code>.stderr.log</code>
<code>[root@tvm001 supervisor.d]</code><code># supervisorctl status</code>
<code>uwsgi RUNNING pid 26248, uptime 5:13:02</code>
<code>uwsgi_asset RUNNING pid 26247, uptime 5:13:02</code>
<code>[root@tvm001 supervisor.d]</code><code># supervisorctl reread</code>
<code>gogogo: available</code>
<code>uwsgi RUNNING pid 26248, uptime 5:13:12</code>
<code>uwsgi_asset RUNNING pid 26247, uptime 5:13:12</code>
<code>[root@tvm001 supervisor.d]</code><code># supervisorctl update</code>
<code>gogogo: added process group</code>
<code>gogogo RUNNING pid 27147, uptime 0:00:04</code>
<code>uwsgi RUNNING pid 26248, uptime 5:13:25</code>
<code>uwsgi_asset RUNNING pid 26247, uptime 5:13:25</code>
<code>[root@tvm001 supervisor.d]</code><code>#</code>
<code>ZYXW、參考</code>
<code>1、doc</code>
<code>http:</code><code>//www</code><code>.supervisord.org</code><code>/running</code><code>.html</code><code>#supervisorctl-actions</code>
本文轉自 pcnk 51CTO部落格,原文連結:http://blog.51cto.com/nosmoking/1595238,如需轉載請自行聯系原作者