#include "kappa/service/service.hpp" #include #include namespace kappa::service { std::string generate_s6_service(const ServiceSpec& spec) { std::ostringstream out; // --- type file content --- std::string type_content; if (spec.type == "oneshot") { type_content = "oneshot"; } else { // "longrun", "notify", and anything else map to longrun in s6 type_content = "longrun"; } // --- run file content --- std::ostringstream run; run << s6_execline_shebang; run << "# Generated by kappa — do not edit manually\n"; run << std::format("# s6 service: {}\n", spec.name); if (!spec.working_dir.empty()) { run << std::format("cd {}\n", spec.working_dir); } for (const auto& [key, value] : spec.env) { run << std::format("export {} \"{}\"\n", key, value); } if (!spec.user.empty()) { run << std::format("s6-setuidgid {}\n", spec.user); } run << spec.exec << "\n"; // --- combined output --- out << std::format("# --- s6 service directory: {} ---\n", spec.name); out << "# file: type\n"; out << type_content << "\n"; out << "# file: run\n"; out << run.str(); return out.str(); } } // namespace kappa::service