# Daemon Lifecycle

This page explains what `Start`, `Stop`, and `Close` do in server mode and in client mode.

## Lifecycle

| Method | Server mode | Client mode |
|---|---|---|
| `Start()` | Non-blocking. Re-probes, returns `ErrAlreadyRunning` if another daemon answers, removes a stale socket file, listens, and accepts in a goroutine. Calling again while listening is a no-op | No-op |
| `Stop()` | Closes the listener, waits for the accept loop, closes every open connection, waits for connection goroutines | No-op |
| `Close()` | `Stop()` then `Store.Close()`, errors joined | Closes idle pooled connections |
| `Mode()` / `Socket()` | `ModeServer` / socket path | `ModeClient` / socket path |
| `Store()` | The underlying `*store.Store` | `nil` |

A server-mode `Daemon` dispatches calls in-process, so its own methods work even before `Start()`. `Stop()` must close live connections, because pooled client connections would otherwise keep `serve()` blocked in `readFrame` and `Stop()` would never return.

A client does not take over when the server process exits; its calls fail with dial errors until a new `daemon.New` elects a new server.

## Related Pages

- [Mode Resolution](/socket-daemon)
- [Connections](/socket-daemon-connections)
- [daemon](/api-reference-daemon)
