Skip to content

Commit

Permalink
Restart the masterserver in case of fatal errors [ds only] [skip appv…
Browse files Browse the repository at this point in the history
…eyor]
  • Loading branch information
geneotech committed May 11, 2024
1 parent 14688ac commit 46fde4d
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/application/masterserver/masterserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ static auto to_webrtc_alias(
return location_id;
}

void perform_masterserver(const config_lua_table& cfg) try {
work_result perform_masterserver(const config_lua_table& cfg) try {
using namespace httplib;

const auto& settings = cfg.masterserver;
Expand Down Expand Up @@ -179,7 +179,7 @@ void perform_masterserver(const config_lua_table& cfg) try {
}
else {
LOG("There was a problem binding masterserver to %x:%x! Quitting.", settings.ip, new_port);
return;
return work_result::FAILURE;
}

LOG("Created masterserver socket at: %x", ::ToString(udp_command_sockets.back().socket.address));
Expand Down Expand Up @@ -283,7 +283,7 @@ void perform_masterserver(const config_lua_table& cfg) try {
const auto masterserver_dump_path = USER_DIR / "masterserver.dump";

auto reserialize_list = [&]() {
MSR_LOG("Reserializing the server list.");
// MSR_LOG("Reserializing the server list.");

const auto peer_map = signalling.get_new_peers_map();

Expand Down Expand Up @@ -691,6 +691,8 @@ void perform_masterserver(const config_lua_table& cfg) try {
push_alert_webhook("Server list restarted.");
}

std::optional<work_result> ms_work_result;

while (true) {
#if PLATFORM_UNIX
if (signal_status != 0) {
Expand Down Expand Up @@ -953,6 +955,9 @@ void perform_masterserver(const config_lua_table& cfg) try {
}

rtc_errors.clear();

ms_work_result = work_result::RELAUNCH_MASTERSERVER;
break;
}
}

Expand All @@ -975,7 +980,14 @@ void perform_masterserver(const config_lua_table& cfg) try {
}

dump_server_list_to_file();

if (ms_work_result.has_value()) {
return *ms_work_result;
}

return work_result::SUCCESS;
}
catch (const netcode_socket_raii_error& err) {
LOG(err.what());
return work_result::FAILURE;
}
3 changes: 2 additions & 1 deletion src/application/masterserver/masterserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "application/masterserver/nat_traversal_step_payload.h"
#include "application/masterserver/gameserver_commands.h"
#include "application/masterserver/masterserver_commands.h"
#include "work_result.h"

struct config_lua_table;
struct server_heartbeat;
Expand All @@ -25,4 +26,4 @@ using masterserver_response = std::variant<
masterserver_out::stun_result_info
>;

void perform_masterserver(const config_lua_table&);
work_result perform_masterserver(const config_lua_table&);
4 changes: 4 additions & 0 deletions src/augs/window_framework/shell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ namespace augs {
}

void open_text_editor(const std::string& on_file) {
#if HEADLESS
(void)on_file;
#else
const auto full_path = std::filesystem::absolute(augs::path_type(on_file));

#if PLATFORM_MACOS
Expand All @@ -44,6 +47,7 @@ namespace augs {
#endif

augs::shell(command.string());
#endif
}
}
#else
Expand Down
7 changes: 7 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ int main(const int argc, const char* const * const argv) {
return augs::restart_application(argc, argv, exe_path.string(), { "--suppress-server-webhook" });
}

case work_result::RELAUNCH_MASTERSERVER: {
LOG("main: Masterserver requested relaunch.");
save_failure_logs();

return augs::restart_application(argc, argv, exe_path.string(), {});
}

case work_result::RELAUNCH_AND_UPDATE_DEDICATED_SERVER: {
LOG("main: Dedicated server detected available updates.");
save_success_logs();
Expand Down
4 changes: 1 addition & 3 deletions src/work.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,9 +801,7 @@ work_result work(
masterserver.get_last_udp_command_port()
);

perform_masterserver(adjusted_config);

return work_result::SUCCESS;
return perform_masterserver(adjusted_config);
}
#endif

Expand Down
1 change: 1 addition & 0 deletions src/work_result.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ enum class work_result {
SUCCESS,
FAILURE,
RELAUNCH_DEDICATED_SERVER,
RELAUNCH_MASTERSERVER,
RELAUNCH_AND_UPDATE_DEDICATED_SERVER,
RELAUNCH_UPGRADED,

Expand Down

0 comments on commit 46fde4d

Please sign in to comment.