I want to use Laravel queue system in my project and I want to run php artisan queue:work permanently on server's background, I did some searches about this and I found a command line which can run it even after quit from ssh terminal but It can be down in some cases and can make terrible problems for me. So after a while I found out that there is a package named Supervisord which can restart command even after server is rebooted. So I want to ask someone to help from 0 to 100 step by step how to install Supervisord and configure it on centos 7 and after that set the queue command line. Thank you so much..
3 Answers
here is how to install and config supervisord on centos 7 to run Laravel queues permanently:
easy_install supervisoryum install supervisorvim /etc/supervisord.confedit section program as following:
[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
systemctl enable supervisordto autorun at startsystemctl restart supervisordto restart the service
- 21
- 4
- 8
-
4You assume that people have `easy_install`, in my case, my fresh CentOS didn't. To get it: `yum install -y python-setuptools` then you can proceed (all commands preceded by `sudo` unless you are root...). This doesn't work: `yum install supervisor`: it's installed via easy_install already. – firepol Mar 11 '19 at 06:05
-
And what if you have a deployment tool like fabric and want to have multiple scripts/programs in the `.conf` file. – TheRealChx101 May 22 '19 at 16:17
-
1First run `yum install epel-release`. Supervisor is not available in the default CentOS 7 Repository. – A. Khaled Sep 17 '22 at 15:20
Hopefully this will be of use to someone, this is the process I have been through in addition to @Abdu's answer to get things working on CentOS 7.
1. Install Supervisor
easy_install supervisor
* If not installed, run yum install -y python-setuptools and then easy_install supervisor
2. Prep work
To get the ideal setup running, you should run 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 this, you should now be able to start and stop supervisor using systemctl. To start systemctl, run systemctl start supervisord. To view the status of supervisor, run systemctl status supervisord.
You can create as many custom configurations as you like under /etc/supervisor/conf.d
3. Enable on system startup
You should also enable supervisord on startup by running
systemctl enable supervisord
- 1,939
- 1
- 19
- 38
-
3Add these to the top of /etc/supervisor/supervisord.conf if you get error message "unix:///var/run/supervisor.sock no such file" `[unix_http_server] file=/var/run/supervisor.sock ; (the path to the socket file) chmod=0700 ; sockef file mode (default 0700)` – BuffK Oct 25 '19 at 10:47
On my Bluehost account systemctl was not running, but instead chkserv was used to monitor and restart processes, so the two answers here did not fully work for me.
Also, I ran into an error with easy_install supervisor, since it tried to install the new 4.x.x version, which requires Python > 2.6, while 2.6 was the exact version of Python running on my machine.
Here is what worked for me:
yum install -y python-setuptoolseasy_install supervisor==3.4.0nano /etc/supervisord.confand 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
nano /etc/chkserv.d/chkservd.conf, add the linesupervisord:1, and then save the filetouch /etc/chkserv.d/supervisordto create chkservd config filenano /etc/chkserv.d/supervisord, add the lineservice[supervisord]=x,x,x,service supervisord restart,supervisord,root, and then save the filesupervisordwill now show up in WHM underService Manager, andchkservdwill start it and make sure it keeps running, but to manually start it, simply runsupervisord
For more information on adding a service to chkservd, click here.
- 1,003
- 10
- 18