From 4d2a2b12eab527b4a81309234b707a076bf693af Mon Sep 17 00:00:00 2001 From: onefang Date: Fri, 13 Aug 2021 03:26:48 +1000 Subject: Restart sims. --- src/sledjchisl/sledjchisl.c | 96 ++++++++++++++++++++++++++------------------- 1 file changed, 56 insertions(+), 40 deletions(-) (limited to 'src') diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index d8b78e6..7180383 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -1769,6 +1769,54 @@ void findSimsTmux(simData *simd, char *sim, char *type, int count, int window, i freeLuaTree(IDs); } +void startSim(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) +{ + if (!checkSimIsRunning(simd->tab)) + { + I("Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d - %s is starting.", window, type, pane, simd->paneID, scTemp, count, simd->name); + doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, simd->paneID, simd->tab); + snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d", scTemp, count); + sendTmuxCmd(simd->paneID, toybuf); + if (0 == ourSims->doIt) + { + snprintf(toybuf, sizeof(toybuf), "INITIALIZATION COMPLETE FOR %s", simd->name); + waitTmuxText(simd->paneID, toybuf); + I("%s is done starting up.", simd->name); + ourSims->la = waitLoadAverage(ourSims->la, loadAverageInc, simTimeOut); + if (1 < bulkSims) + bulkSims = bulkSims / 2; + } + else + { +// TODO - some compromise, do a premptive load check if we are not doing a wait anyway. + } + ourSims->doIt = ((count + 1) % bulkSims); + } +} + +void stopSim(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) +{ + if (checkSimIsRunning(simd->tab)) + { + // Leave empty panes as is. +// TODO - should check if there's people there, but don't count NPCs. alert them, wait a while, or just abort the stop. + sendTmuxCmd(simd->paneID, "quit"); + // There's three things that might happen - + // Sim will quit, tmux pane will go away before we can see the shutdown message. + // pane-exited hook might be useful here. + // Sim will quit, tmux pane wont go away. Dunno yet if waitTmuxText() will still work. + // pane-died hook might be useful here. + // Sim fails to quit, error message on the pane that we want to read, wont see the shutdown message. + // Also sim might not have finished starting up, and may even not be accepting comands yet. +// TODO - cater for and test them all. +// Could also loop on checkSimIsRunning(sim) +// snprintf(toybuf, sizeof(toybuf), "[SHUTDOWN]: Shutdown processing on main thread complete. Exiting..."); +// waitTmuxText(nm, toybuf); +// I("%s is done stopping.", simd->name); +// la = waitLoadAverage(la, loadAverageInc, simTimeOut); + } +} + void doSimsThing(simData *simd, char *sim, char *type, int count, int window, int panes, int pane) { // Check if only doing a single sim. @@ -1798,27 +1846,7 @@ void doSimsThing(simData *simd, char *sim, char *type, int count, int window, in { case START : // "start 'Welcome sim'" "start Welcome.shini" "Welcome.shini" "start Welcome.ini" "start Welcome" "start" start everything { - if (!checkSimIsRunning(simd->tab)) - { - I("Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d - %s is starting.", window, type, pane, simd->paneID, scTemp, count, simd->name); - doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, simd->paneID, simd->tab); - snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d", scTemp, count); - sendTmuxCmd(simd->paneID, toybuf); - if (0 == ourSims->doIt) - { - snprintf(toybuf, sizeof(toybuf), "INITIALIZATION COMPLETE FOR %s", simd->name); - waitTmuxText(simd->paneID, toybuf); - I("%s is done starting up.", simd->name); - ourSims->la = waitLoadAverage(ourSims->la, loadAverageInc, simTimeOut); - if (1 < bulkSims) - bulkSims = bulkSims / 2; - } - else - { -// TODO - some compromise, do a premptive load check if we are not doing a wait anyway. - } - ourSims->doIt = ((count + 1) % bulkSims); - } + startSim(simd, sim, type, count, window, panes, pane); break; } @@ -1866,6 +1894,12 @@ void doSimsThing(simData *simd, char *sim, char *type, int count, int window, in case RESTART : // "restart 'Welcome sim'" "restart Welcome.shini" "Welcome.shini restart" "restart Welcome.ini" "restart Welcome" "restart" restart everything { + I("Tmux tab [%d:%s](pane %d) tmux ID %s, from %s/sim%d - %s is stopping.", window, type, pane, simd->paneID, scTemp, count, simd->name); + stopSim(simd, sim, type, count, window, panes, pane); + while (checkSimIsRunning(simd->tab)) + usleep(100000); + usleep(100000); + startSim(simd, sim, type, count, window, panes, pane); break; } @@ -1881,25 +1915,7 @@ void doSimsThing(simData *simd, char *sim, char *type, int count, int window, in case STOP : // "stop 'Welcome sim'" "stop Welcome.shini" "Welcome.shini stop" "stop Welcome.ini" "stop Welcome" "stop" stop everything { - if (checkSimIsRunning(simd->tab)) - { - // Leave empty panes as is. -// TODO - should check if there's people there, but don't count NPCs. alert them, wait a while, or just abort the stop. - sendTmuxCmd(simd->paneID, "quit"); - // There's three things that might happen - - // Sim will quit, tmux pane will go away before we can see the shutdown message. - // pane-exited hook might be useful here. - // Sim will quit, tmux pane wont go away. Dunno yet if waitTmuxText() will still work. - // pane-died hook might be useful here. - // Sim fails to quit, error message on the pane that we want to read, wont see the shutdown message. - // Also sim might not have finished starting up, and may even not be accepting comands yet. -// TODO - cater for and test them all. -// Could also loop on checkSimIsRunning(sim) -// snprintf(toybuf, sizeof(toybuf), "[SHUTDOWN]: Shutdown processing on main thread complete. Exiting..."); -// waitTmuxText(nm, toybuf); -// I("%s is done stopping.", simd->name); -// la = waitLoadAverage(la, loadAverageInc, simTimeOut); - } + stopSim(simd, sim, type, count, window, panes, pane); break; } -- cgit v1.1