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

如果在这个时间段中仍然有大量的活动的话,你可以使用这些选项组合来进一步缩小结果数据流:
[root@testvm1 ~]# journalctl --since=2020-05-10 10:54:35 --until=2020-05-10 10:55:00 -t hello.sh-- Logs begin at Tue 2020-05-05 18:11:49 EDT, end at Sun 2020-05-10 11:10:41 EDT. --May 10 10:54:45 testvm1.both.org hello.sh[1380]: ###############################May 10 10:54:45 testvm1.both.org hello.sh[1380]: ######### Hello World! ########May 10 10:54:45 testvm1.both.org hello.sh[1380]: ###############################[root@testvm1 ~]#你的结果应该与我的相似 。你可以从这一系列的实验中看出,这个服务运行的很正常 。
重启 —— 还是走到这一步到目前为止,你还没有重启过安装了服务的机器 。所以现在重启吧,因为毕竟这个教程是关于启动阶段程序运行的情况 。首先,你需要在启动序列中启用这个服务 。
[root@testvm1 ~]# systemctl enable hello.serviceCreated symlink /etc/systemd/system/multi-user.target.wants/hello.service → /etc/systemd/system/hello.service.[root@testvm1 ~]#注意到这个软链接是被创建在 
/etc/systemd/system/multi-user.target.wants
目录下的 。这是因为服务单元文件指定了服务是被multi-user.target所“需要”的 。
重启机器,确保能在启动阶段观察数据流,这样你能看到 “Hello world” 信息 。等等……你看见了么?嗯,我看见了 。尽管它很快被刷过去了,但是我确实看到 systemd 的信息显示它启动了 hello.service服务 。
看看上次系统启动后的日志 。你可以使用页面搜索工具 less来找到 “Hello” 或 “hello” 。我裁剪了很多数据,但是留下了附近的日志记录,这样你就能感受到和你服务有关的日志记录在本地是什么样子的:
[root@testvm1 ~]# journalctl -bMay 10 10:37:49 testvm1.both.org systemd[1]: Listening on SSSD Kerberos Cache Manager responder socket.May 10 10:37:49 testvm1.both.org systemd[1]: Reached target Sockets.May 10 10:37:49 testvm1.both.org systemd[1]: Reached target Basic System.May 10 10:37:49 testvm1.both.org systemd[1]: Starting Modem Manager...May 10 10:37:49 testvm1.both.org systemd[1]: Starting Network Manager...May 10 10:37:49 testvm1.both.org systemd[1]: Starting Avahi mDNS/DNS-SD Stack...May 10 10:37:49 testvm1.both.org systemd[1]: Condition check resulted in Secure Boot DBX (blacklist) updater being skipped.May 10 10:37:49 testvm1.both.org systemd[1]: Starting My hello shell script...May 10 10:37:49 testvm1.both.org systemd[1]: Starting IPv4 firewall with iptables...May 10 10:37:49 testvm1.both.org systemd[1]: Started irqbalance daemon.May 10 10:37:49 testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=irqbalance comm=systemd exe=/usr/lib/sy>'May 10 10:37:49 testvm1.both.org systemd[1]: Starting LSB: Init script for live image....May 10 10:37:49 testvm1.both.org systemd[1]: Starting Hardware Monitoring Sensors...May 10 10:37:49 testvm1.both.org systemd[1]: Starting NTP client/server...May 10 10:37:49 testvm1.both.org systemd[1]: Starting SYSV: Late init script for live image....May 10 10:37:49 testvm1.both.org systemd[1]: Started SYSV: Late init script for live image..May 10 10:37:49 testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=livesys-late comm=systemd exe=/usr/lib/>'May 10 10:37:49 testvm1.both.org hello.sh[842]: ###############################May 10 10:37:49 testvm1.both.org hello.sh[842]: ######### Hello World! ########May 10 10:37:49 testvm1.both.org hello.sh[842]: ###############################May 10 10:37:49 testvm1.both.org systemd[1]: hello.service: Succeeded.May 10 10:37:49 testvm1.both.org systemd[1]: Finished My hello shell script.May 10 10:37:49 testvm1.both.org audit[1]: SERVICE_START pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=hello comm=systemd exe=/usr/lib/systemd>'May 10 10:37:49 testvm1.both.org audit[1]: SERVICE_STOP pid=1 uid=0 auid=4294967295 ses=4294967295 msg='unit=hello comm=systemd exe=/usr/lib/systemd/>May 10 10:37:50 testvm1.both.org audit: BPF prog-id=28 op=LOAD

推荐阅读