CentOS: install beanstalkd and supervisor for Laravel queues

beanstalkd

sudo yum install beanstalkd -y
sudo chkconfig beanstalkd on
sudo service beanstalkd start
sudo service beanstalkd status

supervisor

sudo yum install supervisor -y
sudo chkconfig supervisord on

Add to /etc/supervisord.conf

[program:laravel-queue-listener]
command=php /your/laravel/folder/artisan queue:listen --env=production --timeout=0

Start supervisord

sudo service supervisord restart

Reference

Feedback

Installing supervisor on CentOS 6.8

1) Install Epel repo

1. cd /tmp
2. wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
3. rpm -ivh epel-release-6-8.noarch.rpm

2) Install the supervisor
1. yum install supervisor -y
2. chkconfig supervisord on

3) Install the init script

1. vi /etc/rc.d/init.d/supervisord
2. Paste the following code:

---------------------------------------------------------------------------------
#!/bin/bash
 
. /etc/init.d/functions
 
DAEMON=/usr/bin/supervisord
PIDFILE=/var/run/supervisord.pid
 
[ -x "$DAEMON" ] || exit 0
 
start() {
echo -n "Starting supervisord: "
if [ -f $PIDFILE ]; then
PID=`cat $PIDFILE`
echo supervisord already running: $PID
exit 2;
else
daemon $DAEMON --pidfile=$PIDFILE -c /etc/supervisord.conf
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/supervisord
return $RETVAL
fi
 
}
 
stop() {
echo -n "Shutting down supervisord: "
echo
killproc -p $PIDFILE supervisord
echo
rm -f /var/lock/subsys/supervisord
return 0
}
 
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status supervisord
;;
restart)
stop
start
;;
*)
echo "Usage: {start|stop|status|restart}"
exit 1
;;
esac
exit $?
---------------------------------------------------------------------------------
3. chmod 755 /etc/rc.d/init.d/supervisord

4) Paste current config value in the supervisord.conf file

1. vi /etc/supervisord.conf
2. Paste following code:

---------------------------------------------------------------------------------
[unix_http_server]
file=/tmp/supervisor.sock ; (the path to the socket file)

[supervisord]
logfile=/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)

; the below section must remain in the config file for RPC
; (supervisorctl/web interface) to work, additional interfaces may be
; added by defining them in separate rpcinterface: sections
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

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

; The below sample program section shows all possible program subsection values,
; create one or more 'real' program: sections to be able to control them under
; supervisor.

[program:queue]
command=php artisan queue:listen --tries=3
directory=/home/{my_user}/domains/{my_domain}
user={my_user}
autostart=true
autorestart=true
redirect_stderr=true
stdout_logfile=/home/{my_user}/domains/{my_domain}/worker.log
---------------------------------------------------------------------------------

5) Setup the supervisorctl

1. supervisorctl reread
2. supervisorctl add queue
3. supervisorctl start queue

6) Restart the service

1. service supervisord restart

Now the server is configured to automatically run the queue handler even when restarted, because of the init script.
Erik
Jul 8, 2016
#1