Documentation
¶
Overview ¶
Package timesync reads a host's clock-synchronization status through an injected exec.Runner.
r, _ := exec.NewRunner(exec.Direct)
m, err := timesync.New(timesync.Chrony, r)
if err != nil { ... }
st, _ := m.Status(ctx)
fmt.Println(st.Synchronized, st.Source, st.OffsetSeconds)
Two backends are implemented: Timedatectl (systemd; reports synchronized + service-enabled) and Chrony (chronyc; reports synchronized + reference source + estimated offset). Reads are unprivileged. Detect lists the tools on PATH; the consumer picks one and passes it to New (no auto-detection, no globals).
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrUnknownBackend = errors.New("timesync: unknown backend")
ErrUnknownBackend is returned by New for the zero value or any unimplemented backend.
Functions ¶
This section is empty.
Types ¶
type Backend ¶
type Backend int
Backend selects the time-sync daemon to query. The zero value is invalid; only implemented backends exist (ntpd/openntpd are intentionally absent).
func Detect ¶
Detect reports the time-sync backends usable on THIS host: Timedatectl when timedatectl is on PATH, Chrony when chronyc is. It lists; it never picks. The consumer reads the list, picks one, and passes it to New.
The ctx is accepted for signature uniformity; the probe is a pure PATH lookup.
type Manager ¶
type Manager interface {
// Status reads the current synchronization state.
Status(ctx context.Context) (Status, error)
}
Manager is the time-sync read surface.
func New ¶
New returns a Manager for the named backend, driven by runner. Pure: validates the backend; does not probe (use Detect). Nil runner and unknown backend are rejected.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/manchtools/cadestro/sdk/sys/exec"
"github.com/manchtools/cadestro/sdk/sys/timesync"
)
func main() {
r, err := exec.NewRunner(exec.Direct)
if err != nil {
log.Fatal(err)
}
m, err := timesync.New(timesync.Chrony, r)
if err != nil {
log.Fatal(err)
}
st, err := m.Status(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("synchronized=%v source=%s offset=%.6fs\n", st.Synchronized, st.Source, st.OffsetSeconds)
}
Output:
type Status ¶
type Status struct {
Synchronized bool // the clock is currently disciplined to a source
Enabled bool // a time-sync service is enabled/running
Source string // reference source (server name/IP)
OffsetSeconds float64 // estimated offset from true time (signed)
}
Status is a snapshot of the host clock's synchronization state. Fields a backend cannot report are left at their zero value (Timedatectl does not expose source/offset; both are populated by Chrony).