Question

gunicorn gives me "invalid argument" error and cannot be reloaded.

On my droplet I have installed and configured a django website successfully. My client asked me to re-do the project (it was a very old project). So I created another django website on this droplet for testing purposes (for my client to see the new version of the old site before deleting the old one and the new one going live) and added a new domain entry (i.e. stage.example.com) pointing to this droplet.

I edited gunicorn.service file and added this section:

[Service] User=myuser Group=www-data WorkingDirectory=/home/myuser/project2 ExecStart=/home/myuser/.virtualenvs/project2env/bin/gunicorn --workers 3 --bind unix:/home/myuser/project2/project2.sock project2.wsgi:application

Question 1: Is this allowed? To add two [Service] sections in gunicorn.service file?

Anyway, I tried to reload gunicorn and got this error message:

Failed to restart gunicorn.service: Unit gunicorn.service is not loaded properly: Invalid argument.
See system logs and 'systemctl status gunicorn.service' for details.

I opened /var/log/syslog and I noticed this:

Jun  9 08:57:59 project1-fra1 systemd[1]: Reloading.
Jun  9 08:58:00 project1-fra1 systemd[1]: gunicorn.service: Service has more than one ExecStart= setting, which is only allowed for Type=oneshot services. Refusing.
Jun  9 08:58:00 project1-fra1 systemd[1]: apt-daily.timer: Adding 11h 23.852822s random time.
Jun  9 08:58:00 project1-fra1 systemd[1]: snapd.refresh.timer: Adding 4h 8min 5.201022s random time.
Jun  9 08:58:00 project1-fra1 systemd[1]: Started ACPI event daemon.
Jun  9 09:00:22 project1-fra1 systemd[1]: Stopping A high performance web server and a reverse proxy server...
Jun  9 09:00:22 project1-fra1 systemd[1]: Stopped A high performance web server and a reverse proxy server.
Jun  9 09:00:22 project1-fra1 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jun  9 09:00:22 project1-fra1 systemd[1]: nginx.service: Failed to read PID from file /run/nginx.pid: Invalid argument
Jun  9 09:00:22 project1-fra1 systemd[1]: Started A high performance web server and a reverse proxy server.

I removed the second section from gunicorn.service file and tried to reload the gunicorn service, but although the site is working as normal, I still receive the same “Invalid Argument” error message.

Question 2: What did I do wrong? Is this fixable? How?


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Accepted Answer

Hi @xpanta

There cannot be multiple [Service] sections in one project (there are special cases, where it’s allowed). You need different projects, since they need in their own environment and have access to their own socket files, etc.

There might be orphaned processes because of the wrong configuration. You can have a look at all processes running with this command:

sudo ps -aux

Restarting the server will also clear any orphaned processes.

The seconds question is an Nginx warning/error. So can you check it’s configuration:

sudo service nginx configtest

Otherwise post it’s error log:

tail -30 /var/log/nginx/error.log

@xpanta

When you make changes to a service file controlled by systemd (using systemctl), you’ll need to do a reload on the daemon using:

systemctl daemon-reload

That’ll ensure the new service file is used. It should prompt you to do that automatically when you try to restart/reload/start/stop a service using systemctl, though in some cases it may not.

From there, I’d make sure the service is stopped:

systemctl stop gunicorn

Then try starting it again:

systemctl start gunicorn

If stopping and starting doesn’t work, check to see if there are any stray processes and kill them off. Sometimes this can happen when there’s issues with the service file configuration.

The issue with NGINX failing to read the process ID from the nginx.pid file is most likely due to failed service, or the service file is setting one PID file, while NGINX is trying to read from another.

@xpanta Starting a new thread, since it was getting a little narrow.

I’ve never tried to run multiple Gunicorn with SystemD like you’re trying. Try using the default Gunicorn handler: https://scottlinux.com/2014/04/03/how-to-host-multiple-django-or-python-apps-on-the-same-host-with-nginx-and-gunicorn/ Otherwise you need to create a different gunicorn.service for each project. And you could call them gunicorn-app1.service and gunicorn-app2.service.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel