Files
ctrld/internal/router/ntp/ntp.go
T
Cuong Manh Le aec2596262 all: refactor router code to use interface
So the code is more modular, easier to read/maintain.
2023-08-09 23:54:23 +07:00

27 lines
521 B
Go

package ntp
import (
"context"
"errors"
"fmt"
"time"
"github.com/Control-D-Inc/ctrld/internal/router/nvram"
"tailscale.com/logtail/backoff"
)
func Wait() error {
// Wait until `ntp_ready=1` set.
b := backoff.NewBackoff("ntp.Wait", func(format string, args ...any) {}, 10*time.Second)
for {
out, err := nvram.Run("get", "ntp_ready")
if err != nil {
return fmt.Errorf("PreStart: nvram: %w", err)
}
if out == "1" {
return nil
}
b.BackOff(context.Background(), errors.New("ntp not ready"))
}
}