Report this

What is the reason for this report?

Gunicorn for django not working. Active: failed (Result: resources)

Posted on May 26, 2022

When I run // sudo systemctl status gunicorn.socket //it says Active: active (listening) But when I run// sudo systemctl status gunicorn // it says Active: failed (Result: resources)

Below is my gunicorn.service file, I have changed “ /home/sammy/env/bin/gunicorn “ to “ /home/Sammy/env/lib/python3.8/sitepackages/gunicorn “ as I realized there is not gunicorn in the folder /env/bin.

[Unit] Description=gunicorn daemon Requires=gunicorn.socket After=network.target

[Service] User=sammy Group=sammy EnvironmentFile=/home/sammy/env WorkingDirectory=/home/sammy/Connectcaptain_001/savedb002 ExecStart=/home/sammy/env/lib/python3.8/site-packages/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock savedb002.wsgi:application

[Install] WantedBy=multi-user.target

My socket file is :

[Unit] Description=gunicorn socket

[Socket] ListenStream=/run/gunicorn.sock

[Install] WantedBy=sockets.target

My wsgi.py file is under the folder savedb002.

Also when I ran “ sudo systemctl status gunicorn.socket ” The output I got is below: Active: failed (Result: resources) gunicorn.service: Failed to run ‘start’ task: gunicorn.service: Failed with result 'resource Failed to start gunicorn daemon. Failed to load environment f Failed to run ‘start’ task Failed with result 'resource Failed to start gunicorn daemon. gunicorn.service: Start request repeated too q gunicorn.service: Failed with result 'resource Failed to start gunicorn daemon.



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hey,

It looks like that the issue you’re encountering with Gunicorn failing to start is likely due to a misconfiguration in your gunicorn.service file. The error Active: failed (Result: resources) points to the direction that Gunicorn is unable to start due to resource constraints or incorrect paths in your configuration.

The ExecStart path in your gunicorn.service file should point to the Gunicorn executable. Usually, this would be in the bin directory of your virtual environment. The path you provided points to a directory where Python packages are installed, not the executable.

Ensure you have Gunicorn installed in your virtual environment. You can install it with:

source /home/sammy/env/bin/activate
pip install gunicorn

Then, update the ExecStart directive to point to the correct Gunicorn executable path:

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=sammy
Group=sammy
EnvironmentFile=/home/sammy/env
WorkingDirectory=/home/sammy/Connectcaptain_001/savedb002
ExecStart=/home/sammy/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock savedb002.wsgi:application

[Install]
WantedBy=multi-user.target

On another note, check that the sammy user has the necessary permissions to access the specified directories and files. This includes the virtual environment directory, the project directory, and the socket file.

You can change the ownership of the necessary directories and files to the sammy user:

sudo chown -R sammy:sammy /home/sammy/env
sudo chown -R sammy:sammy /home/sammy/Connectcaptain_001

After making the changes, reload the systemd manager configuration, and restart the Gunicorn services:

sudo systemctl daemon-reload
sudo systemctl restart gunicorn.socket
sudo systemctl restart gunicorn.service

If the service still fails to start, check the logs for more detailed error messages:

journalctl -u gunicorn.service -b

Here is an example of a correctly configured gunicorn.service file:

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=sammy
Group=sammy
WorkingDirectory=/home/sammy/Connectcaptain_001/savedb002
ExecStart=/home/sammy/env/bin/gunicorn --access-logfile - --workers 3 --bind unix:/run/gunicorn.sock savedb002.wsgi:application

[Install]
WantedBy=multi-user.target

Here is an example of a correctly configured gunicorn.socket file:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

- Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Start building today

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

Dark mode is coming soon.