我正在尝试在 Ubuntu 16.04 上设置一个名为project
Vagrant 的简单 uwsgi 服务。它应该启动一个 Nginx 可以与之对话的简单 Flask 应用程序。
我可以在运行时使服务正常工作
systemctl start project
,但在启动后无法使服务运行systemctl enable project
。
这是我的project.ini
:
[uwsgi]
module = wsgi:app
master = true
processes = 5
socket = /tmp/project.sock
uid = ubuntu
gid = ubuntu
chmod-socket = 666
vacuum = true
die-on-term = true
logto = /tmp/project.log
这是我的/etc/systemd/system/project.service
:
[Unit]
Description=uWSGI instance to serve project
After=network.target
[Service]
User=vagrant
Group=vagrant
WorkingDirectory=/home/vagrant/flask_trial
Environment="PATH=.:/home/vagrant/bin:/home/vagrant/.local/bin:/home/vagrant/anaconda3/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin"
ExecStart=/home/vagrant/anaconda3/bin/uwsgi --ini /home/vagrant/flask_trial/project.ini
[Install]
WantedBy=multi-user.target
启动后运行systemctl status project
产生:
Sep 12 05:26:08 vagrant systemd[1]: Started uWSGI instance to serve project.
Sep 12 05:26:09 vagrant systemd[1]: project.service: Main process exited, code=exited, status=1/FAILURE
Sep 12 05:26:09 vagrant systemd[1]: project.service: Unit entered failed state.
Sep 12 05:26:09 vagrant systemd[1]: project.service: Failed with result 'exit-code'.
运行journalctl | grep project
产量:
Sep 12 05:26:08 vagrant systemd[1]: Started uWSGI instance to serve project.
Sep 12 05:26:09 vagrant uwsgi[1123]: realpath() of /home/vagrant/flask_trial/project.ini failed: No such file or directory [core/utils.c line 3618]
Sep 12 05:26:09 vagrant systemd[1]: project.service: Main process exited, code=exited, status=1/FAILURE
Sep 12 05:26:09 vagrant systemd[1]: project.service: Unit entered failed state.
Sep 12 05:26:09 vagrant systemd[1]: project.service: Failed with result 'exit-code'.
我怀疑两个问题之一:文件权限,因为谷歌显示人们经常难以获得这些权利,或者路径,因为 realpath() 失败。
许可flask_trial
是
drwxrwxr-x 1 vagrant vagrant 272 Sep 12 04:50 flask_trial
对于其中的所有文件:
-rwxrwxr-x 1 vagrant vagrant 185 Sep 11 02:59 main.py
-rwxrwxr-x 1 vagrant vagrant 189 Sep 12 04:50 project.ini
-rwxrwxr-x 1 vagrant vagrant 70 Sep 11 03:47 wsgi.py
我启用服务 with servicectl enable project
, without sudo
,所以用户应该是vagrant
。
怀疑路径问题,因为看起来 uwsgi 找不到 project.ini,我尝试将 ExecStart 修改为以下任何一个:
ExecStart=/home/vagrant/anaconda3/bin/uwsgi --ini /home/vagrant/flask_trial/project.ini
ExecStart=/home/vagrant/anaconda3/bin/uwsgi --ini project.ini
ExecStart=/home/vagrant/anaconda3/bin/uwsgi --ini ./project.ini
以上似乎都不适用于启动,但都适用于systemctl start
. 真的在这里迷路了,希望能得到一些评论。