supervisor后台进程管理工具

Supervisor安装配置(MAC)

安装supervisor:

brew install supervisor
  • 1

显示如下,就证明安装成功了

RPPETdeMacBook-Pro:data rppet$ brew install supervisor
Updating Homebrew...
==> Downloading https://ghcr.io/v2/homebrew/core/supervisor/manifests/4.2.2
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/supervisor/blobs/sha256:43bd0271e2b89771f2af347f4e60e6abe001efc55f6425a4d61c7a310398d969
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:43bd0271e2b89771f2af347f4e60e6abe001efc55f6425a4d61c7a310398d969?se=2021-07-02T06%3A25%3A00Z&sig=ajVN%2BdQ%2Fr%2Brs0EW5%2FpkxQrBRxNwzmhdBqSLD%2FhkZ%2FC
######################################################################## 100.0%
==> Pouring supervisor--4.2.2.big_sur.bottle.tar.gz
==> Caveats
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
==> Summary
🍺  /usr/local/Cellar/supervisor/4.2.2: 677 files, 9.1MB
==> `brew cleanup` has not been run in 30 days, running now...
Warning: Calling `sha256 "digest" => :tag` in a bottle block is deprecated! Use `brew style --fix` on the formula to update the style or use `sha256 tag: "digest"` instead.
Please report this issue to the exolnet/deprecated tap (not Homebrew/brew or Homebrew/core), or even better, submit a PR to fix it:
  /usr/local/Homebrew/Library/Taps/exolnet/homebrew-deprecated/Formula/php@7.1.rb:10

Removing: /Users/rppet/Library/Logs/Homebrew/cmake... (64B)
Removing: /Users/rppet/Library/Logs/Homebrew/popt... (64B)
Removing: /Users/rppet/Library/Logs/Homebrew/redis... (64B)
Removing: /Users/rppet/Library/Logs/Homebrew/logrotate... (64B)
Removing: /Users/rppet/Library/Logs/Homebrew/rabbitmq-c... (64B)
RPPETdeMacBook-Pro:data rppet$ 

由此可见,supervisor的主配置文件在/usr/local/etc/supervisord.ini,打开配置文件在最后一行可以修改新增子配置文件,默认在/usr/local/etc/supervisor.d/*.ini。

安装成功后需要启动
手动启动,需要指定主配置文件

supervisord -c /usr/local/etc/supervisord.ini
1
自动随系统启动(推荐)

brew services start supervisor
1
在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
1
启动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:*

然后就成功了。

 

posted on 2021-07-02 14:36  andydaopeng  阅读(252)  评论(0编辑  收藏  举报

导航