无法启动gunicorn.service:未找到Unit gunicorn.service

Eri*_*and 5 django ubuntu amazon-ec2 amazon-web-services gunicorn

我想一个基本的应用程序部署到Amazon EC2使用Django,GunicornNginx.我有应用程序git clone进入我的AWS Ubuntu实例并正在运行Django 1.10.

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

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

当我尝试为其创建一个upstart文件时,我遇到了麻烦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
Run Code Online (Sandbox Code Playgroud)

当我跑...

sudo service gunicorn start

我收到以下错误...

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

是什么赋予了?我已经在互联网上寻找答案,但一无所获.你能看到一些明显我做错的事吗?提前致谢.

Ant*_*des 10

由于Ubuntu 15.04 upstart已被替换systemd.您需要创建一个文件/etc/systemd/gunicorn.service,其语法与upstart文件不同.该FAQ可以让你开始,而参照man systemd.service.


Aht*_*ham 10

添加安东尼·克里斯托菲德斯的回答:

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

$ sudo nano /etc/systemd/system/gunicorn.service
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

3)启动服务:

$ sudo systemctl start gunicorn
Run Code Online (Sandbox Code Playgroud)

4)启用服务:

$ sudo systemctl enable gunicorn
Run Code Online (Sandbox Code Playgroud)

5)检查进程状态:

$ sudo systemctl status gunicorn
Run Code Online (Sandbox Code Playgroud)

更多请访问这里

谢谢。:)

  • 我确实做到了这一点。但是,当我运行 `sudo systemctl start gunicorn` 时,它说 - `无法启动 gunicorn.service:未找到 Unit gunicorn.service。` 有什么可能 (2认同)