系統
CentOS Linux release 7.4.1708
Homestead 4.15 Ubuntu 18.04 LTS
Supervisor 安裝
easy_install supervisor
sudo easy_install supervisor
Supervisor 配置
1、生成新主配置檔案
echo_supervisord_conf > /etc/supervisord.conf // 需要 root 限制,sudo 不管用
2、修改 supervisord.conf 主配置檔案
·
·
[unix_http_server]
file=/var/run/supervisor.sock ; the path to the socket file
·
·
[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL for a unix socket
·
·
[supervisord]
logfile=/var/log/supervisord.log ; main log file; default $CWD/supervisord.log
·
·
pidfile=/var/run/supervisord.pid ; supervisord pidfile; default supervisord.pid
·
·
[include]
files = /etc/supervisor/*.conf
3、啟動 supervisor(確保9001埠未被佔用)
sudo supervisord -c /etc/supervisord.conf
4、建立第二步對應的檔案
sudo touch /var/run/supervisor.sock
sudo chmod 777 /var/run/supervisor.sock
sudo touch /var/log/supervisord.log // 已經存在再次建立也沒影響
sudo chmod 777 /run
sudo chmod 777 /var/log
5、建立 supervisor 專案配置檔案
// 檢視 /etc/supervisord.conf 檔案
[include]
files = /etc/supervisor/*.conf // 這個路徑放置專案對應的 supervisor 配置檔案
// 在 /etc/supervisor/ 目錄下建立以 laravel-worker.conf配置檔案(以 .conf 結尾即可),內容如下
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /data/www/laravel/artisan queue:work --sleep=3 --tries=3
autostart=true
autorestart=true
user=vagrant // 自己的使用者名稱
numprocs=8
redirect_stderr=true
stdout_logfile=/var/log/supervisor/laravel-queue.log // 配置檔案路徑
6、建立 supervisor 專案配置檔案日誌
sudo mkdir /var/log/supervisor
sudo touch /var/log/supervisor/laravel-queue.log
sudo chmod 777 /var/log/supervisor/laravel-queue.log
sudo chown vagrant:vagrant /var/log/supervisor/laravel-queue.log
sudo chown vagrant:vagrant /var/log/supervisor
啟動 supervisor 專案配置檔案
sudo supervisorctl reread // 重新載入主配置檔案
sudo supervisorctl update // 建立專案配置檔案程式組
sudo supervisorctl start laravel-worker:* // 啟動監聽程式
sudo supervisorctl status // 出現以下則成功
laravel-worker:laravel-worker_00 RUNNING pid 12425, uptime 0:04:52
laravel-worker:laravel-worker_01 RUNNING pid 12426, uptime 0:04:52
laravel-worker:laravel-worker_02 RUNNING pid 12427, uptime 0:04:52
laravel-worker:laravel-worker_03 RUNNING pid 12428, uptime 0:04:52
laravel-worker:laravel-worker_04 RUNNING pid 12429, uptime 0:04:52
laravel-worker:laravel-worker_05 RUNNING pid 12430, uptime 0:04:52
laravel-worker:laravel-worker_06 RUNNING pid 12431, uptime 0:04:52
laravel-worker:laravel-worker_07 RUNNING pid 12432, uptime 0:04:52
Note
Laravel Job 程式碼修改後,需要重啟 supervisor 才會生效
Supervisor 命令
sudo supervisorctl status
sudo supervisorctl stop usercenter
sudo supervisorctl stop all // 停止所有
sudo supervisorctl start usercenter
sudo supervisorctl restart usercenter
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl // 進入 cli
官網:supervisord.org/running.html
原文連線:分享:使用 Supervisor 管理 Laravel 佇列程式
參考連線:blog.tanteng.me/2017/01/supervisor...
參考連線:blog.csdn.net/qq_28885149/article/...
supervisor Web管理介面與開房自啟動:www.cnblogs.com/lemon-flm/articles/...
本作品採用《CC 協議》,轉載必須註明作者和本文連結