systemctl try-restart 和 systemct
2023-03-22 本文已影响0人
苍蝇的梦
2022-11-08 遇到的一点小问题
最近做某个功能查文档,刚好看到systemctl 中文手册和journalctl 中文手册,记录两个个之前没用到的功能。
systemctl try-restart systemd-timesyncd
有启动才重启,否则不重启。和restart
不一样。
之前都是systemctl status systemd-timesyncd > /dev/null 2>&1;echo $?
,判断0 -eq $?``restart
才重启。

systemctl cat systemd-timesyncd
直接查看服务文件
之前都是systemctl status systemd-timesyncd
,从信息里获取路径,再cat读取cat /usr/lib/systemd/system/systemd-timesyncd.service
。

.
systemctl daemon-reload
测试的时候经常会修改服务文件,修改完要执行systemctl daemon-reload
再restart
。经常忘了怎么拼,顺便记录一下。

echo "$(systemctl status systemd-timesyncd)"
之前的固件,在控制台执行命令systemctl status systemd-timesyncd
,能看到的信息比较多:

最新的固件,只能看到一点点信息:

不过还好使用echo能看到比较多的信息,输出信息里有中文,使用这个也能正常在控制台显示。
[root@wannoo ~]# echo "$(systemctl status systemd-timesyncd)"
* systemd-timesyncd.service - Network Time Synchronization
Loaded: loaded (/usr/lib/systemd/system/systemd-timesyncd.service; disabled; preset: enabled)
Active: active (running) since Thu 2023-03-23 03:14:18 UTC; 35min ago
Docs: man:systemd-timesyncd.service(8)
Main PID: 1028477 (systemd-timesyn)
Status: "Contacted time server 185.209.85.222:123 (pool.ntp.org)."
Tasks: 2 (limit: 4563)
Memory: 1.0M
CGroup: /system.slice/systemd-timesyncd.service
`-1028477 /usr/lib/systemd/systemd-timesyncd
Mar 23 03:14:18 wannoo systemd[1]: Starting Network Time Synchronization...
Mar 23 03:14:18 wannoo systemd[1]: Started Network Time Synchronization.
Mar 23 03:14:18 wannoo systemd-timesyncd[1028477]: Contacted time server 185.209.85.222:123 (pool.ntp.org).
Mar 23 03:14:18 wannoo systemd-timesyncd[1028477]: Initial clock synchronization to Thu 2023-03-23 03:14:18.801809 UTC.
[root@wannoo ~]#