package main import ( "net" "os" "strings" ) // NotifyReady tells systemd this process is ready to serve, for a unit // declared Type=notify. // // It exists so that "the process was exec'd" and "the process is serving" // stop being the same fact to systemd. With Type=simple, `systemctl restart` // succeeds the instant the binary is exec'd — so a console that starts and // then dies on its first request, or half-applies a migration, restarts // SUCCESSFULLY as far as the adopt pass can tell, and the pass then stamps a // version nothing is really running. Signalled after the listener is open, // a broken build fails its restart instead, and adoption's existing rollback // takes over. // // No dependency: the protocol is one datagram on the socket systemd names in // NOTIFY_SOCKET. An unset variable means "not under systemd" — a laptop, a // test, `go run` — and is not an error. // // An "@" prefix denotes a Linux abstract socket, which net.Dial expects as a // leading NUL. // // This is the code half only: it is INERT until console.service is declared // Type=notify, a pinfra change outside this repo — see the runbook in // .superpowers/sdd/2026-08-23-console-as-an-app/. func NotifyReady() error { sock := os.Getenv("NOTIFY_SOCKET") if sock == "" { return nil } if strings.HasPrefix(sock, "@") { sock = "\x00" + sock[1:] } conn, err := net.Dial("unixgram", sock) if err != nil { return err } defer conn.Close() _, err = conn.Write([]byte("READY=1")) return err }