Linux journalctl 未与 systemctl 状态同步/Journalctl 未更新

Linux journalctl 未与 systemctl 状态同步/Journalctl 未更新

我正在运行我的自定义服务,我们称之为“foo.service”。这是一个 gunicorn python 进程,用于记录一些内容。

我以前能够使用 获得实时日志概览journalctl -u <service> -f,但现在日志似乎停留在某些过去的日志上。当我使用systemctl status <service>它时,它确实会显示最新日志。所以我的日志记录确实有效,但 journalctl 似乎卡住了,没有显示任何更新。

例子:

journalctl -u foo.service -f

Nov 25 16:19:09 <name> systemd[1]: Started Instance to load up the program and its endpoints.
Nov 25 16:19:09 <name> gunicorn[28267]: 2019-11-25 16:19:09,844 [INFO]: Connecting to localhost:9773
Nov 25 16:19:09 <name> gunicorn[28267]: 2019-11-25 16:19:09,845 [INFO]: Connecting to localhost:9771
Nov 25 16:19:09 <name> gunicorn[28267]: 2019-11-25 16:19:09,846 [INFO]: Connected
Nov 25 16:19:09 <name> gunicorn[28267]: 2019-11-25 16:19:09,846 [INFO]: Connected

systemctl status foo.service

Nov 26 11:39:53 <name> systemd[1]: Started Instance to load up the program and its endpoints.
Nov 26 11:39:53 <name> gunicorn[29117]: 2019-11-26 11:39:53,458 [INFO]: Connecting to localhost:9773
Nov 26 11:39:53 <name> gunicorn[29117]: 2019-11-26 11:39:53,459 [INFO]: Connecting to localhost:9771
Nov 26 11:39:53 <name> gunicorn[29117]: 2019-11-26 11:39:53,460 [INFO]: Connected
Nov 26 11:39:53 <name> gunicorn[29117]: 2019-11-26 11:39:53,460 [INFO]: Connected

后者是刚刚创建的日志,因此效果很好,但据我了解,journalctl 似乎也已更新。这在过去确实有效,但我从前天开始就遇到了这些问题。

我尝试重新启动 journalctl,但似乎不起作用。

提前致谢。

编辑: 当我重新启动服务时,我注意到在查看 systemctl 服务的状态时 gunicorn 引发了异常,我无法向上滚动,所以我不知道错误的原因是什么(systemctl 状态):

Nov 26 15:08:27 <name> gunicorn[29390]:     self.log.info("Shutting down: %s", self.master_name)
Nov 26 15:08:27 <name> gunicorn[29390]:   File "/opt/my-program/venv/lib/python3.5/site-packages/gunicorn/glogging.py", line 271, in info
Nov 26 15:08:27 <name> gunicorn[29390]:     self.error_log.info(msg, *args, **kwargs)
Nov 26 15:08:27 <name> gunicorn[29390]: Message: 'Shutting down: %s'
Nov 26 15:08:27 <name> gunicorn[29390]: Arguments: ('Master',)
Nov 26 15:08:27 <name> systemd[1]: Started Instance to load up the program and its endpoints.

我的 foo.service 配置文件:

[Unit]
Description=Instance to load up the program and its endpoints
After=network.target

[Service]
User=root
Group=www-data
WorkingDirectory=/opt/my-program/my-program-thing
Environment="PATH=/opt/my-program/venv/bin"
ExecStart=/opt/my-program/venv/bin/gunicorn --workers 1 --threads 12 --bind unix:foo.sock -m 007 app:app --bind 0.0.0.0:8085 --access-logfile '/var/log/foo.info.log' --error-logfile '/var/log/foo.err.log'
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target

答案1

尝试将这些行添加到服务文件的 [Service] 标签下

StandardOutput=journal StandardError=journal

然后执行 systemctl daemon-reload,然后执行 systemctl restart your_service.service

我编辑了答案,以便其他人轻松查看。问题在于 /var 文件系统空间不足,因此 journalctl 无法将日志保存到磁盘并在之后读取,这就是 systemctl status 和 journalctl -fu 之间存在差异的原因。

相关内容