Supervisor����python���Ա�д������linux����ϵͳ��һ��������������ߣ����Լ�ط����������У����������������Զ�Ԥ�����Զ������ȹ��ܡ�
Supervisor������monit��monit��supervisor��һ���Ƚϴ�IJ�����supervisor�����Ľ��̱�����supervisor��������monit���Թ����Ѿ������еij���supervisor��Ҫ������ij����Ƿ�daemon����supervisord��������ת��daemon������������supervisor������nginx�Ļ���������nginx�������ļ�������һ������daemon off��nginx�Է�daemon��ʽ������
һ��Supervisor�����
1. supervisord
The server piece of supervisor is named supervisord.
It is responsible for starting child programs at its own invocation,
responding to commands from clients, restarting crashed or exited subprocesseses,
logging its subprocess stdout and stderr output, and generating and handling “events”
corresponding to points in subprocess lifetimes.
The server process uses a configuration file. This is typically located in /etc/supervisord.conf.
This configuration file is an “Windows-INI” style config file.
It is important to keep this file secure via proper filesystem permissions
because it may contain unencrypted usernames and passwords.
2. supervisorctl
The command-line client piece of the supervisor is named supervisorctl.
It provides a shell-like interface to the features provided by supervisord. From supervisorctl,
a user can connect to different supervisord processes, get status on the subprocesses controlled by,
stop and start subprocesses of, and get lists of running processes of a supervisord.
The command-line client talks to the server across a UNIX domain socket or an internet (TCP) socket.
The server can assert that the user of a client should present authentication credentials before it allows him to perform commands.
The client process typically uses the same configuration file as the server but any configuration file with a [supervisorctl]
section in it will work.
3. Web Server
A (sparse) web user interface with functionality comparable to supervisorctl may be accessed via a browser
if you start supervisord against an internet socket.
Visit the server URL (e.g. http://localhost:9001/) to view and control process status through
the web interface after activating the configuration file’s [inet_http_server] section.
4. XML-RPC Interface
The same HTTP server which serves the web UI serves up an XML-RPC interface that can be used to interrogate
and control supervisor and the programs it runs. See XML-RPC API Documentation.
Platform Requirements
����Supervisor��װ
���ȱ��밲װ��python������linux�Դ�python,�����鰲װ2.7.0���ϵİ汾��
Supervisor����ͨ��
$ sudo easy_install supervisor
��װ����װ�ɹ�����ʾfinished, �����ٴν���python������
����"import supervisor", ���û����ʾ�������ʾ��װ�ɹ���
��ȻҲ����ͨ��Supervisor�������غ�setup.py install��װ��
���ִ�����ʾ:
Installed /usr/local/python2.7.3/lib/python2.7/site-packages/supervisor-4.0.0_dev-py2.7.egg
Processing dependencies for supervisor==4.0.0-dev
Searching for meld3>=1.0.0
Reading https://pypi.python.org/simple/meld3/
Download error on https://pypi.python.org/simple/meld3/: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed -- Some packages may not be found!
Couldn't find index page for 'meld3' (maybe misspelled?)
Scanning index of all packages (this may take a while)
Reading https://pypi.python.org/simple/
Download error on https://pypi.python.org/simple/: [Errno 1] _ssl.c:504: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed -- Some packages may not be found!
No local packages or download links found for meld3>=1.0.0
error: Could not find suitable distribution for Requirement.parse('meld3>=1.0.0')
����취:
������ѯ������ԭ�� ��curl��֤��̫������Ҫ�������µ�֤�飺
�������µ�֤���ļ� ��
$ wget http://curl.haxx.se/ca/cacert.pem
����Ϊca-bundle.crt���õ�Ĭ��Ŀ¼
$ mv cacert.pem ca-bundle.crt
$ mv ca-bundle.crt /etc/pki/tls/certs
���ز���װ��֤��� ���dz������������⣬
����֤��������뵽ʱ�䣬 ����date����鿴ʱ�䣬 ԭ����ʱ��̫С�ˣ�
��date -s ��ʱ��Ϳ���������easy_install�ˡ�
����Supervisor����
�������Ƕ�supervisor���ã�����Ҫ���������ļ�����shell�ն�����:
$ echo_supervisord_conf > /etc/supervisord.conf
����ͨ���ı��༭��������ļ���
$ vim /etc/supervisord.conf
������һ��ʾ���������ļ���
;/etc/supervisord.conf
[unix_http_server]
file = /var/run/supervisor.sock
chmod = 0777
chown= root:root
[inet_http_server]
# Web���������趨
port=9001
;username = admin
;password = yourpassword
[supervisorctl]
; �����'unix_http_server'������趨ƥ��
serverurl = unix:///var/run/supervisord.sock
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=true ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)
user=root ; (default is current user, required if root)
childlogdir=/var/log/supervisord/ ; ('AUTO' child log dir, default $TEMP)
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
;�����ĵ������̵����ã��������Ӷ��program
[program:chatdemon]
command=python /home/felinx/demos/chat/chatdemo.py
autostart = true
startsecs = 5
user = felinx
redirect_stderr = true
; �����program��log����������logfile_maxbytes��supervisord������log����
stdout_logfile_maxbytes = 20MB
stdoiut_logfile_backups = 20
stdout_logfile = /var/log/supervisord/chatdemo.log
[program:app]
command=python app.py --port=61000
directory=/opt/test/supervisor ; �Ƚ��뵽���Ŀ¼����ִ��command�� ���ڳ���Ҫ�ڵ�ǰĿ¼�ij��������
autostart=true ; start at supervisord start (default: true)
autorestart=unexpected ; whether/when to restart (default: unexpected)
startsecs=1 ; number of secs prog must stay running (def. 1)
user=root
; ����һ����̣��������Ƶ�program����ͨ�����ַ�ʽ���ӣ������ֹ�һ��������
[program:groupworker]
command=python /home/felinx/demos/groupworker/worker.py
numprocs=24
process_name=%(program_name)s_%(process_num)02d
autostart = true
startsecs = 5
user = felinx
redirect_stderr = true
stdout_logfile = /var/log/supervisord/groupworker.log
;����������˵����ο���http://supervisord.org/configuration.html��
�༭��ɺ��˳�.
ʹ����������supervisor��
$ supervisord
$ supervisorctl
��ps����鿴���������Ӧ�������Ѿ��Զ������ˡ�
�ġ�Supervisord����
Supervisord��װ��ɺ����������õ�������supervisord��supervisorctl��
����ʹ�ý������£�
• supervisord�� ��ʼ����Supervisord���������������������õĽ��̡�
• supervisorctl stop programxxx�� ֹͣijһ������(programxxx)��programxxxΪ[program:chatdemon]�����õ�ֵ�����ʾ������chatdemon��
• supervisorctl start programxxx�� ����ij������
• supervisorctl restart programxxx������ij������
• supervisorctl stop groupworker: ����������������Ϊgroupworker�������Ľ���(start,restartͬ��)
• supervisorctl stop all�� ֹͣȫ�����̣�ע��start��restart��stop�������������µ������ļ���
• supervisorctl reload�� �������µ������ļ���ֹͣԭ�н��̲����µ������������������н��̡�
• supervisorctl update�� �������µ������ļ������������û��иĶ��Ľ��̣�����û�иĶ��Ľ��̲�����Ӱ���������
ע�⣺��ʾ��stopֹͣ���Ľ��̣���reload����update�������Զ�������
�塢ҳ�����
supervisor�Դ���Web Server, ����ͨ��ҳ������������,
ǰ���ǿ��������ļ��е�[inet_http_server]�
����������ǵ����������������£�
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:51000 ; (ip_address:port specifier, *:port for all iface)
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
����Ƕ�����������Ҫָ��һ������:
[inet_http_server] ; inet (TCP) server disabled by default
port=192.168.2.13:51000 ; (ip_address:port specifier, *:port for all iface)
;username=user ; (default is no username (open server))
;password=123 ; (default is no password (open server))
���������ַ��������:
http://192.168.2.13:51000
�Ϳ��Խ���ҳ�滯�Ĺ����ˡ�
SUSE 10.1�°�װsupervisord���̹������ߣ�//m.ajphoenix.com/linux/2045.html