gunicorn [/etc/systemd/system/gunicorn.socket:6]未知的“服务”部分。忽略

时间:2019-05-17 08:19:47

标签: django gunicorn

我要在digitalocean上设置django,他们有一个设置规则,即使gunicorn无法使用,这次也可以使用。

第一步是使用此命令sudo nano /etc/systemd/system/gunicorn.service

设置gunicorn服务

和内容

[Unit]
Description=gunicorn daemon
Requires=gunicorn.socket
After=network.target

[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/webapp/prestige
ExecStart=/home/sammy/webapp/envs/prestige/bin/gunicorn \
        --access-logfile - \
        --workers 3 \
        --bind unix:/run/gunicorn.sock \
        prestige.wsgi:application

[Install]
WantedBy=multi-user.target

和套接字文件sudo nano /etc/systemd/system/gunicorn.socket

[Unit]
Description=gunicorn socket

[Socket]
ListenStream=/run/gunicorn.sock

[Install]
WantedBy=sockets.target

请注意该目录

/home/sammy/webapp/prestige

是带有manage.py的django的主文件夹目录,因此,基本上,如果我进入cd,我就可以运行python manage.py runserver并起作用。

这是virtualenv的文件夹

/home/sammy/webapp/envs/prestige

现在,当我运行start gunicorn命令时,我得到了

(prestige) sammy@prestige:~/webapp$ sudo systemctl start gunicorn.socket
Failed to start gunicorn.socket: Unit gunicorn.socket is not loaded properly: Invalid argument.
See system logs and 'systemctl status gunicorn.socket' for details.

如果您查看状态

(prestige) sammy@prestige:~/webapp$ sudo systemctl status gunicorn.socket
● gunicorn.socket - gunicorn daemon
Loaded: error (Reason: Invalid argument)
Active: inactive (dead)
May 17 07:25:18 prestige systemd[1]: [/etc/systemd/system/gunicorn.socket:6] Unknown section 'Service'. Ignoring.
May 17 07:25:18 prestige systemd[1]: gunicorn.socket: Unit lacks Listen setting. Refusing.
May 17 07:33:32 prestige systemd[1]: [/etc/systemd/system/gunicorn.socket:6] Unknown section 'Service'. Ignoring.
May 17 07:33:32 prestige systemd[1]: gunicorn.socket: Unit lacks Listen setting. Refusing.
May 17 07:34:09 prestige systemd[1]: [/etc/systemd/system/gunicorn.socket:6] Unknown section 'Service'. Ignoring.
May 17 07:34:09 prestige systemd[1]: gunicorn.socket: Unit lacks Listen setting. Refusing.
May 17 07:53:41 prestige systemd[1]: [/etc/systemd/system/gunicorn.socket:6] Unknown section 'Service'. Ignoring.
May 17 07:53:41 prestige systemd[1]: gunicorn.socket: Unit lacks Listen setting. Refusing.
May 17 07:56:59 prestige systemd[1]: [/etc/systemd/system/gunicorn.socket:6] Unknown section 'Service'. Ignoring.
May 17 07:56:59 prestige systemd[1]: gunicorn.socket: Unit lacks Listen setting. Refusing.

不知道发生了什么事。

1 个答案:

答案 0 :(得分:0)

发现了一种很难的方法,即如果为服务或套接字输入了错误的代码,则会导致错误。刚删除小滴并重新启动后,它就可以顺利进行。