我正在尝试将基本应用程序部署到 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/