# Readiness first, then bounded shutdown

> Documentation for Redweb 0.16.1. Install that exact version when following these examples.

Stop placement to the node, flip readiness, let cooperative handlers observe cancellation, and await deterministic cleanup.

This pattern demonstrates one API area. Application-specific names, credentials, assets, and policies may need to be supplied. Complete starter recipes include all required application files.

```js
import { defineApp, METHODS } from 'redweb'
import { MatchRoute } from './MatchRoute.js'

const app = defineApp({
  sockets: [MatchRoute],
  httpServices: [{
    serviceName: '/ready',
    method: METHODS.GET,
    function: (_request, response) => response.sendStatus(app.sockets?.isReady() ? 200 : 503),
  }],
})
await app.run()

// A deployment controller can invoke this; normal signals use app shutdown.
async function retireNode() {
  app.sockets?.beginDrain()
  await stopExternalPlacement()
  await app.shutdown()
}
```

## Notes and boundaries

- New upgrades receive 503 once draining starts.
- Handlers on routes with drainHandlers: true receive cancellation through socket.context.signal; application work must cooperate.
- A hard deadline terminates non-cooperating peers.
