Limit logs for “journalctl services” in systemd - Centos 7

让人想犯罪 __ 提交于 2019-12-13 04:09:43

问题


I have a service in **/etc/systemd/sysem/horses.service**

[Unit]
Description=Description for sample script goes here
After=rc-local.service

[Service]
Type=simple
ExecStart=/opt/horses/startSanic2.sh
TimeoutStartSec=0
Environment="REDIS_HOST=192.168.150.220"
Environment="REDIS_PORT=6379"

[Install]
WantedBy=default.target

It runs the shell script with this code:

#!/bin/bash
gunicorn horses.server:app --bind 0.0.0.0:9000 --worker-class sanic.worker.GunicornWorker --reload

I succesfully run it and I can see the logs of the service are being written and can be read from:

journalctl -u horses.service

if I run that command - I can see all events which that horses.service logs.

I do not have any experience with logs for systemd services. My very big concern is that because this service will be running all the time - is it possible for example to set to keep the information (logs) in journalctl -u horses.service only for example for last 10 days, or to define some round logging or whatever method is suggested in order to be sure that my logs will not be full because I do want to end with my whole disk (partition) full. Please suggest me how I can limit the logs.

Thank you in advance!!!!!!!


回答1:


What you see by running journalctl -u is the output of your app to console (or errors) which systemd take care of them for you.

The global configurations can be find at /etc/systemd/journald.conf and default values will serve your concern, so you are Ok with default values.

Btw, here are configurations you can use to alter the logging behavior:

  • SystemKeepFree: How much disk space leave for other applications (default = 15%).

  • SystemMaxuse: Maximum disk space usage (default = 10%).

By default systemd keep logs as long as it can (restricted by above rules) however if you need a rotation based configuration you can use MaxRetentionSec.

And again, you don't need to worry about disk usage by systemd, just use default configurations.



来源:https://stackoverflow.com/questions/55493637/limit-logs-for-journalctl-services-in-systemd-centos-7

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!