启动gunicorn.service失败:未找到gunicorn.service单元

13

我正在尝试使用DjangoGunicornNginx将基本应用程序部署到Amazon EC2。我已经将应用程序通过git clone克隆到我的AWS Ubuntu实例中,并且正在运行Django 1.10

我可以使用以下命令使用Gunicorn运行我的应用程序...

gunicorn --bind 0.0.0.0:8000 blackspruceherbals.wsgi:application

但是当我尝试为Gunicorn创建upstart文件时遇到了麻烦。 文件路径如下...

/etc/init/gunicorn.conf

upstart代码如下...

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

当我运行...

sudo service gunicorn start

我遇到了以下错误信息...

Failed to start gunicorn.service: Unit gunicorn.service not found.

怎么回事?我已经在网上搜索答案,但找不到任何解决方法。你能看出我犯的明显错误吗?提前感谢。


你的Ubuntu版本是什么? - Antonis Christofides
16.04 @AntonisChristofides - Erik Åsland
2个回答

16

Antonis Christofides的答案中添加:

1)打开并创建systemd服务文件:

$ sudo nano /etc/systemd/system/gunicorn.service

2)将以下内容写入文件:

[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) 启动服务:

$ sudo systemctl start gunicorn

4) 启用该服务:

$ sudo systemctl enable gunicorn

5) 检查进程的状态:

$ sudo systemctl status gunicorn

更多内容请访问这里

谢谢。:)


2
我确实已经这样做了。但是当我运行 sudo systemctl start gunicorn 时,它会显示“无法启动gunicorn.service:找不到gunicorn.service单元。” 可能是什么原因? - Reema Parakh
1
@ReemaParakh 我修改了我的回答,将 ExecStart=/home/name_of_user/virtualenv_directory 改为 ExecStart=/home/name_of_user/myproject/virtualenv_directory - Ahtisham
你需要找到你的virtualenv目录,其子目录将包括bin、local、lib等,然后用该目录替换virtualenv_directory - Ahtisham
很有帮助。谢谢。 - Reema Parakh

14

自Ubuntu 15.04以来,upstart已被systemd所取代。您需要创建一个文件/etc/systemd/gunicorn.service,其语法与upstart文件不同。可以查看FAQ或参考man systemd.service


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接