3

When setting up a new Ubuntu 15.10 x64 server running nginx, gunicorn, django as a sudo user. I am getting an error message by running service gunicorn start (as root, yes it is a bad idea):

Failed to start gunicorn.service: 
Unit gunicorn.service failed to load: No such file or directory.

From an active virtualenv I can start gunicorn using:

Any ideas would be greatly appreciated on how to resolve this as I have tried quite a few suggestions from various web searches that mentioned problems similar to this with no luck.

My gunicorn file is at `/etc/init/gunicorn.conf` and is configured as follows:

description "Gunicorn application server handling myproject"

start on runlevel [2345]
stop on runlevel [!2345]

respawn
setuid myuser
setgid www-data
chdir /home/myuser/myproject

exec myprojectenv/bin/gunicorn --workers 3 --bind unix:/home/myuser/myproject/myproject.sock myproject.wsgi:application

This question is identical to here, but I don't have privileges to comment and the user seemed to have found the answer with systemd. The original problem stems from following this guide on Ubuntu 15.10. I tried checking the comments section on that page, searching with my google fu and various websites arriving here.

Simplified help would be much appreciated for someone somewhat new with Ubuntu.

1 Answer 1

3

What's happening is you are trying to use Upstart when you need to be using Systemd. So, you need to be using the Systemd configuration, instead of Upstart.

Taken from http://docs.gunicorn.org/en/stable/deploy.html

Systemd

A tool that is starting to be common on linux systems is Systemd. Here are configurations files to set the Gunicorn launch in systemd and the interfaces on which Gunicorn will listen. The sockets will be managed by systemd:

/lib/systemd/system/gunicorn.service:

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

[Service]
PIDFile=/run/gunicorn/pid
User=someuser
Group=someuser
WorkingDirectory=/home/someuser
ExecStart=/home/someuser/gunicorn/bin/gunicorn --pid /run/gunicorn/pid test:app
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

gunicorn.socket:

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn/socket
ListenStream=0.0.0.0:9000
ListenStream=[::]:8000

[Install]
WantedBy=sockets.target

tmpfiles.d/gunicorn.conf:

d /run/gunicorn 0755 someuser someuser -

After running curl http://localhost:9000/, Gunicorn should start and you should see something like that in logs:

2013-02-19 23:48:19 [31436] [DEBUG] Socket activation sockets: unix:/run/gunicorn/socket,http://0.0.0.0:9000,http://[::]:8000

2
  • Is there a way to continue using Upstart? Why use systemd, when it seem overwhelming. I have no idea what most of the settings are in that gunicorn.service file. Upstart would make it easier for a beginner like me to get up and running.
    – clueless
    Mar 22, 2016 at 23:55
  • That's above my pay grade, however, I can recommend against it. Just like many things, when a software becomes depreciated in favor or something else, it's normally a good idea to use the 'something else'. You'll have an uphill battle with just about every application that would rely on systemd to start to have it work with upstart. Ubuntu 15.04 had both with a later updates setting systemd as default, I believe 15.10 only has systemd.
    – user508889
    Mar 23, 2016 at 0:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .