diff options
Diffstat (limited to 'src/zenutil/service.cpp')
| -rw-r--r-- | src/zenutil/service.cpp | 54 |
1 files changed, 22 insertions, 32 deletions
diff --git a/src/zenutil/service.cpp b/src/zenutil/service.cpp index 103fdaa2f..f2a925e61 100644 --- a/src/zenutil/service.cpp +++ b/src/zenutil/service.cpp @@ -229,12 +229,13 @@ namespace { std::filesystem::path GetPListPath(const std::string& DaemonName) { - const std::filesystem::path PListFolder = "/Library/LaunchDaemons"; + char* HomeDir = getenv("HOME"); + std::filesystem::path PListFolder = HomeDir; + PListFolder /= "Library/LaunchAgents"; return PListFolder / (DaemonName + ".plist"); } - std::string BuildPlist(std::string_view ServiceName, - const std::filesystem::path& ExecutablePath, + std::string BuildPlist(const std::filesystem::path& ExecutablePath, std::string_view CommandLineOptions, std::string_view DaemonName, bool Debug) @@ -265,14 +266,8 @@ namespace { " <key>RunAtLoad</key>\n" " <true/>\n" " \n" - // " <key>KeepAlive</key>\n" - // " <true/>\n" - // " \n" - " <key>StandardOutPath</key>\n" - " <string>/var/log/{}.log</string>\n" - " \n" - " <key>StandardErrorPath</key>\n" - " <string>/var/log/{}.err.log</string>\n" + " <key>KeepAlive</key>\n" + " <true/>\n" " \n" " <key>Debug</key>\n" " <{}/>\n" @@ -282,22 +277,7 @@ namespace { DaemonName, ExecutablePath, ProgramArguments.ToView(), - ServiceName, - ServiceName, Debug ? "true"sv : "false"sv); - - // "<key>Sockets</key>" - // "<dict>" - // "<key>Listeners</key>" - // "<dict>" - // "<key>SockServiceName</key>" - // "<string>{}</string>" // Listen socket - // "<key>SockType</key>" - // "<string>tcp</string>" - // "<key>SockFamily</key>" - // "<string>IPv4</string>" - // "</dict>" - // "</dict>" } #endif // ZEN_PLATFORM_MAC @@ -752,9 +732,8 @@ StopService(std::string_view ServiceName) std::error_code InstallService(std::string_view ServiceName, const ServiceSpec& Spec) { - // TODO: Do we need to create a separate user for the service or is running as the default service user OK? const std::string DaemonName = GetDaemonName(ServiceName); - std::string PList = BuildPlist(ServiceName, Spec.ExecutablePath, Spec.CommandLineOptions, DaemonName, true); + std::string PList = BuildPlist(Spec.ExecutablePath, Spec.CommandLineOptions, DaemonName, true); const std::filesystem::path PListPath = GetPListPath(DaemonName); ZEN_INFO("Writing launchd plist to {}", PListPath.string()); @@ -910,8 +889,14 @@ StartService(std::string_view ServiceName) { const std::string DaemonName = GetDaemonName(ServiceName); const std::filesystem::path PListPath = GetPListPath(DaemonName); + std::pair<int, std::string> User = ExecuteProgram("id -u"); + + if (User.first != 0) + { + return MakeErrorCode(User.first); + } - std::pair<int, std::string> Res = ExecuteProgram(fmt::format("launchctl bootstrap system {}", PListPath)); + std::pair<int, std::string> Res = ExecuteProgram(fmt::format("launchctl bootstrap gui/{} {}", User.second, PListPath)); if (Res.first != 0) { return MakeErrorCode(Res.first); @@ -926,13 +911,18 @@ StopService(std::string_view ServiceName) const std::string DaemonName = GetDaemonName(ServiceName); const std::filesystem::path PListPath = GetPListPath(DaemonName); - /* - std::pair<int, std::string> Res = ExecuteProgram(fmt::format("launchctl bootout system ", PListPath.)); + std::pair<int, std::string> User = ExecuteProgram("id -u"); + + if (User.first != 0) + { + return MakeErrorCode(User.first); + } + + std::pair<int, std::string> Res = ExecuteProgram(fmt::format("launchctl bootout gui/{} {}", User.second, PListPath)); if (Res.first != 0) { return MakeErrorCode(Res.first); } - */ return {}; } |