Systemd socket activation: env handling, config option and worldserver.conf.dist entry

This commit is contained in:
Ovv 2025-10-31 20:25:22 +01:00
parent d747c9c67a
commit 9d1143f47c
4 changed files with 20 additions and 6 deletions

View File

@ -23,8 +23,8 @@
int get_listen_fds()
{
const char* listen_pid = std::getenv("LISTEN_PID");
const char* listen_fds = std::getenv("LISTEN_FDS");
char* const listen_pid = std::getenv("LISTEN_PID");
char* const listen_fds = std::getenv("LISTEN_FDS");
if (!listen_pid || !listen_fds)
return 0;
@ -32,10 +32,12 @@ int get_listen_fds()
if (pid != getpid())
return 0;
if (Acore::StringTo<int>(listen_fds).value_or(0) <= 0)
int fds = Acore::StringTo<int>(listen_fds).value_or(0);
if (fds <= 0)
return 0;
return 3;
return fds;
}
#else
// On non-Linux systems, just return 0 (no socket activation)

View File

@ -397,6 +397,17 @@ Network.TcpNodelay = 1
Network.EnableProxyProtocol = 0
#
# Network.UseSocketActivation
# Description: Enable systemd socket activation support for the worldserver.
# When enabled and the process is started by systemd socket activation,
# the server will use the socket passed by systemd instead of
# creating and binding its own listening socket. Disabled by default.
# Example: 1 - (Enabled)
# Default: 0 - (Disabled)
Network.UseSocketActivation = 0
#
###################################################################################################

View File

@ -139,7 +139,7 @@ private:
tcp::socket _socket;
std::atomic<bool> _closed;
std::function<std::pair<tcp::socket*, uint32>()> _socketFactory;
bool _supportSocketActivation = false;
bool _supportSocketActivation;
};
template<class T>

View File

@ -42,7 +42,8 @@ public:
std::unique_ptr<AsyncAcceptor> acceptor;
try
{
acceptor = std::make_unique<AsyncAcceptor>(ioContext, bindIp, port, true);
bool supportSocketActivation = sConfigMgr->GetOption<bool>("Network.UseSocketActivation", false, true);
acceptor = std::make_unique<AsyncAcceptor>(ioContext, bindIp, port, supportSocketActivation);
}
catch (boost::system::system_error const& err)
{