loggingservicecentos7systemdsystemd-journald

Limit logs for "journalctl services" in systemd - Centos 7


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!!!!!!!


Solution

  • 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:

    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.