问题
I am trying to deploy a basic application to Amazon EC2
using Django
, Gunicorn
, and Nginx
. I have the app git clone
'd into my AWS
Ubuntu
instance and am running Django 1.10
.
I am able to run my app using Gunicorn
with the following command...
gunicorn --bind 0.0.0.0:8000 blackspruceherbals.wsgi:application
I am running into trouble though when I try to create a upstart file for Gunicorn
. The file path is as follows...
/etc/init/gunicorn.conf
and the upstart code looks like this...
description "Gunicorn application server handling black spruce herbals"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
setuid ubuntu
setgid www-data
chdir /home/ubuntu/websitename/
exec bsh_env/bin/gunicorn --workers 3 --bind unix:/home/ubuntu/websitename/websitename.sock websitename.wsgi:application
When I run...
sudo service gunicorn start
I get the following error...
Failed to start gunicorn.service: Unit gunicorn.service not found.
What gives? I have scoured the internet looking for an answer, but have found nothing. Can you see something obvious I am doing wrong? Thanks in advance.
回答1:
Since Ubuntu 15.04 upstart
has been replaced by systemd
. You need to create a file /etc/systemd/gunicorn.service
, which has a different syntax than the upstart
file. The FAQ can get you started, and the reference is man systemd.service
.
回答2:
Adding to Antonis Christofides answer:
1) Open and create systemd service file:
$ sudo nano /etc/systemd/system/gunicorn.service
2) Write the following content to the file:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=name_of_user
Group=name_of_user
WorkingDirectory=/home/name_of_user/myproject
ExecStart=/home/name_of_user/myproject/virtualenv_directory/bin/gunicorn --
access-logfile - --workers 3 --bind unix:/home/name_of_user/myproject/myproject.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
3) Starting the service:
$ sudo systemctl start gunicorn
4) Enabling the service:
$ sudo systemctl enable gunicorn
5) Check the status of the process:
$ sudo systemctl status gunicorn
For more visit here
Thanks. :)
来源:https://stackoverflow.com/questions/40711747/failed-to-start-gunicorn-service-unit-gunicorn-service-not-found