0. 服务的状态
systemctl status <service name>
1. 需要journel支持
journalctl -xe
2. systemctl --failed systemd启动失败的服务
输出示例:
UNIT LOAD ACTIVE SUB DESCRIPTION
* rc-local.service loaded failed failed /etc/rc.local Compatibility
* rockchip.service loaded failed failed Setup rockchip platform environment
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
2 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
3. systemd-analyze Commands
在systemd作为init的平台,对各项服务就行分析
Commands
1)time, 默认项,打印出耗时的汇总
输出示例:
Startup finished in 7.439s (firmware) + 5.291s (loader) + 2.006s (kernel) + 14.093s (userspace) = 28.831s
graphical.target reached after 14.070s in userspace
2)blame, 火焰方式,就是按照耗时排序,从多到少逐行显示
输出示例:
1min 136ms motd-news.service
10.149s nut-driver.service
7.343s NetworkManager-wait-online.service
2.027s postfix@-.service
1.688s fstrim.service
1.580s uml-utilities.service
1.578s nfs-server.service
1.556s systemd-udev-settle.service
1.354s apt-daily-upgrade.service
1.335s apt-daily.service
1.316s dev-sdb2.device
1.074s man-db.service
995ms libvirtd.service
865ms udisks2.service
706ms accounts-daemon.service
704ms fwupd-refresh.service
619ms php7.4-fpm.service
599ms networkd-dispatcher.service
576ms systemd-logind.service
562ms smartmontools.service
3)critical-chain, 关键链,这里是启动中关键服务的依赖链
输出示例:
The time when unit became active or started is printed after the "@" character.
The time the unit took to start is printed after the "+" character.
graphical.target @14.070s
└─multi-user.target @14.069s
└─nut-monitor.service @14.058s +9ms
└─nut-server.service @14.040s +15ms
└─network.target @3.807s
└─NetworkManager.service @3.372s +426ms
└─dbus.service @3.362s
└─basic.target @3.324s
└─sockets.target @3.324s
└─libvirtd-ro.socket @3.324s
└─libvirtd.socket @3.319s +2ms
└─sysinit.target @3.311s
└─systemd-udev-settle.service @1.754s +1.556s
└─systemd-udev-trigger.service @1.489s +263ms
└─systemd-udevd-kernel.socket @1.439s
└─system.slice @1.424s
└─-.slice @1.424s
4) dump, dump出当前所有的服务的信息,这里是最全的了,内容很多,适合dump到文件里然后分析自己关心的服务的属性信息。
输出示例:
-> Unit factory.service:
Description: factory flash
Instance: n/a
Unit Load State: loaded
Unit Active State: active
State Change Timestamp: Fri 2021-10-08 15:36:49 CST
Inactive Exit Timestamp: Fri 2021-10-08 15:36:49 CST
Active Enter Timestamp: Fri 2021-10-08 15:36:49 CST
Active Exit Timestamp: n/a
Inactive Enter Timestamp: n/a
May GC: no
Need Daemon Reload: no
Transient: no
Perpetual: no
Garbage Collection Mode: inactive
Slice: system.slice
CGroup: /system.slice/factory.service
CGroup realized: yes
CGroup realized mask: memory devices pids
CGroup own mask: memory pids
Name: factory.service
Invocation ID: 3f518a2f57eb4f6f9cd734df0e68c868
Fragment Path: /lib/systemd/system/factory.service
Condition Timestamp: Fri 2021-10-08 15:36:49 CST
Condition Result: yes
Assert Timestamp: Fri 2021-10-08 15:36:49 CST
Assert Result: yes
Requires: sysinit.target (origin-default)
Requires: system.slice (origin-file)
WantedBy: multi-user.target (destination-file)
Conflicts: shutdown.target (origin-default)
Before: multi-user.target (destination-default)
Before: shutdown.target (origin-default)
After: system.slice (origin-file)
After: network.target (origin-file)
After: basic.target (origin-default)
After: sysinit.target (origin-default)
After: systemd-journald.socket (origin-file)
References: system.slice (origin-file)
References: network.target (origin-file)
References: basic.target (origin-default)
References: sysinit.target (origin-default)
References: systemd-journald.socket (origin-file)
References: shutdown.target (origin-default)
ReferencedBy: multi-user.target (destination-file destination-default)
StopWhenUnneeded: no
RefuseManualStart: no
RefuseManualStop: no
DefaultDependencies: yes
OnFailureJobMode: replace
IgnoreOnIsolate: no
Service State: running
Result: success
Reload Result: success
PermissionsStartOnly: no
RootDirectoryStartOnly: no
RemainAfterExit: no
GuessMainPID: yes
Type: simple
Restart: always
NotifyAccess: none
NotifyState: unknown
Main PID: 1435
Main PID Known: yes
Main PID Alien: no
RestartSec: 10s
TimeoutStartSec: 1min 30s
TimeoutStopSec: 1min 30s
RuntimeMaxSec: infinity
WatchdogSec: 0
KillMode: control-group
KillSignal: SIGTERM
FinalKillSignal: SIGKILL
SendSIGKILL: yes
SendSIGHUP: no
UMask: 0022
WorkingDirectory: /
RootDirectory: /
NonBlocking: no
PrivateTmp: no
PrivateDevices: no
ProtectKernelTunables: no
ProtectKernelModules: no
ProtectControlGroups: no
PrivateNetwork: no
PrivateUsers: no
ProtectHome: no
ProtectSystem: no
MountAPIVFS: no
IgnoreSIGPIPE: yes
MemoryDenyWriteExecute: no
RestrictRealtime: no
KeyringMode: private
RuntimeDirectoryPreserve: no
RuntimeDirectoryMode: 0755
StateDirectoryMode: 0755
CacheDirectoryMode: 0755
LogsDirectoryMode: 0755
ConfigurationDirectoryMode: 0755
LimitNOFILE: 524288
LimitNOFILESoft: 1024
LimitMEMLOCK: 65536
LimitMEMLOCKSoft: 65536
StandardInput: null
StandardOutput: journal
StandardError: inherit
SyslogFacility: daemon
SyslogLevel: info
DynamicUser: no
LockPersonality: no
-> ExecStart:
Command Line: /zspace/shell/flasher
PID: 1435
Start Timestamp: Fri 2021-10-08 15:36:49 CST
CPUAccounting=no
IOAccounting=no
BlockIOAccounting=no
MemoryAccounting=yes
TasksAccounting=yes
IPAccounting=no
CPUWeight=18446744073709551615
StartupCPUWeight=18446744073709551615
CPUShares=18446744073709551615
StartupCPUShares=18446744073709551615
CPUQuotaPerSecSec=infinity
IOWeight=18446744073709551615
StartupIOWeight=18446744073709551615
BlockIOWeight=18446744073709551615
StartupBlockIOWeight=18446744073709551615
MemoryMin=0
MemoryLow=0
MemoryHigh=18446744073709551615
MemoryMax=18446744073709551615
MemorySwapMax=18446744073709551615
MemoryLimit=18446744073709551615
TasksMax=2199
DevicePolicy=auto
Delegate=no