Configuring Supervisor on Elastic Beanstalk

Configuring Supervisor on Elastic Beanstalk

I’ve recently been deploying a laravel app on AWS. I wanted to deploy supervisor on my Amazon Linux 2023 instance but it wasnt as straight forward as the guide I was following made out A Comprehensive Guide to Deploying Laravel on Honeybadger.io

So after figuring it out, here are the steps to make it work:

First create a new folder under .platform/files, we’re then going to create two files supervisor.conf

[supervisord]
nodaemon=true


; Put your supervisor programs here

[inet_http_server]
port=127.0.0.1:9001

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

[supervisorctl]
serverurl=http://127.0.0.1:9001

Make sure to add the programs you wish supervisorctl to look after for you, for example I was adding the laravel schedule:run command so my config looks like this:

[supervisord]
nodaemon=true


[program:laravel-queue]
process_name=%(program_name)s
command=php /var/app/current/artisan queue:work
autostart=true
autorestart=true
user=root
numprocs=1
redirect_stderr=true
stdout_logfile=/var/log/worker.log
stopwaitsecs=3600

[inet_http_server]
port=127.0.0.1:9001

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

[supervisorctl]
serverurl=http://127.0.0.1:9001

and then create 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/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl -c /etc/supervisord.conf $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=50s

[Install]
WantedBy=multi-user.target

Now create a new prebuild hook .platform/hooks/prebuild/install_supervisor.sh

#!/bin/sh

sudo python3 -m venv /opt/supervisor
sudo /opt/supervisor/bin/pip install --upgrade pip
sudo /opt/supervisor/bin/pip install supervisor certbot-nginx
sudo ln -sf /opt/supervisor/bin/supervisord /usr/bin/supervisord
sudo ln -sf /opt/supervisor/bin/supervisorctl /usr/bin/supervisorctl
sudo cp .platform/files/supervisor.conf /etc/supervisord.conf
sudo cp .platform/files/supervisord.service /lib/systemd/system/supervisord.service
sudo systemctl start supervisord
sudo systemctl enable supervisord
sudo systemctl daemon-reload

We’re installing supervisor with pip in its own environment, we then create a symlink for the binaries into /usr/bin then we copy our config files from our .platform/files folder and finally we enable the service.

Create the last file which is a postdeploy hook .platform/hooks/postdeploy/restart_supervisorctl.sh

#!/bin/sh

sudo supervisorctl restart all

This just ensures supervisor is restarted after your app has been successfully deployed.

Redeploy your app and you should be good to go.

Comments

Comments are powered by Github!

Post comment
Loading...