0

I have a systemd .timer which runs my .service every 5 seconds. The service itself doesn't output anything to stout or stderr. However, when I check journalctl -u <service_name> I see lots of

systemd[1]: Started ...
systemd[1]: <sevice_name>: Succeeded.

Any way to suppress that output for a particular service only? Thanks.

UPD: more info and changed to every 5m

# cat munin-cron.timer

[Unit]
Description=Survey monitored computers every five minutes

[Timer]
OnCalendar=*-*-* *:00/5:00

[Install]
WantedBy=multi-user.target

# cat munin-cron.service

[Unit]
Description=Survey monitored computers
After=network.target

[Service]
Type=exec
User=munin
LogLevelMax=alert
SyslogLevel=2
ExecStart=/usr/bin/munin-cron

# systemctl show munin-cron.service

Type=exec
Restart=no
NotifyAccess=none
RestartUSec=100ms
TimeoutStartUSec=1min 30s
TimeoutStopUSec=1min 30s
TimeoutAbortUSec=1min 30s
RuntimeMaxUSec=infinity
WatchdogUSec=0
WatchdogTimestampMonotonic=0
RootDirectoryStartOnly=no
RemainAfterExit=no
GuessMainPID=yes
MainPID=0
ControlPID=0
FileDescriptorStoreMax=0
NFileDescriptorStore=0
StatusErrno=0
Result=success
ReloadResult=success
CleanResult=success
UID=[not set]
GID=[not set]
NRestarts=0
OOMPolicy=stop
ExecMainStartTimestamp=Mon 2019-10-21 06:30:00 CEST
ExecMainStartTimestampMonotonic=193534630899
ExecMainExitTimestamp=Mon 2019-10-21 06:30:12 CEST
ExecMainExitTimestampMonotonic=193546001811
ExecMainPID=68208
ExecMainCode=1
ExecMainStatus=0
ExecStart={ path=/usr/bin/munin-cron ; argv[]=/usr/bin/munin-cron ; ignore_errors=no ; start_time=[Mon 2019-10-21 06:30:00 CEST] ; stop_time=[Mon 2019-10-21 06:30:12 CEST] ; pid=68208 ; code=exited ; status=0 }
ExecStartEx={ path=/usr/bin/munin-cron ; argv[]=/usr/bin/munin-cron ; flags= ; start_time=[Mon 2019-10-21 06:30:00 CEST] ; stop_time=[Mon 2019-10-21 06:30:12 CEST] ; pid=68208 ; code=exited ; status=0 }
Slice=system.slice
MemoryCurrent=[not set]
CPUUsageNSec=[not set]
TasksCurrent=[not set]
IPIngressBytes=[no data]
IPIngressPackets=[no data]
IPEgressBytes=[no data]
IPEgressPackets=[no data]
IOReadBytes=18446744073709551615
IOReadOperations=18446744073709551615
IOWriteBytes=18446744073709551615
IOWriteOperations=18446744073709551615
Delegate=no
CPUAccounting=no
CPUWeight=[not set]
StartupCPUWeight=[not set]
CPUShares=[not set]
StartupCPUShares=[not set]
CPUQuotaPerSecUSec=infinity
CPUQuotaPeriodUSec=infinity
IOAccounting=no
IOWeight=[not set]
StartupIOWeight=[not set]
BlockIOAccounting=no
BlockIOWeight=[not set]
StartupBlockIOWeight=[not set]
MemoryAccounting=yes
DefaultMemoryLow=0
DefaultMemoryMin=0
MemoryMin=0
MemoryLow=0
MemoryHigh=infinity
MemoryMax=infinity
MemorySwapMax=infinity
MemoryLimit=infinity
DevicePolicy=auto
TasksAccounting=yes
TasksMax=infinity
IPAccounting=no
UMask=0022
LimitCPU=infinity
LimitCPUSoft=infinity
LimitFSIZE=infinity
LimitFSIZESoft=infinity
LimitDATA=infinity
LimitDATASoft=infinity
LimitSTACK=infinity
LimitSTACKSoft=8388608
LimitCORE=infinity
LimitCORESoft=infinity
LimitRSS=infinity
LimitRSSSoft=infinity
LimitNOFILE=524288
LimitNOFILESoft=1024
LimitAS=infinity
LimitASSoft=infinity
LimitNPROC=1857
LimitNPROCSoft=1857
LimitMEMLOCK=65536
LimitMEMLOCKSoft=65536
LimitLOCKS=infinity
LimitLOCKSSoft=infinity
LimitSIGPENDING=1857
LimitSIGPENDINGSoft=1857
LimitMSGQUEUE=819200
LimitMSGQUEUESoft=819200
LimitNICE=0
LimitNICESoft=0
LimitRTPRIO=0
LimitRTPRIOSoft=0
LimitRTTIME=infinity
LimitRTTIMESoft=infinity
OOMScoreAdjust=0
Nice=0
IOSchedulingClass=0
IOSchedulingPriority=0
CPUSchedulingPolicy=0
CPUSchedulingPriority=0
CPUAffinity=
NUMAPolicy=n/a
NUMAMask=
TimerSlackNSec=50000
CPUSchedulingResetOnFork=no
NonBlocking=no
StandardInput=null
StandardInputData=
StandardOutput=journal
StandardError=inherit
TTYReset=no
TTYVHangup=no
TTYVTDisallocate=no
SyslogPriority=26
SyslogLevelPrefix=yes
SyslogLevel=2
SyslogFacility=3
LogLevelMax=1
LogRateLimitIntervalUSec=0
LogRateLimitBurst=0
SecureBits=0
CapabilityBoundingSet=cap_chown cap_dac_override cap_dac_read_search cap_fowner cap_fsetid cap_kill cap_setgid cap_setuid cap_setpcap cap_linux_immutable cap_net_bind_service cap_net_broadcast cap_net_admin cap_net_raw cap_ipc_lock cap_ipc_owner cap_sys_module cap_sys_rawio cap_sys_chroot cap_sys_ptrace cap_sys_pacct cap_sys_admin cap_sys_boot cap_sys_nice cap_sys_resource cap_sys_time cap_sys_tty_config cap_mknod cap_lease cap_audit_write cap_audit_control cap_setfcap cap_mac_override cap_mac_admin cap_syslog cap_wake_alarm cap_block_suspend cap_audit_read
AmbientCapabilities=
User=munin
DynamicUser=no
RemoveIPC=no
MountFlags=
PrivateTmp=no
PrivateDevices=no
ProtectKernelTunables=no
ProtectKernelModules=no
ProtectControlGroups=no
PrivateNetwork=no
PrivateUsers=no
PrivateMounts=no
ProtectHome=no
ProtectSystem=no
SameProcessGroup=no
UtmpMode=init
IgnoreSIGPIPE=yes
NoNewPrivileges=no
SystemCallErrorNumber=0
LockPersonality=no
RuntimeDirectoryPreserve=no
RuntimeDirectoryMode=0755
StateDirectoryMode=0755
CacheDirectoryMode=0755
LogsDirectoryMode=0755
ConfigurationDirectoryMode=0755
TimeoutCleanUSec=infinity
MemoryDenyWriteExecute=no
RestrictRealtime=no
RestrictSUIDSGID=no
RestrictNamespaces=no
MountAPIVFS=no
KeyringMode=private
ProtectHostname=no
KillMode=control-group
KillSignal=15
FinalKillSignal=9
SendSIGKILL=yes
SendSIGHUP=no
WatchdogSignal=6
Id=munin-cron.service
Names=munin-cron.service
Requires=sysinit.target system.slice
Conflicts=shutdown.target
Before=shutdown.target
After=sysinit.target network.target munin-cron.timer systemd-journald.socket basic.target system.slice
TriggeredBy=munin-cron.timer
Description=Survey monitored computers
LoadState=loaded
ActiveState=inactive
SubState=dead
FragmentPath=/etc/systemd/system/munin-cron.service
UnitFileState=static
UnitFilePreset=disabled
StateChangeTimestamp=Mon 2019-10-21 06:30:12 CEST
StateChangeTimestampMonotonic=193546002012
InactiveExitTimestamp=Mon 2019-10-21 06:30:00 CEST
InactiveExitTimestampMonotonic=193534631573
ActiveEnterTimestamp=Mon 2019-10-21 06:30:00 CEST
ActiveEnterTimestampMonotonic=193534639294
ActiveExitTimestamp=Mon 2019-10-21 06:30:12 CEST
ActiveExitTimestampMonotonic=193546002012
InactiveEnterTimestamp=Mon 2019-10-21 06:30:12 CEST
InactiveEnterTimestampMonotonic=193546002012
CanStart=yes
CanStop=yes
CanReload=no
CanIsolate=no
StopWhenUnneeded=no
RefuseManualStart=no
RefuseManualStop=no
AllowIsolate=no
DefaultDependencies=yes
OnFailureJobMode=replace
IgnoreOnIsolate=no
NeedDaemonReload=no
JobTimeoutUSec=infinity
JobRunningTimeoutUSec=infinity
JobTimeoutAction=none
ConditionResult=yes
AssertResult=yes
ConditionTimestamp=Mon 2019-10-21 06:30:00 CEST
ConditionTimestampMonotonic=193534628264
AssertTimestamp=Mon 2019-10-21 06:30:00 CEST
AssertTimestampMonotonic=193534628265
Transient=no
Perpetual=no
StartLimitIntervalUSec=10s
StartLimitBurst=5
StartLimitAction=none
FailureAction=none
SuccessAction=none
InvocationID=f16620fc799644929a09903ef54e1415
CollectMode=inactive

# journalctl -u munin-cron.service

Oct 21 06:25:00 hostname systemd[1]: Starting Survey monitored computers...
Oct 21 06:25:00 hostname systemd[1]: Started Survey monitored computers.
Oct 21 06:25:11 hostname systemd[1]: munin-cron.service: Succeeded.
Oct 21 06:30:00 hostname systemd[1]: Starting Survey monitored computers...
Oct 21 06:30:00 hostname systemd[1]: Started Survey monitored computers.
Oct 21 06:30:12 hostname systemd[1]: munin-cron.service: Succeeded.
Oct 21 06:35:00 hostname systemd[1]: Starting Survey monitored computers...
Oct 21 06:35:00 hostname systemd[1]: Started Survey monitored computers.
Oct 21 06:35:11 hostname systemd[1]: munin-cron.service: Succeeded.
0

You can quickly do this by dropping the log level of your .service to one that only records crucial events.

Allowed log levels are: emerg , alert, crit, err, warning, notice, info, debug

by adding the following to your .service configuration file

LogLevelMax=alert

However, your .service and .timer setup seems very counterproductive as the .service itself should not be getting restarted every 5 seconds. Any critical reason why you chose not to have the script in the .service itself to be doing that repetetive task for you, once the service is started? As you have discovered yourself, there are a lot of things a system records and appends when a new system is started/added/reloaded.

  • Thanks, but LogLevelMax=, StandardOutput=null, StandardError=null directives don't work as they control the output of the service itself (script in my case) which doesn't produce any. Started/Stopped messages are generated by systemd itself. Most likely will loop the script as I don't think it's possible to shut systemd's notifications for a particular service. – systemdlover Oct 21 at 3:35
  • if .service has Type=notify try switching it to exec and lower SyslogLevel directive to =2. Systemd reads the corresponding configuration for each service, and only overrules if they get set to some that are fundamentally unallowed. You can check your .service config with systemctl show [NAME].service . You will see a huge list of descriptors, and remeber that if you change your .service file you will need to execute systemctl daemon-reload . Having Type=exec and LogLevelMax=alert for StandardOutput=journal and SyslogLevel=2 for StandardOutput=syslog will work. – BarBar1234 Oct 21 at 3:49
  • I don't think it tries to overrule anything, it's just how it works. systemd[1]: Starting [service description goes here] systemd[1]: Started [service description goes here] systemd[1]: my_beautiful.service: Succeeded. Added some more info to the question. – systemdlover Oct 21 at 4:56
  • Also, found the exact problem here: unix.stackexchange.com/questions/178193/… Infinite loop and sleep() seems like the only option for me. – systemdlover Oct 21 at 5:12
  • yeah, sorry I actually realized that you wanted to get rid of the systemd parts of logs after your comment. That one is tough. The only thing I could achieve was changing the MaxLevelStore=notice MaxLevelSyslog=notice MaxLevelKMsg=err MaxLevelConsole=err MaxLevelWall=emerg in /etc/systemd/journald.conf . I tried setting up unit confs in /etc/systemd/journald.conf.d/* per the manual, but could not accomplish it on a unit basis. The only other solution was attacking it from /etc/rsyslog.d/* and am slowly making progress but systemd seems to still catch the $SERVICE_RESULT. – BarBar1234 Oct 21 at 7:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.