我有一个非常简单的SystemD用户单元:
~/.config/systemd/user/logtest.service
[Unit]
Description=log test
After=network.target
[Service]
Type=oneshot
ExecStart=/home/andrey/tmp/1.sh
[Install]
WantedBy=default.target1.sh就是echo
#!/bin/bash
echo "123"我启动它,systemctl start --user logtest.service
然后我检查日志journalctl --user-unit logtest -n5,但是在这个输出中看不到我的123。为什么?
journalctl --user-unit logtest -n5
-- Logs begin at Сб 2016-10-15 22:17:53 +07, end at Пт 2017-01-06 16:03:16 +07. --
янв 06 16:03:15 andrcomp systemd[1524]: Started log test.
янв 06 16:03:16 andrcomp systemd[1524]: Starting log test...
янв 06 16:03:16 andrcomp systemd[1524]: Started log test.
янв 06 16:03:16 andrcomp systemd[1524]: Starting log test...
янв 06 16:03:16 andrcomp systemd[1524]: Started log test.但是如果我把sleep 1添加到1.sh
#!/bin/bash
echo "123"
sleep 1然后123出现在我的日志中
$ journalctl --user-unit logtest -n5
-- Logs begin at Сб 2016-10-15 22:17:53 +07, end at Пт 2017-01-06 16:10:25 +07. --
янв 06 16:07:57 andrcomp systemd[1524]: Starting log test...
янв 06 16:07:57 andrcomp systemd[1524]: Started log test.
янв 06 16:10:24 andrcomp systemd[1524]: Starting log test...
янв 06 16:10:24 andrcomp 1.sh[3760]: 123
янв 06 16:10:25 andrcomp systemd[1524]: Started log test.为什么?
如果我检查所有的用户日志,那么123就在这里(1.sh中没有sleep )。
$ journalctl --user -n5
-- Logs begin at Вс 2016-12-18 16:15:56 +07, end at Пт 2017-01-06 16:13:32 +07. --
янв 06 16:13:32 andrcomp 1.sh[3997]: 123
янв 06 16:13:32 andrcomp systemd[1524]: Started log test.
янв 06 16:13:32 andrcomp systemd[1524]: Starting log test...
янв 06 16:13:32 andrcomp 1.sh[4007]: 123
янв 06 16:13:32 andrcomp systemd[1524]: Started log test.但我只需要看一些单位日志
它作为系统单元(/usr/lib/systemd/system/logtest_syst.service)运行良好。
$ journalctl -u logtest_syst
-- Logs begin at Сб 2016-10-15 22:17:53 +07, end at Пт 2017-01-06 15:43:59 +07. --
янв 06 15:43:59 andrcomp systemd[1]: Starting log test...
янв 06 15:43:59 andrcomp 1.sh[1082]: 123
янв 06 15:43:59 andrcomp systemd[1]: Started log test.有睡眠的魔术师是什么?或者它不是检查用户单元日志的正确方法?
发布于 2017-06-24 14:49:59
有一个错误标记为封闭的CANTFIX关于这个:期刊错过显示来自单位的日志
Red高级软件工程师Michal Sekletar说:
这是一个众所周知的问题。系统日志有时无法记录日志消息来源于哪个单元的信息。如果记录消息的进程是短暂的,则遇到此问题的可能性更高。 ..。 原木不会消失。只是对于一些来自短暂进程的日志消息,日志记录无法计算出各自的cgroup (单元)。因此,如果应用基于单元名称的筛选,则不会看到这些日志行。在内核给我们一种方法以非理性的方式收集cgroup信息之前,我们不能对此做任何事情。但是,日志仍然存在,使用基于时间的过滤的第一个命令证明了这一点。
因此,您应该能够使用如下命令查看脚本的输出(没有睡眠):
journalctl --since "2016-10-15 22:17:53"https://stackoverflow.com/questions/41502564
复制相似问题