django - 无法启动 gunicorn.service : Unit gunicorn. 找不到服务

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

我正在尝试将基本应用程序部署到 Amazon EC2使用 Django , Gunicorn , 和 Nginx .我有应用 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.

什么给了?我已经在互联网上搜索以寻找答案,但一无所获。你能看出我做错了什么吗?提前致谢。

最佳答案

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

谢谢。 :)

关于django - 无法启动 gunicorn.service : Unit gunicorn. 找不到服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40711747/

相关文章:

python - 以 django 模型形式手动输入值

javascript - 如何让JavaScript从Django中的views.py中识别context_dict对象

linux - 什么 Linux 命令将在本地主机和远程服务器之间同步文件?

Django:ModelMultipleChoiceField 不会保存数据

python - apscheduler:返回了多个 DjangoJobExecution - 它返回了 2

amazon-web-services - 无需配置即可在 EC2 内的 docker 中使用 awscli

amazon-web-services - 无法在区域/可用区中创建 EBS

python - 在 python2 boto 中使用 aws 配置文件

linux - Ubuntu shell 脚本 - root 权限

search - 最优 Solr JVM/虚拟/物理内存配置