From 689ca3bdadc00015d5aedd81f76fd0950777f1ef Mon Sep 17 00:00:00 2001 From: batsumaru <> Date: Wed, 1 Jul 2026 16:36:55 +0900 Subject: Add ntpd/clock-sync check and a pre-commit hook for exec bits checks/ntpd.sh reports whether ntpd is running and whether the clock's offset is within tolerance (ok <50ms, warn <200ms, down beyond that or if ntpq doesn't respond) - clock drift is a silent failure that otherwise only surfaces later as TLS handshake failures or misleading cross-jail log timestamps. Also add .githooks/pre-commit + core.hooksPath, since this checkout is on Windows where core.fileMode is false (the filesystem doesn't reliably preserve the executable bit) - without it, a plain `git add` on a new check script silently stages it as non-executable, and render.sh skips non-executable files with no visible error. Co-Authored-By: Claude Sonnet 5 --- .githooks/pre-commit | 13 +++++++++++++ statuspage/checks/ntpd.sh | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 .githooks/pre-commit create mode 100755 statuspage/checks/ntpd.sh diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100644 index 0000000..220fc19 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,13 @@ +#!/bin/sh +# .githooks/pre-commit +# This repo is checked out on Windows, which doesn't reliably preserve +# the executable bit (that's why core.fileMode is false - see +# statuspage/README.md). Without this hook, a newly-added *.sh file +# silently stages as non-executable, and render.sh skips non-executable +# files with no error - a broken check script wouldn't even show up as +# a down/warn row, it'd just vanish. +# +# Force +x on every staged *.sh file so that can't happen. +git diff --cached --name-only --diff-filter=ACM -- '*.sh' | while IFS= read -r f; do + git update-index --chmod=+x "$f" +done diff --git a/statuspage/checks/ntpd.sh b/statuspage/checks/ntpd.sh new file mode 100755 index 0000000..1770dc8 --- /dev/null +++ b/statuspage/checks/ntpd.sh @@ -0,0 +1,33 @@ +#!/bin/sh +# checks/ntpd.sh +# ntpd process, plus whether the clock's actual offset is within +# tolerance. A stopped or badly-drifted ntpd is a silent failure that +# only shows up later - in TLS handshake failures, cron firing at the +# wrong time, or cross-jail log timestamps that don't line up. +set -eu + +DIR=$(dirname "$0") +. "$DIR/../lib/common.sh" + +NTPD_STATUS=$(svc_status ntpd) +json_line "host services" "ntpd" "" "$NTPD_STATUS" + +if [ "$NTPD_STATUS" != "ok" ]; then + exit 0 +fi + +RAW=$(ntpq -c "rv 0 offset" 2>/dev/null | sed -n 's/.*offset=\([-0-9.]*\).*/\1/p') + +if [ -z "$RAW" ]; then + json_line "host services" "clock offset" "no response" "warn" + exit 0 +fi + +STATUS=$(awk -v v="$RAW" 'BEGIN { + a = (v < 0) ? -v : v + if (a < 50) print "ok" + else if (a < 200) print "warn" + else print "down" +}') + +json_line "host services" "clock offset" "${RAW} ms" "$STATUS" -- cgit v1.3