Skip to content

Instantly share code, notes, and snippets.

@vrajroham
Last active December 1, 2023 01:55
Installing Supervisor on AWS EC2 and Beanstalk

Installing Supervisor on AWS EC2 and Beanstalk

This gist may help you to install supervisor Manually on AWS Beanstalk host. I was enable to install and configure referring supervisor docs. Here are the steps by which I was able to use supervisor on my project.

Note: I have performed this steps on Laravel project and my instance was Debian powered. You can change according to your requirement.


  • Check python with easy_install is installed
  • Install supervisor > $ easy_install supervisor
  • Create directory for supervisor workers > mkdir /etc/supervisor/conf.d/
  • Create laravel worker file > touch /etc/supervisor/conf.d/laravel-worker.conf
  • Add following contents to laravel-worker.conf
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/artisan queue:work --tries=3
autostart=true
autorestart=true
user=root
numprocs=5
redirect_stderr=true
stdout_logfile=/var/www/html/storage/worker.log
  • Change command and stdout_logfile according to project setup
  • Create supervisor config file > touch /etc/supervisord.conf and following contents to created file
; supervisor config file

[unix_http_server]
file=/var/run/supervisor.sock   ; (the path to the socket file)
chmod=0700                       ; sockef file mode (default 0700)

[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)

; 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:///var/run/supervisor.sock ; use a unix:// URL  for a unix socket

; The [include] section can just contain the "files" setting.  This
; setting can list multiple files (separated by whitespace or
; newlines).  It can also contain wildcards.  The filenames are
; interpreted as relative to this file.  Included files *cannot*
; include files themselves.

[include]
files = /etc/supervisor/conf.d/*.conf
; Change according to your configurations
  • Create log file for supervisor as > touch /var/log/supervisor/supervisord.log if not exist
  • Restart the supervisord as > /usr/local/bin/supervisord -c /etc/supervisord.conf
  • Reread supervisorctl as > /usr/local/bin/supervisorctl reread
  • Update supervisorctl as > /usr/local/bin/supervisorctl update
  • Start laravel-worker and any other workers as > /usr/local/bin/supervisorctl start laravel-worker:*
  • Check status whether workers are running as > /usr/local/bin/supervisorctl status you show see similar output as below
laravel-worker:laravel-worker_00   RUNNING   pid 10039, uptime 0:20:35
laravel-worker:laravel-worker_01   RUNNING   pid 10040, uptime 0:20:35
laravel-worker:laravel-worker_02   RUNNING   pid 10041, uptime 0:20:35
laravel-worker:laravel-worker_03   RUNNING   pid 10042, uptime 0:20:35
laravel-worker:laravel-worker_04   RUNNING   pid 10043, uptime 0:20:35
  • Done 🎉
@yasirmturk
Copy link

What about Amazon Linux 2?

@johnyvelho
Copy link

For those struggling to do it. Here you go an updated way: https://gist.github.com/johnyvelho/6a457d5e0500ca0c1faa2e6c5eab7ced

@hpvala
Copy link

hpvala commented Jul 21, 2021

How to make auto start supervisord because it's sometime off when load balancer is set in EC2, I already set auto start code but it's not working.

/usr/local/etc/laravel-worker.conf:
    mode: "000755"
    owner: root
    group: root
    content: |
       [program:laravel-worker]
       process_name=%(program_name)s_%(process_num)02d
       command=php /var/www/html/artisan queue:work --timeout=6000
       autostart=true
       autorestart=true
       startsecs=0
       user=root
       numprocs=1
       redirect_stderr=true
       stdout_logfile=/var/www/html/storage/worker.log

@Novslugger
Copy link

@hpvala Have you tried this one?

[program:laravel-worker.conf]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/html/mywebsite/artisan queue:work database --sleep=1 --tries=1 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=root
numprocs=4
redirect_stderr=true
stdout_logfile=/var/log/laravel-worker.log
stdout_logfile_maxbytes=0
stopwaitsecs=3600

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment