What is supervisor?

Supervisor is a process monitor in linux based operating system. Basically it keeps the background task up and running. It restarts the task if it failed for some reason.

How to install supervisor?

Using linux terminal run following command to install supervisor:

sudo apt-get install supervisor

How to configure supervisor?

Let's create a sample configuration for laravel application to run background jobs. First of all we need to create a new configuration for our laravel app.

Create a new file called /etc/supervisor/conf.d/laravel-worker.conf this file will have our supervisor configuration for our laravel queue workers.

Let's paste following contents to this file:

command=php /home/ssh_user/laravel-project/artisan queue:work sqs --sleep=3 --tries=3

In above file replace ssh_user with your ssh user on linux server. I assume that your laravel project is setup under /home/ssh_user/laravel-project folder.

Save above file and run following command to start supervisor:

# let our supervisor know about this new task
sudo supervisorctl reread

# update newly created config file
sudo supervisorctl update

# start our background task
sudo supervisorctl start laravel-worker:*

# check the status of our supervisor task
sudo supervisorctl status

That is it, this newly created task will be constantly monitored using supervisor in case it fails supervisor will restart our task and you can check the status using status command.