| 241 | } |
| 242 | |
| 243 | func waitForDaemonStop( |
| 244 | ctx context.Context, |
| 245 | deps commandDeps, |
| 246 | runtime *runtimeContext, |
| 247 | info aghdaemon.Info, |
| 248 | ) (DaemonStatus, error) { |
| 249 | waitCtx := ctx |
| 250 | if waitCtx == nil { |
| 251 | waitCtx = context.Background() |
| 252 | } |
| 253 | if _, hasDeadline := waitCtx.Deadline(); !hasDeadline { |
| 254 | var cancel context.CancelFunc |
| 255 | waitCtx, cancel = context.WithTimeout(waitCtx, deps.stopTimeout) |
| 256 | defer cancel() |
| 257 | } |
| 258 | |
| 259 | client, clientErr := clientFromDeps(deps) |
| 260 | ticker := time.NewTicker(deps.pollInterval) |
| 261 | defer ticker.Stop() |
| 262 | |
| 263 | for { |
| 264 | select { |
| 265 | case <-waitCtx.Done(): |
| 266 | return DaemonStatus{}, errors.New("cli: daemon did not stop before timeout") |
| 267 | case <-ticker.C: |
| 268 | if _, running, err := daemonInfo(runtime.HomePaths, deps); err == nil && !running { |
| 269 | return daemonStatusWithState(runtime, info, "stopped"), nil |
| 270 | } |
| 271 | if clientErr == nil { |
| 272 | if _, err := client.DaemonStatus(waitCtx); err != nil { |
| 273 | if _, running, infoErr := daemonInfo(runtime.HomePaths, deps); infoErr == nil && !running { |
| 274 | return daemonStatusWithState(runtime, info, "stopped"), nil |
| 275 | } |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | } |
| 280 | } |
| 281 | |
| 282 | func daemonStatusFromDeps(ctx context.Context, deps commandDeps, runtime *runtimeContext) (DaemonStatus, error) { |
| 283 | client, err := clientFromDeps(deps) |