小编que*_*dam的帖子

在 Ubuntu 16.04 上使用 systemd 截断/丢失日志

我正在使用 Ubuntu 16.04 服务器,创建了一个基本的 nodejs 脚本并将其打包在一个简单的 systemd 服务中。

api.service 的内容/lib/systemd/system/api.service

[Unit]
Description=api
After=network.target

[Service]
WorkingDirectory=/var/node/api
ExecStart=/usr/bin/node index.js
Restart=always
RestartSec=5s
StartLimitInterval=60s
StartLimitBurst=5

[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud)

当我用 看日志时journalctl -u api.service -n -f,似乎我的一些脚本输出行没有被记录,特别是当脚本在短时间内产生大量日志行时。

例如,如果 nodejs 脚本只是一个简单的 for 循环,输出前 3000 个整数,那么日志中似乎只记录了大约 2500 行。

index.js 的内容在/var/node/api/index.js

for (var i = 1; i <= 3000; i++) {
    console.log(i);
}
console.log("end of script");
Run Code Online (Sandbox Code Playgroud)

查看日志时journalctl -u api.service -n -f,我只得到大约 2500 行:

May 04 13:52:15 test systemd[1]: Stopping api...
May 04 13:52:15 …
Run Code Online (Sandbox Code Playgroud)

ubuntu systemd systemctl journald journalctl

2
推荐指数
1
解决办法
1397
查看次数

标签 统计

journalctl ×1

journald ×1

systemctl ×1

systemd ×1

ubuntu ×1