Stage 3 · Build
Long-Running Daemons & Services
Supervisor Integration
systemd NotifyAccess, Docker healthchecks, PID 1 behavior, and exit code contracts.
PID 1 Behavior
When running as PID 1 in a container, Go processes have special behavior. PID 1 does not have a default signal handler — signals are ignored unless explicitly handled.
Exit Code Contracts
systemd Integration
Docker Healthchecks
# Dockerfile
FROM golang:1.22 AS build
WORKDIR /app
COPY . .
RUN CGO_ENABLED=0 go build -o /app/server ./cmd/server
FROM gcr.io/distroless/static:nonroot
COPY --from=build /app/server /server
EXPOSE 8080
# Healthcheck
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD ["/server", "--healthcheck"]
# Or use wget (distroless doesn't have curl)
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD wget -qO- http://localhost:8080/healthz || exit 1HEALTHCHECK tells Docker how to check container health. interval: time between checks. timeout: max time per check. start-period: grace period for startup. retries: consecutive failures before unhealthy. Distroless images don't have curl — use wget or a built-in healthcheck flag.
Signal Forwarding
Process Replacement
Every container process must handle SIGTERM. Without explicit handling, SIGTERM is ignored and Docker must use SIGKILL after the grace period. This prevents graceful shutdown and causes data loss.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.