systemd调试工具

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

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,711评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,932评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,770评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,799评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,697评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,069评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,535评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,200评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,353评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,290评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,331评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,020评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,610评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,694评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,927评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,330评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,904评论 2 341

推荐阅读更多精彩内容