supervisorclusterctl

program配置块

该块就是我们要监控的程序的配置项。该配置块的头部是有固定格式的,一个关键字program,后面跟着一个冒号,接下来才是程序名。例如:[program:foo],foo就是程序名,在使用supervisorctl来操作程序的时候,就是以foo来标明的。该块的参数介绍如下:

- command:启动程序使用的命令,可以是绝对路径或者相对路径
- process_name:一个python字符串表达式,用来表示supervisor进程启动的这个的名称,默认值是%(program_name)s
- numprocs:Supervisor启动这个程序的多个实例,如果numprocs>1,则process_name的表达式必须包含%(process_num)s,默认是1
- numprocs_start:一个int偏移值,当启动实例的时候用来计算numprocs的值
- priority:权重,可以控制程序启动和关闭时的顺序,权重越低:越早启动,越晚关闭。默认值是999
- autostart:如果设置为true,当supervisord启动的时候,进程会自动重启。
- autorestart:值可以是false、true、unexpected。false:进程不会自动重启,unexpected:当程序退出时的退出码不是exitcodes中定义的时,进程会重启,true:进程会无条件重启当退出的时候。
- startsecs:程序启动后等待多长时间后才认为程序启动成功
- startretries:supervisord尝试启动一个程序时尝试的次数。默认是3
- exitcodes:一个预期的退出返回码,默认是0,2。
- stopsignal:当收到stop请求的时候,发送信号给程序,默认是TERM信号,也可以是 HUP, INT, QUIT, KILL, USR1, or USR2。
- stopwaitsecs:在操作系统给supervisord发送SIGCHILD信号时等待的时间
- stopasgroup:如果设置为true,则会使supervisor发送停止信号到整个进程组
- killasgroup:如果设置为true,则在给程序发送SIGKILL信号的时候,会发送到整个进程组,它的子进程也会受到影响。
- user:如果supervisord以root运行,则会使用这个设置用户启动子程序
- redirect_stderr:如果设置为true,进程则会把标准错误输出到supervisord后台的标准输出文件描述符。
- stdout_logfile:把进程的标准输出写入文件中,如果stdout_logfile没有设置或者设置为AUTO,则supervisor会自动选择一个文件位置。
- stdout_logfile_maxbytes:标准输出log文件达到多少后自动进行轮转,单位是KB、MB、GB。如果设置为0则表示不限制日志文件大小
- stdout_logfile_backups:标准输出日志轮转备份的数量,默认是10,如果设置为0,则不备份
- stdout_capture_maxbytes:当进程处于stderr capture mode模式的时候,写入FIFO队列的最大bytes值,单位可以是KB、MB、GB
- stdout_events_enabled:如果设置为true,当进程在写它的stderr到文件描述符的时候,PROCESS_LOG_STDERR事件会被触发
- stderr_logfile:把进程的错误日志输出一个文件中,除非redirect_stderr参数被设置为true
- stderr_logfile_maxbytes:错误log文件达到多少后自动进行轮转,单位是KB、MB、GB。如果设置为0则表示不限制日志文件大小
- stderr_logfile_backups:错误日志轮转备份的数量,默认是10,如果设置为0,则不备份
- stderr_capture_maxbytes:当进程处于stderr capture mode模式的时候,写入FIFO队列的最大bytes值,单位可以是KB、MB、GB
- stderr_events_enabled:如果设置为true,当进程在写它的stderr到文件描述符的时候,PROCESS_LOG_STDERR事件会被触发
- environment:一个k/v对的list列表
- directory:supervisord在生成子进程的时候会切换到该目录
- umask:设置进程的umask
- serverurl:是否允许子进程和内部的HTTP服务通讯,如果设置为AUTO,supervisor会自动的构造一个url
[program:XXXXXXXX]
process_name=follow_ask-%(process_num)s
directory=/home/online/XXXXXXXX/
command=python XXXXXXXX.py --port=%(process_num)s
startsecs=2
user=youruser
stdout_logfile=/home/XXXXXXXX/log/out-%(process_num)s.log
stderr_logfile=/home/XXXXXXXX/log/err-%(process_num)s.log
numprocs=8
numprocs_start=9102
user=XXXXXXXX

supervisorclusterctl requiresAnsibleto be installed on the control machine. You only need to install Ansible on one machine and it can control an entire fleet of remote nodes from that central point.

$ sudo easy_install pip

Then install Ansible with:

$ sudo pip install ansible

supervisorclusterctl can be installed via “pip”:

$ sudo pip install supervisorclusterctl

Managed Node Requirements

Running supervisorclusterctl

Now that you’ve installed supervisorclusterctl, it’s time to get started with some basics.

Run help to see all available command-line commands, arguments and options

$ supervisorclusterctl -h
     usage: supervisorclusterctl [-h] [-v] [-s] [-V]
                                 host-pattern
                                 {status,reread,reload,update,start,stop,restart,remove}
                                 ...

     supervisorclusterctl is a cmd line tool that allows to control a cluster of
     processes by utilizing Supervisor and Ansible.

     positional arguments:
       host-pattern          A host-pattern usually refers to a group of hosts. For
                             more details, see Ansible documentation about
                             Patterns.
       {status,reread,reload,update,start,stop,restart,remove}
                             One of the available supervisorctl actions.
         status              Get status info of all processes.
         reread              Reread the configuration files of supervisord
         reload              Restart remote supervisord
         update              Reload the configuration files of supervisord and
                             add/remove processes as necessary
         start               Start a process by name
         stop                Stop a process by name
         restart             Restart a process by name
         remove              Remove a process by name

     optional arguments:
       -h, --help            show this help message and exit
       -v, --verbose         run in verbose mode (-vvv for more, -vvvv to enable
                             connection debugging)
       -s, --sudo            run supervisorctl actions with sudo (nopasswd))
       -V, --version         show program's version number and exit

Run subcommand help to see all available arguments and options of the subcommand

$ supervisorclusterctl production restart -h
     usage: supervisorclusterctl host-pattern start [-h] process-name

     positional arguments:
       process-name  Name of the process

     optional arguments:
       -h, --help    show this help message and exit

Now edit /etc/ansible/hosts and put one or more remote systems in it, for which you have your SSH key inauthorized_keys:

[production]
192.168.0.11
192.168.0.12
[development]
192.168.0.10

This is an inventory file, which is explained in greater detail in Ansible’s documentation

Now edit /etc/ansible/hosts and put one or more remote systems in it, for which you have your SSH key inauthorized_keys:

[production]
192.168.0.11
192.168.0.12
[development]
192.168.0.10

这里需要将 管理端的公钥 拷贝到每台机器认证私钥

$ supervisorclusterctl production status
     192.168.0.11 | success | rc=0 >>
     managed_service         RUNNING    pid 12136, uptime 21:50:02

     192.168.0.12 | success | rc=0 >>
     managed_service         RUNNING    pid 12261, uptime 21:50:02

Now you are able to restart themanaged_serviceprocess on all of your configured production nodes:

$ supervisorclusterctl production restart managed_service
     192.168.0.11 | success | rc=0 >>
     managed_service: stopped
     managed_service: started

     192.168.0.12 | success | rc=0 >>
     managed_service: stopped
     managed_service: started

results for ""

    No results matching ""