Application Server Setup – Gunicorn
The Gunicorn (Green Unicorn) is a Python Web Server Gateway Interface (WSGI) HTTP server. As we have already installed Gunicorn, we'll explain how to set it up in this section. To manage the Gunicorn application server on a Linux server, we can use systemd to run the server.
As web services should always be available on the Internet, the process must run when the server runs. systemd is a daemon (or a service) that manages other daemons for Linux OS. When Linux OS starts or reboots, systemd also starts and continues running to centrally control other daemons until the OS shuts down.
If you want to learn more about systemd, please check our 'Linux OS Introduction' course.
Linux OS Introduction 'Systemd'
There are three steps for Gunicorn setup.
- To run Gunicorn using systemd, you need to create two unit files. Unit files are used to set rules to manage units (processes) by systemd.
- Enable the unit files and start the units
- Check if the units are running
Create unit files
To run Gunicorn, you need to create a service unit file and a socket unit file.
Create a service unit file
A service unit file is used to create a service to run the application itself. The file should be stored under /etc/systemd/system. You can set any name but usually use a project name like project_d.service. To create and edit the file, use the vim
command.
su
Subscribe now for
uninterrupted access.