package mac import ( "bytes" "encoding/xml" ) // AgentLabel is the launchd user agent's label. const AgentLabel = "io.amadan.equipo-runner" // Exit statuses under launchd. KeepAlive restarts the runner only after // a non-zero exit (SuccessfulExit false): an update exits ExitUpdated so // the new binary starts, a runner that lost its lease to a newer process // exits 0 so the two never take turns, and a crash restarts. const ExitUpdated = 75 // LaunchAgent is ~/Library/LaunchAgents/io.amadan.equipo-runner.plist // (spec ยง3.2): runs at load, kept alive, a Standard process so builds // are not throttled, its environment from envFile (launchd has no // EnvironmentFile), logs under logDir, private files. func LaunchAgent(binary, envFile, logDir string) []byte { var b bytes.Buffer esc := func(s string) string { var e bytes.Buffer _ = xml.EscapeText(&e, []byte(s)) return e.String() } b.WriteString(` Label ` + AgentLabel + ` ProgramArguments ` + esc(binary) + ` run --env-file ` + esc(envFile) + ` RunAtLoad KeepAlive SuccessfulExit ProcessType Standard ThrottleInterval 10 ExitTimeOut 45 Umask 63 StandardOutPath ` + esc(logDir+"/runner.log") + ` StandardErrorPath ` + esc(logDir+"/runner.log") + ` `) return b.Bytes() }