linux - Python Flask 服务文件未启动

标签 linux python-3.x flask raspberry-pi uwsgi

我写了一个小应用程序。该应用程序运行良好。但是,我正在尝试创建服务文件,但遇到了问题。运行命令 sudo uwsgi uwsgi.ini 有效。应用程序启动。 我创建了一个服务文件。

[Unit]
Description=uWsgi instance to start relay site
After=network.target

[Service]
User=pi
Group=pi
WorkingDirectory=/var/www/relay
ExecStart=sudo uwsgi uwsgi.ini

[Install]
WantedBy=multi-user.target

当我尝试启动服务文件时出现错误。

Loaded: error (Reason: Invalid argument)
relay.service: Unit entered failed state.
relay.service: Failed with result 'exit-code'.
[/etc/systemd/system/relay.service:11] Executable path is not absolute, ignoring: uwsgi uwsgi.ini
relay.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.
[/etc/systemd/system/relay.service:9] Executable path is not absolute, ignoring: sudo uwsgi uwsgi.ini
relay.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

最佳答案

它说 Executable path is not absolute 因为可执行文件是 sudo 而不是 /usr/bin/sudo。 Systemd 需要完整路径,因为它不像您使用终端那样使用 shell。

此外,如果您要 sudo 命令,那么您也可以使用 root 作为用户(这是默认设置)。这样的事情应该有效:

[Service]
WorkingDirectory=/var/www/relay
ExecStart=/absolute/path/to/uwsgi uwsgi.ini

你可以运行which uwsgi来找到uwsgi的绝对路径。

关于linux - Python Flask 服务文件未启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55444108/

相关文章:

python - 如何为 python 3.0 的仅关键字参数导入 __future__?

python-3.x - Pyspark:如何将 spark 数据帧转换为 json 并将其另存为 json 文件?

python - 如何在 Python 中检测一行的结尾

javascript - 从ajax get请求接收到的数据

java - PhantomJs 2.1.1 无法在带有 Selenium 3.4 的 CentOs 6.5 上运行

sql - linux 中具有多个子行的文本文件中的精确行

c - 如何链接 geany 中的 math.h 库?

c++ - 每次将目标文件转储到其他目录时,makefile 都会重建

python - Flask - 避免将完整的用户名和密码放入配置中

python - 如果 Jinja2 没有小数值,如何四舍五入为零小数?