supervisor 是一個用 python 開發的常駐程式管理工具。

php artisan queue:listen 這個命令,就是一個持續監控待辦工作(Job)的程式。在測試時,我們會手動執行這個命令,但是在正式環境中,我們需要他一開機就自己自動執行,這時,就需要 supervisord 這個服務。

Laravel Docs – Queues 中有提到,如果正式環境中,會建議使用 queue:work ,在效能上會有比較好的表現。

在 homestead(ubuntu) 上安裝

sudo apt-get install supervisord
# 主要設定檔,通常不需要改
sudo vi /etc/supervisor/supervisord.conf
# 
sudo vi /etc/supervisor/conf.d/laravel-quene.conf

/etc/supervisor/conf.d/laravel-quene.conf 內容

[program:laravel-queue]
process_name=%(program_name)s_%(process_num)02d
command=php /home/vagrant/Code/clptc-edm/artisan queue:listen
autostart=true
autorestart=true
user=vagrant
numprocs=1
redirect_stderr=true
stdout_log=/home/vagrant/Code/clptc-edm/storage/logs/queue.log
# 重新啟動 supervisor 服務
service supervisor stop
service supervisor start
# 檢查是否正常運作
service supervisor status

檢查結果如下

vagrant@homestead:/etc/init.d$ service supervisor status
● supervisor.service - Supervisor process control system for UNIX
   Loaded: loaded (/lib/systemd/system/supervisor.service; enabled; vendor preset: enabled)
   Active: active (running) since Sun 2019-12-22 08:47:22 UTC; 2s ago
     Docs: http://supervisord.org
  Process: 2860 ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown (code=exited, status=0/SUCCESS)
 Main PID: 2924 (supervisord)
    Tasks: 2 (limit: 2319)
   CGroup: /system.slice/supervisor.service
           ├─2924 /usr/bin/python /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
           └─2946 php /home/vagrant/Code/clptc-edm/artisan queue:work

在 CentOS 7 上安裝

yum install supervisor

systemctl enable supervisord

# restart 後,會自動建立 /etc/supervisord.conf
systemctl restart supervisord

# 與 ubuntu 不同,centos 上的設定檔副檔名是 ini
vi /etc/supervisor.d/laravel-queue.ini

systemctl restart supervisord

systemctl status supervisord

參考資料

https://www.cnblogs.com/xishuai/p/ubuntu-install-supervisor.html

https://www.cnblogs.com/restran/p/4854623.html

https://stackoverflow.com/questions/41991251/what-is-the-difference-queuework-and-queuelisten/41991848

https://stackoverflow.com/questions/41991251/what-is-the-difference-queuework-and-queuelisten/41991848

Last modified: 2019-12-27

Author

Comments

Write a Reply or Comment

Your email address will not be published.