This repository was archived by the owner on Jan 30, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +14
-18
lines changed Expand file tree Collapse file tree 1 file changed +14
-18
lines changed Original file line number Diff line number Diff line change @@ -1104,25 +1104,21 @@ func tryWaitForSystemdActiveState(units []string) (ret int) {
11041104// active, retrying periodically until the unit gets active. It will retry
11051105// up to maxAttempts.
11061106func waitForSystemdActiveState (conn * sd_dbus.Conn , unitName string ) (found bool , err error ) {
1107- found = false
1108- var errAssert error
1109- sleep := defaultSleepTime
1110- maxAttempts := 3
1111- for attempt := 0 ; attempt < maxAttempts ; attempt ++ {
1112- found , errAssert = assertSystemdActiveState (conn , unitName )
1113- if found && errAssert == nil {
1114- break
1107+ return func () (found bool , errWait error ) {
1108+ timeout := 15 * time .Second
1109+ alarm := time .After (timeout )
1110+ ticker := time .Tick (250 * time .Millisecond )
1111+ for {
1112+ select {
1113+ case <- alarm :
1114+ return false , fmt .Errorf ("Failed to reach expected state within %v." , timeout )
1115+ case <- ticker :
1116+ if found , errA := assertSystemdActiveState (conn , unitName ); found && errA == nil {
1117+ return found , nil
1118+ }
1119+ }
11151120 }
1116- time .Sleep (sleep )
1117- }
1118-
1119- if found {
1120- err = nil
1121- } else {
1122- err = fmt .Errorf ("%v" , errAssert )
1123- }
1124-
1125- return found , err
1121+ }()
11261122}
11271123
11281124// assertSystemdActiveState determines if a given systemd unit is actually
You can’t perform that action at this time.
0 commit comments