systemctl start 可以工作,但是 systemctl enable 失败并出现 realpath() 错误

systemctl start 可以工作,但是 systemctl enable 失败并出现 realpath() 错误

我正在尝试在 Vagrant(Ubuntu 16.04)上设置一个名为的简单 uwsgi 服务project。它应该启动一个 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

我启用有servicectl enable project、无服务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

以上方法似乎都不适用于 boot,但都适用于 with systemctl start。真的很困惑,希望能得到一些评论。

答案1

好的,向别人说出你的问题确实可以帮助你从不同的角度看待手头的问题。

这里没什么问题systemctl。问题是我的 /flask_trial 项目是一个共享的 Vagrant 文件夹,显然在systemctl运行后与系统链接 - 所以systemctl找不到.ini文件。我真傻。

一旦我知道了我的问题是什么,我就知道要问什么问题,这里有一个很好的解决方案: https://serverfault.com/a/838390/435122

相关内容