使用 systemd 在启动序列期间打印真实的服务名称

使用 systemd 在启动序列期间打印真实的服务名称

我启用了非安静启动,我想知道如何简单地管理启动服务的真实名称,而不是诸如:

[Started] Manage, install and generate color profile

我真的很讨厌当事情对我隐藏时,特别是在 Linux 上,它怎么可能只显示:

[Started] service colord

显然这只是一个示例,我想简单地打印启动的服务名称而不是其描述,而不激活超硬的详细调试信息(如果可能)。

答案1

笔记:这展示了如何调整 systemd 的日志级别并获取有关服务名称的更多详细信息。


要确定 systemd 的日志级别,您可以使用以下命令:

$ systemctl -pLogLevel show
LogLevel=debug

你可以这样改变它:

$ systemd-analyze set-log-level notice

$ systemctl -pLogLevel show
LogLevel=notice

各个级别如下:

   --log-level=
       Set log level. As argument this accepts a numerical log level or the
       well-known syslog(3) symbolic names (lowercase): emerg, alert, crit, 
       err, warning, notice, info, debug.

要使其在重新启动之间永久生效,您可以在 systemd 的配置文件中编辑它:

$ grep LogLevel /etc/systemd/system.conf
#LogLevel=info

或者通过和/etc/default/grub的文件定义来设置它。GRUB_CMDLINE_LINUXGRUB_CMDLINE_LINUX_DEFAULT

GRUB_CMDLINE_LINUX="console=tty1 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300 net.ifnames=0 quiet loglevel=5 rd.systemd.show_status=auto systemd.log_level=debug"
GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 console=ttyS0,115200n8 earlyprintk=ttyS0,115200 rootdelay=300 net.ifnames=0 quiet loglevel=5 rd.systemd.show_status=auto systemd.log_level=debug"

然后重建你的 initramfs:

$ grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.21.1.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.21.1.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-1ec1e304541e429e8876ba9b8942a14a
Found initrd image: /boot/initramfs-0-rescue-1ec1e304541e429e8876ba9b8942a14a.img
done

当级别设置为 时debug,来自 systemd 的消息如下所示:

$ journalctl -b | less
Jul 13 12:06:44 centos7 systemd[1]: Activating default unit: default.target
Jul 13 12:06:44 centos7 systemd[1]: Trying to enqueue job initrd.target/start/isolate
Jul 13 12:06:44 centos7 systemd[1]: Installed new job local-fs.target/start as 20
Jul 13 12:06:44 centos7 systemd[1]: Installed new job systemd-udev-trigger.service/start as 18
Jul 13 12:06:44 centos7 systemd[1]: Installed new job systemd-udevd-control.socket/start as 8
Jul 13 12:06:44 centos7 systemd[1]: Installed new job remote-fs.target/start as 38
Jul 13 12:06:44 centos7 systemd[1]: Installed new job sysroot.mount/start as 31
Jul 13 12:06:44 centos7 systemd[1]: Installed new job swap.target/start as 17
Jul 13 12:06:44 centos7 systemd[1]: Installed new job kmod-static-nodes.service/start as 21
Jul 13 12:06:44 centos7 systemd[1]: Installed new job slices.target/start as 26
Jul 13 12:06:44 centos7 systemd[1]: Installed new job systemd-journald.service/start as 9
Jul 13 12:06:44 centos7 systemd[1]: Installed new job initrd-root-fs.target/start as 30
Jul 13 12:06:44 centos7 systemd[1]: Installed new job systemd-tmpfiles-setup-dev.service/start as 19
Jul 13 12:06:44 centos7 systemd[1]: Installed new job paths.target/start as 27
Jul 13 12:06:44 centos7 systemd[1]: Installed new job initrd.target/start as 1
Jul 13 12:06:44 centos7 systemd[1]: Installed new job initrd-fs.target/start as 42
...
...
Jul 13 12:06:44 centos7 systemd[1]: dracut-pre-udev.service: cgroup is empty
Jul 13 12:06:44 centos7 systemd[1]: ConditionPathIsReadWrite=/sys succeeded for systemd-udevd.service.
Jul 13 12:06:44 centos7 systemd[1]: About to execute: /usr/lib/systemd/systemd-udevd
Jul 13 12:06:44 centos7 systemd[1]: Forked /usr/lib/systemd/systemd-udevd as 226
Jul 13 12:06:44 centos7 systemd[1]: systemd-udevd.service changed dead -> start
Jul 13 12:06:44 centos7 systemd[1]: Starting udev Kernel Device Manager...
Jul 13 12:06:44 centos7 systemd[1]: Got cgroup empty notification for: /system.slice/dracut-pre-udev.service
Jul 13 12:06:44 centos7 systemd[1]: dracut-pre-udev.service: cgroup is empty
Jul 13 12:06:44 centos7 systemd[226]: Executing: /usr/lib/systemd/systemd-udevd
Jul 13 12:06:44 centos7 systemd-udevd[226]: ctrl=4 netlink=3

您可以在上面的输出中清楚地看到服务的名称,例如。systemd-journald.service

参考

相关内容