diff options
| author | Per Larsson <[email protected]> | 2021-09-28 15:09:15 +0200 |
|---|---|---|
| committer | Per Larsson <[email protected]> | 2021-09-28 15:09:15 +0200 |
| commit | 141317786f9d59e95da8316ce40cf30e4dfd7b53 (patch) | |
| tree | 3c863384c6ca68a30e82989994408c5f40159273 /zenserver | |
| parent | Removed using the bucket name to detect binary cache records and store conten... (diff) | |
| parent | apply: Re-enabled environment variable setup for child processes (diff) | |
| download | zen-141317786f9d59e95da8316ce40cf30e4dfd7b53.tar.xz zen-141317786f9d59e95da8316ce40cf30e4dfd7b53.zip | |
Merge branch 'main' of https://github.com/EpicGames/zen
Diffstat (limited to 'zenserver')
| -rw-r--r-- | zenserver/admin/admin.cpp | 44 | ||||
| -rw-r--r-- | zenserver/admin/admin.h | 10 | ||||
| -rw-r--r-- | zenserver/compute/apply.cpp | 4 | ||||
| -rw-r--r-- | zenserver/config.cpp | 4 | ||||
| -rw-r--r-- | zenserver/config.h | 9 | ||||
| -rw-r--r-- | zenserver/testing/httptest.cpp | 11 | ||||
| -rw-r--r-- | zenserver/testing/httptest.h | 5 | ||||
| -rw-r--r-- | zenserver/windows/service.cpp | 33 | ||||
| -rw-r--r-- | zenserver/zenserver.cpp | 4 | ||||
| -rw-r--r-- | zenserver/zenserver.vcxproj | 1 |
10 files changed, 101 insertions, 24 deletions
diff --git a/zenserver/admin/admin.cpp b/zenserver/admin/admin.cpp new file mode 100644 index 000000000..07211cbeb --- /dev/null +++ b/zenserver/admin/admin.cpp @@ -0,0 +1,44 @@ +// Copyright Epic Games, Inc. All Rights Reserved. + +#pragma once + +#include "admin.h" + +#include <zencore/compactbinarybuilder.h> + +namespace zen { + +HttpAdminService::HttpAdminService() +{ + m_Router.RegisterRoute( + "hello", + [this](HttpRouterRequest& Req) { Req.ServerRequest().WriteResponse(HttpResponseCode::OK); }, + HttpVerb::kGet); + + m_Router.RegisterRoute( + "health", + [this](HttpRouterRequest& Req) { + CbObjectWriter Obj; + Obj.AddBool("ok", true); + Req.ServerRequest().WriteResponse(HttpResponseCode::OK, Obj.Save()); + }, + HttpVerb::kGet); +} + +HttpAdminService::~HttpAdminService() +{ +} + +const char* +HttpAdminService::BaseUri() const +{ + return "/admin/"; +} + +void +HttpAdminService::HandleRequest(zen::HttpServerRequest& Request) +{ + m_Router.HandleRequest(Request); +} + +} // namespace zen diff --git a/zenserver/admin/admin.h b/zenserver/admin/admin.h index 3554b1005..6257f0998 100644 --- a/zenserver/admin/admin.h +++ b/zenserver/admin/admin.h @@ -9,14 +9,14 @@ namespace zen { class HttpAdminService : public zen::HttpService { public: - HttpAdminService() = default; - ~HttpAdminService() = default; + HttpAdminService(); + ~HttpAdminService(); - virtual const char* BaseUri() const override { return "/admin/"; } - - virtual void HandleRequest(zen::HttpServerRequest& Request) override { ZEN_UNUSED(Request); } + virtual const char* BaseUri() const override; + virtual void HandleRequest(zen::HttpServerRequest& Request) override; private: + HttpRequestRouter m_Router; }; } // namespace zen diff --git a/zenserver/compute/apply.cpp b/zenserver/compute/apply.cpp index 15d9e0141..a522aa35b 100644 --- a/zenserver/compute/apply.cpp +++ b/zenserver/compute/apply.cpp @@ -767,8 +767,8 @@ HttpFunctionService::ExecAction(const WorkerDesc& Worker, CbObject Action) lpThreadAttributes, bInheritHandles, dwCreationFlags, - nullptr, // (LPVOID)EnvironmentBlock.c_str(), // Environment block - SandboxPath.c_str(), // Current directory + (LPVOID)EnvironmentBlock.Data(), // Environment block + SandboxPath.c_str(), // Current directory &StartupInfo, /* out */ &ProcessInformation); diff --git a/zenserver/config.cpp b/zenserver/config.cpp index 91fb80747..42f59b26c 100644 --- a/zenserver/config.cpp +++ b/zenserver/config.cpp @@ -122,12 +122,14 @@ ParseGlobalCliOptions(int argc, char* argv[], ZenServerOptions& GlobalOptions, Z cxxopts::value<int>(GlobalOptions.BasePort)->default_value("1337"), "<port number>"); +#if ZEN_ENABLE_MESH options.add_option("network", "m", "mesh", "Enable mesh network", cxxopts::value<bool>(ServiceConfig.MeshEnabled)->default_value("false"), ""); +#endif options.add_option("diagnostics", "", @@ -311,7 +313,9 @@ ParseServiceConfig(const std::filesystem::path& DataRoot, ZenServiceConfig& Serv throw std::runtime_error("failed to run global config script ('{}'): {}"_format(ConfigScript, e.what()).c_str()); } +#if ZEN_ENABLE_MESH ServiceConfig.MeshEnabled = lua["mesh"]["enable"].get_or(ServiceConfig.MeshEnabled); +#endif auto UpdateStringValueFromConfig = [](const sol::table& Table, std::string_view Key, std::string& OutValue) { // Update the specified config value unless it has been set, i.e. from command line diff --git a/zenserver/config.h b/zenserver/config.h index ce059bdb2..75c19d690 100644 --- a/zenserver/config.h +++ b/zenserver/config.h @@ -56,10 +56,11 @@ struct ZenUpstreamCacheConfig struct ZenServiceConfig { - bool StructuredCacheEnabled = true; - bool ShouldCrash = false; // Option for testing crash handling - bool MeshEnabled = false; // Experimental p2p mesh discovery - std::string FlockId; // Id for grouping test instances into sets + bool StructuredCacheEnabled = true; + bool ShouldCrash = false; // Option for testing crash handling +#if ZEN_ENABLE_MESH + bool MeshEnabled = false; // Experimental p2p mesh discovery +#endif ZenUpstreamCacheConfig UpstreamCacheConfig; }; diff --git a/zenserver/testing/httptest.cpp b/zenserver/testing/httptest.cpp index c4fd6003c..18d63a6ef 100644 --- a/zenserver/testing/httptest.cpp +++ b/zenserver/testing/httptest.cpp @@ -2,6 +2,7 @@ #include "httptest.h" +#include <zencore/compactbinarybuilder.h> #include <zencore/compactbinarypackage.h> namespace zen { @@ -14,6 +15,16 @@ HttpTestingService::HttpTestingService() HttpVerb::kGet); m_Router.RegisterRoute( + "json", + [this](HttpRouterRequest& Req) { + CbObjectWriter Obj; + Obj.AddBool("ok", true); + Obj.AddInteger("counter", ++m_Counter); + Req.ServerRequest().WriteResponse(HttpResponseCode::OK, Obj.Save()); + }, + HttpVerb::kGet); + + m_Router.RegisterRoute( "echo", [this](HttpRouterRequest& Req) { IoBuffer Body = Req.ServerRequest().ReadPayload(); diff --git a/zenserver/testing/httptest.h b/zenserver/testing/httptest.h index b445fb450..f55780d05 100644 --- a/zenserver/testing/httptest.h +++ b/zenserver/testing/httptest.h @@ -5,6 +5,8 @@ #include <zencore/logging.h> #include <zenhttp/httpserver.h> +#include <atomic> + namespace zen { /** @@ -37,7 +39,8 @@ public: }; private: - HttpRequestRouter m_Router; + HttpRequestRouter m_Router; + std::atomic<uint32_t> m_Counter{0}; RwLock m_RwLock; std::unordered_map<uint32_t, Ref<PackageHandler>> m_HandlerMap; diff --git a/zenserver/windows/service.cpp b/zenserver/windows/service.cpp index 017b5f9a7..b7b3b9bc1 100644 --- a/zenserver/windows/service.cpp +++ b/zenserver/windows/service.cpp @@ -3,6 +3,7 @@ #include "service.h" #include <zencore/zencore.h> +#include <zencore/except.h> #include <stdio.h> #include <tchar.h> @@ -146,26 +147,34 @@ CallMain(DWORD, LPSTR*) int WindowsService::ServiceMain() { - if (zen::IsInteractiveSession()) - { - // Not actually running as a service - return Run(); - } - else + gSvc = this; + + SERVICE_TABLE_ENTRY DispatchTable[] = {{(LPWSTR)SVCNAME, (LPSERVICE_MAIN_FUNCTION)&CallMain}, {NULL, NULL}}; + + // This call returns when the service has stopped. + // The process should simply terminate when the call returns. + + if (!StartServiceCtrlDispatcher(DispatchTable)) { - gSvc = this; + const DWORD dwError = zen::GetLastError(); - SERVICE_TABLE_ENTRY DispatchTable[] = {{(LPWSTR)SVCNAME, (LPSERVICE_MAIN_FUNCTION)&CallMain}, {NULL, NULL}}; + if (dwError == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) + { + // Not actually running as a service + gSvc = nullptr; - // This call returns when the service has stopped. - // The process should simply terminate when the call returns. + zen::SetIsInteractiveSession(true); - if (!StartServiceCtrlDispatcher(DispatchTable)) + return Run(); + } + else { - SvcReportEvent((LPTSTR)L"StartServiceCtrlDispatcher"); + zen::ThrowSystemError(dwError, "StartServiceCtrlDispatcher failed"); } } + zen::SetIsInteractiveSession(false); + return 0; } diff --git a/zenserver/zenserver.cpp b/zenserver/zenserver.cpp index fe4f41ab5..b45df9fef 100644 --- a/zenserver/zenserver.cpp +++ b/zenserver/zenserver.cpp @@ -261,6 +261,7 @@ public: ZEN_INFO("NOT instantiating structured cache service"); } +#if ZEN_ENABLE_MESH if (ServiceConfig.MeshEnabled) { StartMesh(BasePort); @@ -269,6 +270,7 @@ public: { ZEN_INFO("NOT starting mesh"); } +#endif m_Http = zen::CreateHttpServer(); m_Http->Initialize(BasePort); @@ -302,11 +304,13 @@ public: } } +#if ZEN_ENABLE_MESH void StartMesh(int BasePort) { ZEN_INFO("initializing mesh discovery"); m_ZenMesh.Start(uint16_t(BasePort)); } +#endif void Run() { diff --git a/zenserver/zenserver.vcxproj b/zenserver/zenserver.vcxproj index 29436d840..bcb7ea028 100644 --- a/zenserver/zenserver.vcxproj +++ b/zenserver/zenserver.vcxproj @@ -126,6 +126,7 @@ <ClInclude Include="windows\service.h" /> </ItemGroup> <ItemGroup> + <ClCompile Include="admin\admin.cpp" /> <ClCompile Include="cache\structuredcache.cpp" /> <ClCompile Include="cache\structuredcachestore.cpp" /> <ClCompile Include="compute\apply.cpp" /> |