How do I ensure that Gunicorn starts upon boot?

Linode Staff

Whenever I reboot my Linode I have to manually start Gunicorn which is just no fun.

1 Reply

A great question! While most services can be configured so that they start on boot by simply enabling them (systemctl enable <service_name>), Gunicorn is a bit different -- in order to ensure that Gunicorn remains ready to serve your app's dynamic content even after a reboot, you'll need to:

  • Create .socket and .service files
  • Enable Gunicorn by enabling the .socket file

Creating the .socket and .service files

These will need to go in your /etc/systemd/system/ directory. You can create empty Gunicorn files with the following command:

sudo touch /etc/systemd/system/gunicorn.{socket,service}

You're now ready to edit these files to your liking -- a great starting point can be found in Gunicorn's official documentation.

Enabling Gunicorn

The homestretch! All you'll need to do to allow Gunicorn to persist through reboots is to enable the .socket file you created earlier by entering the following command:

sudo systemctl enable gunicorn.socket

Once you've followed the above steps, you should be good to go. Note that while the above commands are specific to Ubuntu versions > 15.04, the same steps should apply to RH distributions (CentOS, Fedora) as well.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct