fix: 优化 chrony 时间源检查逻辑以正确识别同步状态

This commit is contained in:
seahi committed 2026-10-09 15:13:51 +08:00
1 parent 756b8f6004
commit a3a01fc80f
1 file changed
+5 -2
+5 -2
View File
@@ -252,8 +252,11 @@ chrony_synced() {
local sources local sources
sources=$(timeout 10 chronyc -n sources) || return 1 sources=$(timeout 10 chronyc -n sources) || return 1
printf '%s\n' "$sources" | awk -v ip="$CONTROLLER_IP" ' printf '%s\n' "$sources" | awk -v ip="$CONTROLLER_IP" '
$1=="^*" && $2==ip {found=1} # 时间源标记只有两个字符(如 ^*、^?、=+);排除表头的等号分隔线。
$1 ~ /^[\^=]/ && $2!=ip {bad=1} length($1)==2 && (substr($1,1,1)=="^" || substr($1,1,1)=="=") {
if($1=="^*" && $2==ip) found=1
if($2!=ip) bad=1
}
END{exit !(found && !bad)}' END{exit !(found && !bad)}'
} }
check 2 'chrony 已安装' 'chrony 未安装(第1步:安装软件)' rpm -q chrony check 2 'chrony 已安装' 'chrony 未安装(第1步:安装软件)' rpm -q chrony