Using Supervisor to start Gunicorn

Install Supervisor.

[email protected]:~$ sudo pip install supervisor

Create the default configuration file for Supervisor.

[email protected]:~$ sudo echo_supervisord_conf > /etc/supervisord.conf

Create the configuration file for the website.

[email protected]:~$ sudo nano /etc/supervisor/conf.d/website.conf

Enter the following.

; /etc/supervisor/conf.d/website.conf
[program:website]
command=gunicorn -c /opt/env/gunicorn_config.py django_project.wsgi:application
directory=/opt/env/django_project/
user=jitsejan
autostart=True
autorestart=True
redirect_stderr=True

Make the file executable.

[email protected]:~$ sudo chmod a+x /etc/supervisor/conf.d/website.conf 

Reload Supervisor to find the new file and update the configuration.

[email protected]:~$ sudo supervisorctl reread
[email protected]:~$ sudo supervisorctl update

Now you can start the website with the following command.

[email protected]:~$ sudo supervisorctl start website