Supervisor安装配置(MAC)
安装supervisor
:
brew install supervisor
显示如下,就证明安装成功了
==> python
Python has been installed as
/usr/local/bin/python3
Unversioned symlinks `python`, `python-config`, `pip` etc. pointing to
`python3`, `python3-config`, `pip3` etc., respectively, have been installed into
/usr/local/opt/python/libexec/bin
If you need Homebrew's Python 2.7 run
brew install python@2
You can install Python packages with
pip3 install <package>
They will install into the site-package directory
/usr/local/lib/python3.7/site-packages
See: https://docs.brew.sh/Homebrew-and-Python
==> supervisor
To have launchd start supervisor now and restart at login:
brew services start supervisor
Or, if you don't want/need a background service you can just run:
supervisord -c /usr/local/etc/supervisord.ini
由此可见,supervisor
的主配置文件在/usr/local/etc/supervisord.ini
,打开配置文件在最后一行可以修改新增子配置文件,默认在/usr/local/etc/supervisor.d/*.ini
。
安装成功后需要启动
-
手动启动,需要指定主配置文件
supervisord -c /usr/local/etc/supervisord.ini
-
自动随系统启动(推荐)
brew services start supervisor
在supervisor
安装目录/usr/local/Cellar/supervisor/4.0.4/bin
下面有个supervisorctl
客户端,supervisorctl
用于向supervisord
发起命令。
编辑supervisord.ini
,将下列注释打开
[inet_http_server] ; inet (TCP) server disabled by default
port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface
启动supervisorctl
客户端方法:
supervisorctl -c /usr/local/etc/supervisord.ini
启动supervisorctl
客户端后,可以用浏览器打开进入web界面。
接下来新增子配置,开头已经说过了,子配置文件放在/usr/local/etc/supervisor.d
目录下,在该目录下,可以创建多个配置文件指示 Supervisor
如何监视进程,例如,让我们创建一个开启并监视 queue:work
进程的laravel-worker.ini
文件:
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /Applications/MAMP/htdocs/baichuanzhen/artisan queue:work database --sleep=3 --tries=3
autostart=true
autorestart=true
user=forge
numprocs=2
redirect_stderr=true
stdout_logfile=/Applications/MAMP/htdocs/baichuanzhen/storage/logs/queue.log
来看一下supervisorctl
有哪些命令
reread ;重新加载配置文件
update ;将配置文件里新增的子进程加入进程组,如果设置了autostart=true则会启动新新增的子进程
status ;查看所有进程状态
status <name> ;查看指定进程状态
start all; 启动所有子进程
start <name>; 启动指定子进程
restart all; 重启所有子进程
restart <name>; 重启指定子进程
stop all; 停止所有子进程
stop <name>; 停止指定子进程
reload ;重启supervisord
add <name>; 添加子进程到进程组
reomve <name>; 从进程组移除子进程,需要先stop。注意:移除后,需要使用reread和update才能重新运行该进程
启动 Supervisor
当成功创建配置文件后,需要刷新 Supervisor
的配置信息并使用如下命令启动进程:
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start laravel-worker:*
然后就成功了。