使用 systemd 来管理启动项 启动序列( 七 )

还有部分 graphical.target的日志:
[   19.436815] testvm1.both.org systemd[1]: Starting My hello shell script...[   19.437070] testvm1.both.org systemd[1]: Starting IPv4 firewall with iptables...[   19.612614] testvm1.both.org hello.sh[841]: ###############################[   19.612614] testvm1.both.org hello.sh[841]: ######### Hello World! ########[   19.612614] testvm1.both.org hello.sh[841]: ###############################[   19.629455] testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=hello comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'[   19.629569] testvm1.both.org audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=hello comm=systemd exe=/usr/lib/systemd/systemd hostname=? addr=? terminal=? res=success'[   19.629682] testvm1.both.org systemd[1]: hello.service: Succeeded.[   19.629782] testvm1.both.org systemd[1]: Finished My hello shell script.尽管单元文件的 WantedBy部分包含了graphical.targethello.service单元在启动后大约 19.5 或 19.6 秒后运行 。但是hello.servicemulti-user.target中开始于 17.24 秒,在graphical target中开始于 19.43 秒 。
这意味着什么呢?看看 
/etc/systemd/system/default.target
这个链接 。文件内容显示 systemd 先启动了默认目标graphical.target,然后graphical.target触发了multi-user.target
[root@testvm1 system]# cat default.target#  SPDX-License-Identifier: LGPL-2.1+##  This file is part of systemd.##  systemd is free software; you can redistribute it and/or modify it#  under the terms of the GNU Lesser General Public License as published by#  the Free Software Foundation; either version 2.1 of the License, or#  (at your option) any later version.[Unit]Description=Graphical InterfaceDocumentation=man:systemd.special(7)Requires=multi-user.targetWants=display-manager.serviceConflicts=rescue.service rescue.targetAfter=multi-user.target rescue.service rescue.target display-manager.serviceAllowIsolate=yes[root@testvm1 system]#不管是用 graphical.target还是multi-user.target启动服务,hello.service单元都在启动后的 19.5 或 19.6 秒后启动 。基于这个事实和日志结果(特别是使用单调输出的日志),你就知道这些目标是在并行启动 。再看看日志中另外一件事:
[   28.397330] testvm1.both.org systemd[1]: Reached target Multi-User System.[   28.397431] testvm1.both.org systemd[1]: Reached target Graphical Interface.两个目标几乎是同时完成的 。这是和理论一致的,因为 graphical.target触发了multi-user.target,在multi-user.target到达(即完成)之前它是不会完成的 。但是hello.service比这个完成的早的多 。
这一切表明,这两个目标几乎是并行启动的 。如果你查看日志,你会发现各种目标和来自这类主要目标的服务大多是平行启动的 。很明显,

推荐阅读