mirror of
https://github.com/Control-D-Inc/ctrld.git
synced 2026-05-15 00:50:25 +02:00
aec2596262
So the code is more modular, easier to read/maintain.
27 lines
521 B
Go
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"))
|
|
}
|
|
}
|