WaitForManager waits for the sysbox-mgr to startup.
(ctx context.Context)
| 14 | |
| 15 | // WaitForManager waits for the sysbox-mgr to startup. |
| 16 | func WaitForManager(ctx context.Context) error { |
| 17 | fs := xunix.GetFS(ctx) |
| 18 | |
| 19 | _, err := fs.Stat(ManagerSocketPath) |
| 20 | if err == nil { |
| 21 | return nil |
| 22 | } |
| 23 | |
| 24 | const ( |
| 25 | period = time.Second |
| 26 | ) |
| 27 | |
| 28 | t := time.NewTicker(period) |
| 29 | defer t.Stop() |
| 30 | |
| 31 | for { |
| 32 | select { |
| 33 | case <-ctx.Done(): |
| 34 | return ctx.Err() |
| 35 | case <-t.C: |
| 36 | _, err := fs.Stat(ManagerSocketPath) |
| 37 | if err != nil { |
| 38 | if !xerrors.Is(err, os.ErrNotExist) { |
| 39 | return xerrors.Errorf("unexpected stat err %s: %w", ManagerSocketPath, err) |
| 40 | } |
| 41 | continue |
| 42 | } |
| 43 | return nil |
| 44 | } |
| 45 | } |
| 46 | } |