
我有一個 systemd 服務配置,如下所示:
[Unit]
Description=cprev agent
After=network.target
StartLimitIntervalSec=2
[Service]
Type=simple
Restart=always
RestartSec=15
ExecStart=/home/oleg/.local/bin/cprev-safe-start
[Install]
WantedBy=default.target
我像這樣安裝服務:
rsync "$PWD/systemd.service" "$HOME/.config/systemd/user/cprev.agent.service"
systemctl --user daemon-reload
systemctl --user enable cprev.agent.service
systemctl --user restart cprev.agent.service
我可以使用以下方法追蹤我的服務日誌:
journalctl -f --user -u cprev.agent.service
我的問題是 - 我是否需要手動截斷我的服務的日誌,以免它們填滿,或者 systemd 是否為我管理日誌?如果它對我有用,它是如何運作的?
答案1
根據systemd文檔,日誌journald
預設保留的大小限制為磁碟容量的 15% 或 4GB,以較小者為準。如果/var
未掛載、不可寫入或/var/log/journal
不存在,則journald
日誌將僅儲存在易失性記憶體中 ( /run/log/journal
.)
如果您的服務在 systemd 日誌之外建立自己的日誌文件,您需要建立一個對數旋轉進入管理它們。