Install and configure supervisord on centos 7 to run Laravel queues permanently

I want to use the Laravel queue system in my project and want to run php artisan queue: run in the background of the server constantly , I did some searches on this and found a command line that can start it even after exiting the ssh terminal, but it might be in some cases and can create terrible problems for me. So after a while, I discovered that there is a package named Supervisord that can restart the command even after the server is restarted. But unfortunately my Linux knowledge is not great, so I want to ask someone for help from 0 to 100, step by step how to install Supervisord and set it up on centos 7 and then install the queue command line. Thank you so much..

+16
laravel centos7 supervisord laravel-queue


source to share


4 answers


here's how to install and configure supervisord on centos 7 to keep Laravel queues running all the time:

  • easy_install supervisor

  • yum install supervisor

  • vim /etc/supervisord.conf

    edit the section program as follows:


[program:laravel-worker]
command=php /path/to/app.com/artisan queue:work 
process_name=%(program_name)s_%(process_num)02d
numprocs=8 
priority=999 
autostart=true
autorestart=true  
startsecs=1
startretries=3
user=apache
redirect_stderr=true
stdout_logfile=/path/to/log/worker.log

      

  1. systemctl enable supervisord

    to autorun at startup
  2. systemctl restart supervisord

    to restart the service.
+39


source to share


Hope this is useful to someone, this is a process I went through in addition to @ Abdu's answer to get it working on CentOS 7.

1. Install Supervisor

easy_install supervisor

* If not installed, run yum install -y python-setuptools

and theneasy_install supervisor

2. Preparatory work

To run a perfect setup, you should do the following ...



# create directory for supervisor logs
mkdir /var/log/supervisor

# create directory for supervisor configs
mkdir -p /etc/supervisor/conf.d

# create config directory for supervisor
cat <<EOT >> /etc/supervisor/supervisord.conf
; supervisor config file

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
childlogdir=/var/log/supervisor            ; ('AUTO' child log dir, default $TEMP)

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

[include]
files = /etc/supervisor/conf.d/*.conf
EOT

# create systemctl service script
cat <<EOT >> /lib/systemd/system/supervisord.service
[Unit]
Description=Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target

[Service]
ExecStart=/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl -c /etc/supervisor/supervisord.conf $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=50s

[Install]
WantedBy=multi-user.target
EOT

      

Once you've done that, you can start and stop the supervisor using systemctl. To start systemctl, run systemctl start supervisord

. To view the supervisor status, run systemctl status supervisord

.

You can create as many custom configurations as you like in /etc/supervisor/conf.d

3. Enable at system startup

You must also enable supervisor at startup by running

systemctl enable supervisord

      

+3


source to share


In my account, Bluehost systemctl

didn't work, but instead was chkserv

used to monitor and restart processes, so the two answers here don't completely work for me.

Also, I ran into a bug in easy_install supervisor

as it was trying to install the new 4.xx version which it requires Python > 2.6

, while 2.6 was the exact version of Python running on my machine.

Here's what worked for me:

  1. yum install -y python-setuptools

  2. easy_install supervisor==3.4.0

  3. nano /etc/supervisord.conf

    and add

[supervisord]
nodaemon=true

[include]
files = /etc/supervisor/conf.d/*.conf

[program:laravel-worker]
command=php artisan queue:work --tries=1
autostart=true
autorestart=true
stderr_logfile=/var/log/queue.err.log
stdout_logfile=/var/log/queue.out.log

      

  1. nano /etc/chkserv.d/chkservd.conf

    , add the line supervisord:1

    and then save the file

  2. touch /etc/chkserv.d/supervisord

    to create the chkservd config file

  3. nano /etc/chkserv.d/supervisord

    , add the line service[supervisord]=x,x,x,service supervisord restart,supervisord,root

    and then save the file

  4. supervisord

    will now show up in WHM under Service Manager

    , and chkservd

    launch it and make sure it keeps running, but to start it manually, just runsupervisord

For more information on adding a service to chkservd

, click here .

0


source to share


I think the official documentation of the supervisor is pretty easy to follow. And to customize it with Laravel, the official Laravel documentation is good enough.

-1


source to share







All Articles
Loading...
X
Show
Funny
Dev
Pics