无法 运行 uwsgi .ini 文件与 systemd emperor
Can't run uwsgi .ini file with systemd emperor
我正在尝试在带有 Fedora 24 的 Linode 上为 Django 1.10 的 systemd 设置 uwsgi.service 到 运行。
/etc/systemd/system/uwsgi.服务
[Unit]
Description=uWSGI Emperor
After=syslog.target
[Service]
ExecStart=/home/ofey/djangoenv/bin/uwsgi --ini /etc/uwsgi/emperor.ini
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
这应该调用,
/etc/uwsgi/emporer.ini
[uwsgi]
emperor = /etc/uwsgi/vassals
uid = www-data
gid = www-data
limit-as = 1024
logto = /tmp/uwsgi.log
然后我使用符号 link,
$ sudo ln -s /home/ofey/djangoForum/django.ini /etc/uwsgi/vassals/
到
/home/ofey/djangoForum/django.ini
[uwsgi]
project = djangoForum
base = /home/ofey
chdir = %(base)/%(project)
home = %(base)/djangoenv
module = crudProject.wsgi:application
master = true
processes = 2
socket = 127.0.0.1:3031
chmod-socket = 664
vacuum = true
我已经重新启动了,
$ sudo systemctl daemon-reload
$ sudo systemctl restart nginx.service
$ sudo systemctl retart uwsgi.service
最后一条命令给出,
Job for uwsgi.service failed because the control process exited with error code. See "systemctl status uwsgi.service" and "journalctl -xe" for details.
$ sudo systemctl status uwsgi.service
给予,
● uwsgi.service - uWSGI Emperor
Loaded: loaded (/etc/systemd/system/uwsgi.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Dec 07 23:56:28 ofeyspi systemd[1]: Starting uWSGI Emperor...
Dec 07 23:56:28 ofeyspi uwsgi[7834]: [uWSGI] getting INI configuration from /etc/uwsgi/emperor.ini
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Main process exited, code=exited, status=1/FAILURE
Dec 07 23:56:28 ofeyspi systemd[1]: Failed to start uWSGI Emperor.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Unit entered failed state.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Failed with result 'exit-code'.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Service hold-off time over, scheduling restart.
Dec 07 23:56:28 ofeyspi systemd[1]: Stopped uWSGI Emperor.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Start request repeated too quickly.
Dec 07 23:56:28 ofeyspi systemd[1]: Failed to start uWSGI Emperor.
我不明白为什么 uwsgi.service 不会 运行。
uwsgi 运行s 当我不通过 systemd 而是使用时,
$ sudo --ini django.ini
uwsgi systemd docs 建议将 RuntimeDirectory=uwsgi
添加到您的服务文件中。尝试添加它。
同时检查 /tmp/uwsgi.log
以查看是否在那里生成了任何日志记录。
最可能的原因是皇帝不能:
- 创建 .pid 文件以写入进程 ID;
- 为 vassal 创建 unix-socket 文件(似乎不是你的情况,因为你使用的是 :3031 端口);
- 写入由
--logto
选项指定的日志文件(/tmp/uwsgi.log)。
当这些文件中的任何一个存在并且由另一个用户(最有可能是 root)拥有,或者位于启动服务的用户无法写入的目录中时,通常会发生这种情况。
Systemd 的状态日志关于这个主题的信息不是很丰富。因此,识别案例的最快方法是 运行 来自 systemd 服务的 ExecStart
命令 而不是 root 并查看输出:
$ /home/ofey/djangoenv/bin/uwsgi --ini /etc/uwsgi/emperor.ini
如果输出显示权限问题,请尝试以下操作。
因为您要代表 www-data
用户访问您的服务器,正如已经有人建议的那样,请确保您有:
[Service]
User=www-data
Group=www-data
RuntimeDirectory=uwsgi
在您的 systemd 单元配置中。然后,确保 .pid 文件和 unix-socket 文件(如果有的话)是在该目录下创建的(即在 /run/uwsgi 下),方法是将其添加到您的 vassal .ini 文件中:
runtime_dir = /run/uwsgi
pidfile=%(runtime_dir)/%n.pid
# if you prefer using unix-socket instead of a port
socket = %(runtime_dir)/%n.sock
# trying to chmod-socket is useless with a port, by the way
chmod-socket = 664
给定示例中的 %n
变量代表不带扩展名的 vassal 的 .ini 文件名(参见 full-list here)。
最后,确保在皇帝和封臣的配置中指定的--logto
文件是可写的。
请注意,如果你运行 uwsgi --ini /etc/uwsgi/emperor.ini
as root 然后用ctrl+D终止procecc,它会留下上面提到的temp文件存在并且 由 root 拥有,这将阻止其他所有者(如 www-data)写入它们,直到您删除文件或 chown/chmod
他们又来了。
注释掉KillSignal = SIGQUIT
它可能会导致问题,请参阅 http://uwsgi-docs.readthedocs.io/en/latest/Systemd.html
也会导致 Centos 7 出现问题
我正在尝试在带有 Fedora 24 的 Linode 上为 Django 1.10 的 systemd 设置 uwsgi.service 到 运行。
/etc/systemd/system/uwsgi.服务
[Unit]
Description=uWSGI Emperor
After=syslog.target
[Service]
ExecStart=/home/ofey/djangoenv/bin/uwsgi --ini /etc/uwsgi/emperor.ini
Restart=always
KillSignal=SIGQUIT
Type=notify
StandardError=syslog
NotifyAccess=all
[Install]
WantedBy=multi-user.target
这应该调用, /etc/uwsgi/emporer.ini
[uwsgi]
emperor = /etc/uwsgi/vassals
uid = www-data
gid = www-data
limit-as = 1024
logto = /tmp/uwsgi.log
然后我使用符号 link,
$ sudo ln -s /home/ofey/djangoForum/django.ini /etc/uwsgi/vassals/
到 /home/ofey/djangoForum/django.ini
[uwsgi]
project = djangoForum
base = /home/ofey
chdir = %(base)/%(project)
home = %(base)/djangoenv
module = crudProject.wsgi:application
master = true
processes = 2
socket = 127.0.0.1:3031
chmod-socket = 664
vacuum = true
我已经重新启动了,
$ sudo systemctl daemon-reload
$ sudo systemctl restart nginx.service
$ sudo systemctl retart uwsgi.service
最后一条命令给出,
Job for uwsgi.service failed because the control process exited with error code. See "systemctl status uwsgi.service" and "journalctl -xe" for details.
$ sudo systemctl status uwsgi.service
给予,
● uwsgi.service - uWSGI Emperor
Loaded: loaded (/etc/systemd/system/uwsgi.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Dec 07 23:56:28 ofeyspi systemd[1]: Starting uWSGI Emperor...
Dec 07 23:56:28 ofeyspi uwsgi[7834]: [uWSGI] getting INI configuration from /etc/uwsgi/emperor.ini
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Main process exited, code=exited, status=1/FAILURE
Dec 07 23:56:28 ofeyspi systemd[1]: Failed to start uWSGI Emperor.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Unit entered failed state.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Failed with result 'exit-code'.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Service hold-off time over, scheduling restart.
Dec 07 23:56:28 ofeyspi systemd[1]: Stopped uWSGI Emperor.
Dec 07 23:56:28 ofeyspi systemd[1]: uwsgi.service: Start request repeated too quickly.
Dec 07 23:56:28 ofeyspi systemd[1]: Failed to start uWSGI Emperor.
我不明白为什么 uwsgi.service 不会 运行。
uwsgi 运行s 当我不通过 systemd 而是使用时,
$ sudo --ini django.ini
uwsgi systemd docs 建议将 RuntimeDirectory=uwsgi
添加到您的服务文件中。尝试添加它。
同时检查 /tmp/uwsgi.log
以查看是否在那里生成了任何日志记录。
最可能的原因是皇帝不能:
- 创建 .pid 文件以写入进程 ID;
- 为 vassal 创建 unix-socket 文件(似乎不是你的情况,因为你使用的是 :3031 端口);
- 写入由
--logto
选项指定的日志文件(/tmp/uwsgi.log)。
当这些文件中的任何一个存在并且由另一个用户(最有可能是 root)拥有,或者位于启动服务的用户无法写入的目录中时,通常会发生这种情况。
Systemd 的状态日志关于这个主题的信息不是很丰富。因此,识别案例的最快方法是 运行 来自 systemd 服务的 ExecStart
命令 而不是 root 并查看输出:
$ /home/ofey/djangoenv/bin/uwsgi --ini /etc/uwsgi/emperor.ini
如果输出显示权限问题,请尝试以下操作。
因为您要代表 www-data
用户访问您的服务器,正如已经有人建议的那样,请确保您有:
[Service]
User=www-data
Group=www-data
RuntimeDirectory=uwsgi
在您的 systemd 单元配置中。然后,确保 .pid 文件和 unix-socket 文件(如果有的话)是在该目录下创建的(即在 /run/uwsgi 下),方法是将其添加到您的 vassal .ini 文件中:
runtime_dir = /run/uwsgi
pidfile=%(runtime_dir)/%n.pid
# if you prefer using unix-socket instead of a port
socket = %(runtime_dir)/%n.sock
# trying to chmod-socket is useless with a port, by the way
chmod-socket = 664
给定示例中的 %n
变量代表不带扩展名的 vassal 的 .ini 文件名(参见 full-list here)。
最后,确保在皇帝和封臣的配置中指定的--logto
文件是可写的。
请注意,如果你运行 uwsgi --ini /etc/uwsgi/emperor.ini
as root 然后用ctrl+D终止procecc,它会留下上面提到的temp文件存在并且 由 root 拥有,这将阻止其他所有者(如 www-data)写入它们,直到您删除文件或 chown/chmod
他们又来了。
注释掉KillSignal = SIGQUIT
它可能会导致问题,请参阅 http://uwsgi-docs.readthedocs.io/en/latest/Systemd.html
也会导致 Centos 7 出现问题