---
id: w1/m4/t003
title: Implement the wake path (chosen in t002)
worker: worker1
status: done
estimate: 30m
depends_on: [w1/m4/t002]
---

## Objective

Build the production wake-on-request path: the custom Go activator.

## Implementation

`lego/operator/cmd/activator/main.go` — HTTP server on :8888:

1. **Healthz**: `GET /healthz` → 200 (for k8s readiness probe).
2. **Wake handler**: for every other request:
   - Extracts `Host` header, finds the App by matching `status.url` / `status.urls`.
   - Patches `app.Annotations["app.bex.co/last-active"] = now` so `shouldAutoHibernate()` returns false on the next operator reconcile.
   - Patches `deployment.spec.replicas = 1` — this is the Deployment change that triggers the operator reconcile (via `Owns` watch) which switches the Ingress back.
   - Returns 503 with `Retry-After: 5` header; HTML loading page for browsers, JSON for API clients.
3. Built as `/activator` binary inside the shared `lego/Dockerfile` (same image as manager/api, different entrypoint).

The wake loop: activator patches annotation + Deployment → operator reconciles → `shouldAutoHibernate()` false → operator sets normal replicas, switches Ingress to app Service → pod starts → Ingress routes app traffic directly.
