如何禁用 systemd 服务启动/停止通知

如何禁用 systemd 服务启动/停止通知

我有一个 systemd .timer 每 5 秒运行一次我的 .service 。该服务本身不会向 stout 或 stderr 输出任何内容。然而,当我检查时,journalctl -u <service_name>我看到很多

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

有什么方法可以仅抑制特定服务的输出吗?谢谢。

UPD:更多信息并更改为每 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.

答案1

您可以通过将日志级别降低.service到仅记录关键事件的级别来快速完成此操作。

允许的日志级别是:emerg 、警报、暴击、错误、警告、通知、信息、调试

通过将以下内容添加到您的.service配置文件中

LogLevelMax=alert

然而,您的.service设置.timer似乎非常适得其反,因为它.service本身不应该每 5 秒重新启动一次。.service一旦服务启动,您选择不让脚本本身为您执行重复性任务的任何关键原因是什么?正如您自己发现的那样,当启动/添加/重新加载新系统时,系统会记录并附加很多内容。

相关内容