【问题标题】:Failed to start gunicorn.service: Unit gunicorn.service not found启动 gunicorn.service 失败:未找到 Unit gunicorn.service
【发布时间】:2017-04-04 08:25:18
【问题描述】:

我正在尝试使用 DjangoGunicornNginx 将基本应用程序部署到 Amazon EC2。我有应用程序git clone'd 到我的AWS Ubuntu 实例中并且正在运行Django 1.10

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

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

当我尝试为Gunicorn 创建一个新贵文件时,我遇到了麻烦。文件路径如下...

/etc/init/gunicorn.conf

暴发户的代码是这样的……

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 版本是多少?
  • 16.04 @AntonisChristofides

标签: django amazon-web-services ubuntu amazon-ec2 gunicorn


【解决方案1】:

添加到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

更多信息请访问here

谢谢。 :)

【讨论】:

  • 我确实做到了。但是当我运行sudo systemctl start gunicorn 时,它会说-Failed to start gunicorn.service: Unit gunicorn.service not found. 有什么可能
  • @ReemaParakh 我编辑我的答案,将 ExecStart=/home/name_of_user/virtualenv_directory 更改为 ExecStart=/home/name_of_user/myproject/virtualenv_directory
  • 您需要找到您的 virtualenv 目录,其子目录将是 bin、local、lib 等,然后将 virtualenv_directory 替换为该目录。
  • 它有帮助。谢谢。
【解决方案2】:

自 Ubuntu 15.04 起,upstart 已被 systemd 取代。您需要创建一个文件/etc/systemd/gunicorn.service,它的语法与upstart 文件不同。 FAQ 可以帮助您入门,参考是man systemd.service

【讨论】:

    猜你喜欢
    • 2023-04-10
    • 2018-06-14
    • 2021-11-08
    • 1970-01-01
    • 2020-09-21
    • 1970-01-01
    • 1970-01-01
    • 2020-03-21
    • 2022-10-14
    相关资源
    最近更新 更多