Evita que o systemd grave no syslog sempre que iniciar o mesmo serviço

6

Eu tenho um serviço que é executado a cada 30 segundos. O arquivo de timer do systemd para este serviço é o seguinte:

~# cat /etc/systemd/system/speed_check.timer
[Unit]
Description="Check device speed"

[Timer]
OnBootSec=1
OnUnitActiveSec=30

[Install]
WantedBy=multi-user.target

O arquivo de serviço simplesmente chama um script python:

# cat /etc/systemd/system/speed_check.service 
[Unit]
Description=Check device speed

[Service]
Type=simple
ExecStart=/usr/bin/check-speed

A cada 30 segundos, quando o systemd inicia o serviço, ele imprime dois logs:

Jan  8 17:54:23 localhost systemd[1]: Starting Check device speed...
Jan  8 17:54:23 localhost systemd[1]: Started Check device speed.

Existe uma maneira de suprimir essas mensagens? Eles estão enchendo meu syslog!

obrigado

    
por linuxfan 08.01.2015 / 19:07

1 resposta

2

Existem várias possibilidades. Você deve configurar o arquivo /etc/systemd/journald.conf . Duas opções relevantes (da página man) são:

RateLimitInterval=, RateLimitBurst=

 Configures the rate limiting that is applied to all messages generated on the system. If, in the time interval
       defined by RateLimitInterval=, more messages than specified in RateLimitBurst= are logged by a service, all
       further messages within the interval are dropped until the interval is over. A message about the number of
       dropped messages is generated. This rate limiting is applied per-service, so that two services which log do not
       interfere with each other's limits. Defaults to 1000 messages in 30s. The time specification for
       RateLimitInterval= may be specified in the following units: "s", "min", "h", "ms", "us". To turn off any kind of
       rate limiting, set either value to 0.

e

Storage=

      Controls where to store journal data. One of "volatile", "persistent", "auto" and "none". If "volatile", journal
       log data will be stored only in memory, i.e. below the /run/log/journal hierarchy (which is created if needed).
       If "persistent", data will be stored preferably on disk, i.e. below the /var/log/journal hierarchy (which is
       created if needed), with a fallback to /run/log/journal (which is created if needed), during early boot and if
       the disk is not writable.  "auto" is similar to "persistent" but the directory /var/log/journal is not created if
       needed, so that its existence controls where log data goes.  "none" turns off all storage, all log data received
       will be dropped. Forwarding to other targets, such as the console, the kernel log buffer or a syslog daemon will
       still work however. Defaults to "auto".

Assim, você pode desativar todos os syslogs por meio de Storage = none , mas isso parece excessivo e imprudente. Limitando a taxa (a primeira opção = é muito mais sábia; o padrão é de 1000 mensagens por 30s, o que é muito acima do que você deseja, e explica por que você está tendo tanta saída, desmarcada.

Ou, você pode usar uma dessas opções,

   SystemMaxUse=, SystemKeepFree=, SystemMaxFileSize=, RuntimeMaxUse=, RuntimeKeepFree=, RuntimeMaxFileSize=

para controlar o tamanho dos arquivos de diário armazenados. Você pode emparelhar essas opções com um desses,

MaxFileSec=

      The maximum time to store entries in a single journal file before rotating to the next one

MaxRetentionSec=

      The maximum time to store journal entries.

para reter todas as mensagens do syslog, mas por um tempo menor.

Por fim, você pode querer usar:

MaxLevelStore=, MaxLevelSyslog=, MaxLevelKMsg=, MaxLevelConsole=, MaxLevelWall=

      Controls the maximum log level of messages that are stored on disk, forwarded to syslog, kmsg, the console or
       wall (if that is enabled, see above). As argument, takes one of "emerg", "alert", "crit", "err", "warning",
       "notice", "info", "debug" or integer values in the range of 0..7 (corresponding to the same levels). Messages
       equal or below the log level specified are stored/forwarded, messages above are dropped. Defaults to "debug" for
       MaxLevelStore= and MaxLevelSyslog=, to ensure that the all messages are written to disk and forwarded to syslog.
       Defaults to "notice" for MaxLevelKMsg=, "info" for MaxLevelConsole= and "emerg" for MaxLevelWall=.

para ignorar mensagens menos importantes e reter apenas as críticas.

    
por 08.01.2015 / 19:50

Tags