The Gunicorn Server and start.sh file
Learn about the start.sh file and the Gunicorn server that lies within!
We'll cover the following
start.sh file
The below image shows a snapshot of what the inside of our file looks like:
#!/bin/bash# Start Gunicorn processesecho Starting Gunicorn.exec gunicorn --reload helloworld.helloworld.wsgi:application \--bind 0.0.0.0:8000
Line 4, writes “Starting Gunicorn” to the command line to confirm that Gunicorn is starting execution.
Line 5 does three things:
-
Set the path to the application folder, i.e.,
helloworld,
to ensure the script is looking in the directory where it’s supposed to. -
Launch the Gunicorn server.
-
The
reload
flag basically just checks and makes necessary changes in case files have been updated.
We pass the gunicorn
command with the first argument of helloworld.wsgi:application.
This is a reference to the wsgi
file Django generated for us by the django-admin tool and is a Web Server Gateway Interface file. This file is Python’s standard for web servers and applications.
This file define the application variable, in this case, helloworld.wsgi:application
, and Gunicorn itself will already have the information on how to interact with the object to start the webserver.
In Line 6, the bind
flag is passed to the command to attach the running server to port 8000
, which will be used to communicate with the running web server. This is done via HTTP.
And with this, we’ve covered the mechanics of the start.sh
file. Let’s finally see how to use all of this on the Educative platform.
In the next lesson, we’ll set up our docker and LiveVM and see them in action on Educative!
Stay tuned :)