// echoapp is the e2e/vet test tenant: a minimal app honoring the platform // contract — it accepts -socket (unix) or -addr (TCP), or inherits a // systemd-activated listener (LISTEN_FDS, the carlos-app@.socket contract), // answers GET /healthz with "ok", and echoes its BUILD env everywhere else. // // It also accepts -db and ignores it. The two backends spawn a tenant // DIFFERENTLY: carlos-app@.service runs `live/ serve` with no flags // (the listener arrives as LISTEN_FDS), while the activator's ExecBackend // runs `live/ --socket --db ` (backend_exec.go). An app that // declares only -socket/-addr therefore works unit-backed and dies instantly // exec-backed — Go's flag package rejects the unknown --db, prints usage and // exits before binding anything, so the activator waits out its 30s health // timeout on a socket that will never appear and the edge serves "instance // is waking; retry shortly" forever. // // That is exactly what happened on a live deployment: an instance // provisioned through `carlos instances create` could not boot, because this // tenant — the one the e2e suite treats as the reference app — only ever met // the unit-backed half of the contract it claims to honour. echoapp keeps no // state, so the flag is accepted and discarded; the point is to be spawnable // by BOTH backends. package main import ( "flag" "fmt" "net" "net/http" "os" "strconv" ) func main() { socket := flag.String("socket", "", "unix socket to listen on") addr := flag.String("addr", "", "TCP host:port to listen on") // Accepted and ignored: the activator always passes it (every route the // provisioning pass mints carries a DBPath), and a tenant that cannot // PARSE it never reaches its listener. echoapp keeps no state. _ = flag.String("db", "", "instance database path (accepted, unused: echoapp is stateless)") flag.Parse() mux := http.NewServeMux() mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) { fmt.Fprint(w, "ok") }) mux.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) { fmt.Fprintf(w, "echoapp BUILD=%s", os.Getenv("BUILD")) }) ln, err := listen(*socket, *addr) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } if err := http.Serve(ln, mux); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } // listen picks the app's listener, activation first: when systemd (or a test // playing systemd) passed a pre-bound socket — LISTEN_FDS=1, the fd at 3 — // serve on it and never touch any path. That is the carlos-app@.socket // contract: the file is root-bound and carlos-owned so only the edge can // connect; the tenant just inherits the fd. Otherwise bind -socket (unix) // or -addr (TCP) ourselves. func listen(socket, addr string) (net.Listener, error) { if n, _ := strconv.Atoi(os.Getenv("LISTEN_FDS")); n >= 1 { // systemd sets LISTEN_PID to our pid post-fork; accept it unset for // harnesses that exec us directly and can't know the pid in advance. if pid := os.Getenv("LISTEN_PID"); pid == "" || pid == strconv.Itoa(os.Getpid()) { return net.FileListener(os.NewFile(3, "listen-fd")) } } network, address := "tcp", addr if socket != "" { network, address = "unix", socket os.Remove(socket) } return net.Listen(network, address) }