domain/architecture/system/deployment/launchd/ops.bend source
domain/architecture/system/deployment/launchd/ops.bend on the hub · documented module
import Baseimport ../../../../../general/markup/type.bend as Mimport ../../../../../general/markup/ops.bend as MOimport ../nix_darwin/type.bend as NDimport ./type.bend as L# A launch agent's property list, written as XML through markup.def key(+k: String) -> M.Node: M.Element{"key", [], [M.Text{k}]}def str(+s: String) -> M.Node: M.Element{"string", [], [M.Text{s}]}def strs(xs: List<&2, String>) -> List<&2, M.Node>: match xs: case []: [] case x <> rest: str(x) <> strs(rest)def vars(vs: List<&2, L.Variable>) -> List<&2, M.Node>: match vs: case []: [] case L.Variable{k, v} <> rest: key(k) <> str(v) <> vars(rest)def path(+home: String, +label: String) -> String: home ++ "/Library/LaunchAgents/" ++ label ++ ".plist"def plist(+home: String, a: L.Agent) -> String: match a: case L.Agent{_, label, program, _, args, env, +log, _}: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ++ "<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n" ++ MO.print([M.Element{"plist", [M.Attribute{"version", "1.0"}], [M.Element{"dict", [], [ key("Label"), str(label), key("ProgramArguments"), M.Element{"array", [], str(program) <> strs(args)}, key("EnvironmentVariables"), M.Element{"dict", [], vars(env)}, key("RunAtLoad"), M.Raw{"<true/>"}, key("KeepAlive"), M.Raw{"<true/>"}, key("StandardOutPath"), str(home ++ "/Library/Logs/" ++ log ++ ".log"), key("StandardErrorPath"), str(home ++ "/Library/Logs/" ++ log ++ ".log")]}]}]) ++ "\n"def label_of(a: L.Agent) -> String: match a: case L.Agent{_, label, _, _, _, _, _, _}: labeldef agents(ld: L.Launchd) -> List<&2, L.Agent>: match ld: case L.Launchd{xs, _}: xsdef serves(ld: L.Launchd) -> List<&2, ND.Serve>: match ld: case L.Launchd{_, xs}: xsdef port_of(a: L.Agent) -> U32: match a: case L.Agent{_, _, _, _, _, _, _, p}: pdef ports(xs: List<&2, L.Agent>) -> List<&2, U32>: match xs: case []: [] case a <> rest: port_of(a) <> ports(rest)def entry_of(a: L.Agent) -> String: match a: case L.Agent{_, _, _, e, _, _, _, _}: e