Pi Awesome

Reference and guides to build kick ass raspberry pi projects.

View the Project on GitHub codingforentrepreneurs/Pi-Awesome

Supervisor as a Background Service Manager

Supervisor, often called supervisord, is a simple way to manage processes that you need your pi to run. In our case, we’re using it to run a minimal python web application (flask).

1. Install

sudo apt install supervisor -y

2. Start Supervisor

sudo service supervisor start

3. Create a Supervisor Process

Be sure to enable the correct permissions on the user or the user’s group so the below process can actually run.

All of your custom processes will live in the following directory:

/etc/supervisor/conf.d/

Create file project.supervisor.conf and put:

[program:flaskapp]
user=pi
directory=/home/pi/app
command=/home/pi/app/bin/gunicorn wsgi:app
 
autostart=true
autorestart=true
stdout_logfile=/var/log/www/flaskapp/stdout.log
stderr_logfile=/var/log/www/flaskapp/stderr.log

4. Update Supervisor

sudo supervisorctl reread
sudo supervisorctl update

These two commands will let supervisor know of our new process (reread) and it will run it (update).

5. Verify Commands

sudo supervisorctl status flaskapp
sudo supervisorctl start flaskapp
sudo supervisorctl stop flaskapp
sudo supervisorctl restart flaskapp

6. Check logs

In our project.supervisor.conf from Step 3, we have the following log paths:

/var/log/www/flaskapp/stdout.log

and

/var/log/www/flaskapp/stderr.log

These logs are useful to uncover errors with your application running.