Merge pull request #476 from Cyberboss/SilentRestart

Allows silent reboots from in game
This commit is contained in:
Jordan Brown
2018-01-21 11:34:10 -05:00
committed by GitHub
5 changed files with 27 additions and 10 deletions
+3 -2
View File
@@ -1,5 +1,5 @@
// /tg/station 13 server tools API // /tg/station 13 server tools API
#define SERVICE_API_VERSION_STRING "3.2.0.2" #define SERVICE_API_VERSION_STRING "3.2.0.3"
//CONFIGURATION //CONFIGURATION
//use this define if you want to do configuration outside of this file //use this define if you want to do configuration outside of this file
@@ -47,7 +47,7 @@
//Forces a hard reboot of BYOND by ending the process //Forces a hard reboot of BYOND by ending the process
//unlike del(world) clients will try to reconnect //unlike del(world) clients will try to reconnect
//If the service has not requested a shutdown, the world will reboot shortly after //If the service has not requested a shutdown, the world will reboot shortly after
#define SERVER_TOOLS_REBOOT_BYOND world.ServiceEndProcess() #define SERVER_TOOLS_REBOOT_BYOND(silent) world.ServiceEndProcess(silent)
/* /*
Gets the list of any testmerged github pull requests Gets the list of any testmerged github pull requests
@@ -93,6 +93,7 @@
#define SERVICE_JSON_PARAM_REQUIREDPARAMETERS "required_parameters" #define SERVICE_JSON_PARAM_REQUIREDPARAMETERS "required_parameters"
#define SERVICE_REQUEST_KILL_PROCESS "killme" #define SERVICE_REQUEST_KILL_PROCESS "killme"
#define SERVICE_REQUEST_KILL_PROCESS_SILENT "killmesilent"
#define SERVICE_REQUEST_IRC_BROADCAST "irc" #define SERVICE_REQUEST_IRC_BROADCAST "irc"
#define SERVICE_REQUEST_IRC_ADMIN_CHANNEL_MESSAGE "send2irc" #define SERVICE_REQUEST_IRC_ADMIN_CHANNEL_MESSAGE "send2irc"
#define SERVICE_REQUEST_WORLD_REBOOT "worldreboot" #define SERVICE_REQUEST_WORLD_REBOOT "worldreboot"
+2 -2
View File
@@ -47,10 +47,10 @@ SERVER_TOOLS_DEFINE_AND_SET_GLOBAL(server_tools_api_compatible, FALSE)
/world/proc/AdminBroadcast(message) /world/proc/AdminBroadcast(message)
ExportService("[SERVICE_REQUEST_IRC_ADMIN_CHANNEL_MESSAGE] [message]") ExportService("[SERVICE_REQUEST_IRC_ADMIN_CHANNEL_MESSAGE] [message]")
/world/proc/ServiceEndProcess() /world/proc/ServiceEndProcess(silent = FALSE)
SERVER_TOOLS_LOG("Sending shutdown request!"); SERVER_TOOLS_LOG("Sending shutdown request!");
sleep(world.tick_lag) //flush the buffers sleep(world.tick_lag) //flush the buffers
ExportService(SERVICE_REQUEST_KILL_PROCESS) ExportService(silent ? SERVICE_REQUEST_KILL_PROCESS_SILENT : SERVICE_REQUEST_KILL_PROCESS)
//called at the exact moment the world is supposed to reboot //called at the exact moment the world is supposed to reboot
/world/proc/ServiceReboot() /world/proc/ServiceReboot()
+14 -3
View File
@@ -246,7 +246,7 @@ namespace TGS.Server
} }
//handle a kill request from the server //handle a kill request from the server
public void KillMe() public void KillMe(bool silent)
{ {
bool DoRestart; bool DoRestart;
lock (watchdogLock) lock (watchdogLock)
@@ -257,7 +257,7 @@ namespace TGS.Server
} }
//Do this is a seperate thread or we'll kill this thread in the middle of rebooting //Do this is a seperate thread or we'll kill this thread in the middle of rebooting
if (DoRestart) if (DoRestart)
ThreadPool.QueueUserWorkItem(_ => { Restart(); }); ThreadPool.QueueUserWorkItem(_ => { RestartImpl(silent); });
else else
ThreadPool.QueueUserWorkItem(_ => { Stop(); }); ThreadPool.QueueUserWorkItem(_ => { Stop(); });
} }
@@ -267,13 +267,24 @@ namespace TGS.Server
{ {
if (DaemonStatus() == DreamDaemonStatus.Offline) if (DaemonStatus() == DreamDaemonStatus.Offline)
return Start(); return Start();
return RestartImpl(false);
}
/// <summary>
/// Restarts DD
/// </summary>
/// <param name="silent">If <see langword="false"/> no chat message will be sent</param>
/// <returns><see langword="null"/> on success, error message on failure</returns>
string RestartImpl(bool silent)
{
lock (restartLock) lock (restartLock)
{ {
if (RestartInProgress) if (RestartInProgress)
return "Restart already in progress"; return "Restart already in progress";
RestartInProgress = true; RestartInProgress = true;
} }
SendMessage("DD: Hard restart triggered", MessageType.WatchdogInfo); if (!silent)
SendMessage("DD: Hard restart triggered", MessageType.WatchdogInfo);
Stop(); Stop();
var res = Start(); var res = Start();
if (res != null) if (res != null)
+7 -2
View File
@@ -41,6 +41,7 @@ namespace TGS.Server
const string SRetSuccess = "SUCCESS"; const string SRetSuccess = "SUCCESS";
const string SRKillProcess = "killme"; const string SRKillProcess = "killme";
const string SRKillProcessSilent = "killmesilent";
const string SRIRCBroadcast = "irc"; const string SRIRCBroadcast = "irc";
const string SRIRCAdminChannelMessage = "send2irc"; const string SRIRCAdminChannelMessage = "send2irc";
const string SRWorldReboot = "worldreboot"; const string SRWorldReboot = "worldreboot";
@@ -102,15 +103,19 @@ namespace TGS.Server
} }
if (!APIValid && cmd != SRAPIVersion) if (!APIValid && cmd != SRAPIVersion)
return; //SPEAK THE LANGUAGE!!! return; //SPEAK THE LANGUAGE!!!
var showKillMessage = true;
switch (cmd) switch (cmd)
{ {
case SRIRCBroadcast: case SRIRCBroadcast:
SendMessage("GAME: " + String.Join(" ", splits), MessageType.GameInfo); SendMessage("GAME: " + String.Join(" ", splits), MessageType.GameInfo);
break; break;
case SRKillProcessSilent:
showKillMessage = false;
goto case SRKillProcess;
case SRKillProcess: case SRKillProcess:
KillMe(); KillMe(!showKillMessage);
break; break;
case SRIRCAdminChannelMessage: case SRIRCAdminChannelMessage:
SendMessage("RELAY: " + String.Join(" ", splits), MessageType.AdminInfo); SendMessage("RELAY: " + String.Join(" ", splits), MessageType.AdminInfo);
+1 -1
View File
@@ -8,7 +8,7 @@
/world/Reboot(reason) /world/Reboot(reason)
SERVER_TOOLS_ON_REBOOT SERVER_TOOLS_ON_REBOOT
SERVER_TOOLS_REBOOT_BYOND SERVER_TOOLS_REBOOT_BYOND(FALSE)
/proc/message_admins(event) /proc/message_admins(event)
world << event world << event