all: cleaning up router before waiting ntp synchronization

On some Merlin routers reported by users, ctrld some how is not stopped
properly. So the router does not have a working DNS at boot time to do
ntp synchronization.

To fix it, just clean up the router before start waiting for ntp ready.
This commit is contained in:
Cuong Manh Le
2023-06-27 09:19:05 +07:00
committed by Cuong Manh Le
parent f3a3227f21
commit 1aa991298a
2 changed files with 6 additions and 3 deletions

View File

@@ -168,7 +168,7 @@ func initCLI() {
// Processing --cd flag require connecting to ControlD API, which needs valid
// time for validating server certificate. Some routers need NTP synchronization
// to set the current time, so this check must happen before processCDFlags.
if err := router.PreRun(); err != nil {
if err := router.PreRun(svcConfig); err != nil {
mainLog.Fatal().Err(err).Msg("failed to perform router pre-run check")
}

View File

@@ -127,10 +127,13 @@ func ConfigureService(sc *service.Config) error {
}
// PreRun blocks until the router is ready for running ctrld.
func PreRun() (err error) {
func PreRun(svc *service.Config) (err error) {
// On some routers, NTP may out of sync, so waiting for it to be ready.
switch Name() {
case Merlin, Tomato:
case DDWrt, Merlin, Tomato:
// Cleanup router to ensure valid DNS for NTP synchronization.
_ = Cleanup(svc)
// Wait until `ntp_ready=1` set.
b := backoff.NewBackoff("PreRun", func(format string, args ...any) {}, 10*time.Second)
for {