安装 easy_install 工具,可以使用以下命令:
yum install python-setuptools
使用 easy_install 安装 Supervisor,可以使用以下命令:
easy_install supervisor
生成 Supervisor 配置文件,可以使用以下命令:
echo_supervisord_conf > /etc/supervisord.conf
启动 Supervisor,可以使用以下命令:
supervisord -c /etc/supervisord.conf
这将启动 Supervisor 进程并加载默认配置文件。可以使用以下命令查看 Supervisor 是否已经运行:
ps -ef | grep supervisord
将需要管理的进程添加到 Supervisor 配置文件中。可以编辑 /etc/supervisord.conf 文件,添加以下内容:
[program:myprogram]
command=/path/to/myprogram
autostart=true
autorestart=true
user=myuser
其中,myprogram 是要管理的程序的名称,/path/to/myprogram 是程序的路径,myuser 是运行程序的用户。可以根据需要添加更多的配置项。
重新加载 Supervisor 配置文件,可以使用以下命令:
supervisorctl reread
supervisorctl update
这将重新加载配置文件并更新 Supervisor 的管理状态。可以使用以下命令查看程序是否已经启动:
supervisorctl status
完成以上步骤后,Supervisor 将自动管理添加的程序,并在需要时重新启动它们。可以使用 Supervisor 命令行工具(supervisorctl)来管理这些程序,例如,可以使用以下命令来停止程序:
supervisorctl stop myprogram
[program:myprogram]
command=/path/to/myprogram
directory=/path/to/working/directory
autostart=true
autorestart=true
startsecs=10
startretries=3
user=myuser
priority=999
redirect_stderr=true
stdout_logfile=/var/log/myprogram.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10
stdout_capture_maxbytes=0
stderr_logfile=/var/log/myprogram_err.log
stderr_logfile_maxbytes=50MB
stderr_logfile_backups=10
stderr_capture_maxbytes=0
stopsignal=QUIT
stopwaitsecs=10
以下是常见的 program 配置项:
command: 需要 Supervisor 启动的命令或脚本。必选项。
directory: 运行命令时的工作目录。如果不指定,将使用默认工作目录。
autostart: 是否在 Supervisor 启动时自动启动此程序。默认为 true。
autorestart: 当此程序停止时,是否自动重启程序。可以是 false、true、unexpected,或者是一个数字表示重启的最大尝试次数,默认为 true。
startsecs: 程序启动后,如果在此时间内仍未退出,则 Supervisor 认为启动成功。默认为 1。
startretries: 如果程序在启动时失败,尝试重启的次数。默认为 3。
user: 程序运行的用户名。默认为 root。
priority: 程序启动时的优先级。值越小,优先级越高。默认为 999。
redirect_stderr: 是否重定向标准错误输出到标准输出中。默认为 false。
stdout_logfile: 程序标准输出日志文件的路径。默认为不记录。
stdout_logfile_maxbytes: 程序标准输出日志文件的最大字节数。默认为 50MB。
stdout_logfile_backups: 程序标准输出日志文件的备份数量。默认为 10。
stdout_capture_maxbytes: 程序标准输出最大允许输出到 supervisorctl tail 命令的缓冲区中的字节数。默认为 0,表示不限制。
stderr_logfile: 程序标准错误输出日志文件的路径。默认为不记录。
stderr_logfile_maxbytes: 程序标准错误输出日志文件的最大字节数。默认为 50MB。
stderr_logfile_backups: 程序标准错误输出日志文件的备份数量。默认为 10。
stderr_capture_maxbytes: 程序标准错误输出最大允许输出到 supervisorctl tail 命令的缓冲区中的字节数。默认