From 26ff060ea52a18adee459bddd81f4d48b5d9407b Mon Sep 17 00:00:00 2001 From: onefang Date: Fri, 6 Aug 2021 08:22:57 +1000 Subject: Move the OpenSim stuff to before the web stuff. Coz that's the way we roll, er I mean run. --- src/sledjchisl/sledjchisl.c | 241 ++++++++++++++++++++++---------------------- 1 file changed, 118 insertions(+), 123 deletions(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 12c03cd..5d81ee2 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -7430,12 +7430,12 @@ jit library is loaded or the JIT compiler will not be activated. } + if (!isWeb) + { //////////////////////////////////////////////////////////////////////////////////////////////////// // Figure out what and where we are. //////////////////////////////////////////////////////////////////////////////////////////////////// // TODO - still a bit chicken and egg here about the tmux socket and reading configs from scEtc /.sledjChisl.conf.lua - if (!isWeb) - { I("Outputting to a terminal, not a web server."); // Check if we are already running inside the proper tmux server. char *eTMUX = getenv("TMUX"); @@ -7655,11 +7655,125 @@ jit library is loaded or the JIT compiler will not be activated. } + if (!isWeb) + { //////////////////////////////////////////////////////////////////////////////////////////////////// -// Start of web wrangling section. +// Start of OpenSim wrangling section. //////////////////////////////////////////////////////////////////////////////////////////////////// - if (isWeb) + struct sysinfo info; + // TODO - See https://stackoverflow.com/questions/2693948/how-do-i-retrieve-the-number-of-processors-on-c-linux, there are more portable ways, this seems to be GNU specific. + int cpus = (int) sysconf(_SC_NPROCESSORS_CONF), cpusOnline = (int) sysconf(_SC_NPROCESSORS_ONLN); + + if (0 == bulkSims) + bulkSims = (cpusOnline / 3) - 1; + sysinfo(&info); + ourSims->la = info.loads[0]/65536.0; + I("There are %i CPUs, %i of them are online. Doing %i sims at once. LoadAverage = %f", cpus, cpusOnline, bulkSims, ourSims->la); + + if (0 == toys.optc) + ; + else if (strcmp(toys.optargs[0], "create") == 0) + currentMode = CREATE; + else if (strcmp(toys.optargs[0], "start") == 0) + currentMode = START; + else if (strcmp(toys.optargs[0], "backup") == 0) + currentMode = BACKUP; + else if (strcmp(toys.optargs[0], "gitar") == 0) + currentMode = GITAR; + else if (strcmp(toys.optargs[0], "status") == 0) + currentMode = STATUS; + else if (strcmp(toys.optargs[0], "stop") == 0) + currentMode = STOP; + else + ourSims->target = toys.optargs[0]; + if (2 == toys.optc) + ourSims->target = toys.optargs[1]; +V("ARGS - %d %d %i |%s| %s |%s|", toys.optc, toys.optflags, currentMode, toys.optargs[0], toys.optargs[1], ourSims->target); + + // Start ROBUST or join the tmux session, or just figure out where the sims are running in tmux. + if ((START == currentMode) && !checkSimIsRunning("ROBUST")) + { + char *d = xmprintf("%s.{right}", Ttab); + char *c = xmprintf("cd %s/current/bin", scRoot); + + I("ROBUST is starting up."); + sendTmuxCmd(d, c); + free(c); + c = xmprintf("mono Robust.exe -inidirectory=%s/config/ROBUST", scRoot); + sendTmuxCmd(d, c); + free(c); + doTmuxCmd("select-pane -t 0 -T 'ROBUST'", Tcmd, scRun, Tsocket); + + // Create all the tmux windows, panes, and temporary .ini files coz OpenSim sucketh. + forEachSim("Prepping", prepSims); + waitTmuxText(d, "INITIALIZATION COMPLETE FOR ROBUST"); + I("ROBUST is done starting up."); + free(d); + } + else if ((0 == toys.optc) && (checkSimIsRunning("ROBUST"))) + { + // Join the session. + doTmuxCmd("select-window -t '%s' \\; attach-session -t '%s'", Tconsole, Tconsole); + goto finished; + } + else // Find out where the sims are in tmux. + forEachSim(NULL, findSimsTmux); + + // Do stuff with the sims. + forEachSim("Doing", doSimsThing); + + if ((STOP == currentMode) && (NULL == ourSims->target)) + { + // Stop all the sims. + forEachSim(NULL, stopSims); + I("Closing all the other windows."); + // First figure out what panes and windows are left. + snprintf(toybuf, sizeof(toybuf), "echo 'IDs={' >%s/IDs_ALL.lua", scTemp); + system(toybuf); + doTmuxCmd("list-panes -s -F '\"#{window_id}.#{pane_id}\",' >> %s/IDs_ALL.lua", scTemp); + snprintf(toybuf, sizeof(toybuf), "echo '}\nreturn IDs' >>%s/IDs_ALL.lua", scTemp); + system(toybuf); + snprintf(toybuf, sizeof(toybuf), "%s/IDs_ALL.lua", scTemp); + qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); + + qtreetbl_obj_t obj0; + memset((void*)&obj0, 0, sizeof(obj0)); + IDs->lock(IDs); + while(IDs->getnext(IDs, &obj0, false) == true) + { + qLua *q0 = obj0.data; + + if ('0' != q0->v.s[1]) + doTmuxCmd("kill-pane -t %s", q0->v.s); + } + IDs->unlock(IDs); + freeLuaTree(IDs); + + char *c = xmprintf("rm -fr %s/*", scTemp); + if (!WIFEXITED(system(c))) + E("rm command failed! %s", c); + free(c); + } + else if (START == currentMode) + { + if (checkSimIsRunning("ROBUST") && (NULL == ourSims->target)) + { + // TODO - remove this once we handle the fcgi stuff ourselves. + I("Starting the web stuff."); + char *c = xmprintf("spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- /usr/bin/valgrind --leak-check=full sledjchisl", + scUser, scCache, scRoot); + sendTmuxCmd(Ttab, c); + free(c); + } + else + I("NOT Starting the web stuff."); + } + } + else { +//////////////////////////////////////////////////////////////////////////////////////////////////// +// Start of web wrangling section. +//////////////////////////////////////////////////////////////////////////////////////////////////// char **initialEnv = environ; char *tmp0, *tmp1; int count = 0, entries, bytes; @@ -8031,8 +8145,6 @@ fcgiDone: FCGI_fprintf(FCGI_stderr, "Stopped SledjChisl web server.\n"); D("Stopped SledjChisl web server."); - - goto finished; } //////////////////////////////////////////////////////////////////////////////////////////////////// // End of web wrangling section. @@ -8040,123 +8152,6 @@ fcgiDone: -//////////////////////////////////////////////////////////////////////////////////////////////////// -// Start of OpenSim wrangling section. -//////////////////////////////////////////////////////////////////////////////////////////////////// - struct sysinfo info; - // TODO - See https://stackoverflow.com/questions/2693948/how-do-i-retrieve-the-number-of-processors-on-c-linux, there are more portable ways, this seems to be GNU specific. - int cpus = (int) sysconf(_SC_NPROCESSORS_CONF), cpusOnline = (int) sysconf(_SC_NPROCESSORS_ONLN); - - if (0 == bulkSims) - bulkSims = (cpusOnline / 3) - 1; - sysinfo(&info); - ourSims->la = info.loads[0]/65536.0; - I("There are %i CPUs, %i of them are online. Doing %i sims at once. LoadAverage = %f", cpus, cpusOnline, bulkSims, ourSims->la); - - if (0 == toys.optc) - ; - else if (strcmp(toys.optargs[0], "create") == 0) - currentMode = CREATE; - else if (strcmp(toys.optargs[0], "start") == 0) - currentMode = START; - else if (strcmp(toys.optargs[0], "backup") == 0) - currentMode = BACKUP; - else if (strcmp(toys.optargs[0], "gitar") == 0) - currentMode = GITAR; - else if (strcmp(toys.optargs[0], "status") == 0) - currentMode = STATUS; - else if (strcmp(toys.optargs[0], "stop") == 0) - currentMode = STOP; - else - ourSims->target = toys.optargs[0]; - if (2 == toys.optc) - ourSims->target = toys.optargs[1]; -V("ARGS - %d %d %i |%s| %s |%s|", toys.optc, toys.optflags, currentMode, toys.optargs[0], toys.optargs[1], ourSims->target); - - // Start ROBUST or join the tmux session, or just figure out where the sims are running in tmux. - if ((START == currentMode) && !checkSimIsRunning("ROBUST")) - { - char *d = xmprintf("%s.{right}", Ttab); - char *c = xmprintf("cd %s/current/bin", scRoot); - - I("ROBUST is starting up."); - sendTmuxCmd(d, c); - free(c); - c = xmprintf("mono Robust.exe -inidirectory=%s/config/ROBUST", scRoot); - sendTmuxCmd(d, c); - free(c); - doTmuxCmd("select-pane -t 0 -T 'ROBUST'", Tcmd, scRun, Tsocket); - - // Create all the tmux windows, panes, and temporary .ini files coz OpenSim sucketh. - forEachSim("Prepping", prepSims); - waitTmuxText(d, "INITIALIZATION COMPLETE FOR ROBUST"); - I("ROBUST is done starting up."); - free(d); - } - else if ((0 == toys.optc) && (checkSimIsRunning("ROBUST"))) - { - // Join the session. - doTmuxCmd("select-window -t '%s' \\; attach-session -t '%s'", Tconsole, Tconsole); - goto finished; - } - else // Find out where the sims are in tmux. - forEachSim(NULL, findSimsTmux); - - // Do stuff with the sims. - forEachSim("Doing", doSimsThing); - - if (START == currentMode) - { - if (checkSimIsRunning("ROBUST") && (NULL == ourSims->target)) - { - // TODO - remove this once we handle the fcgi stuff ourselves. - I("Starting the web stuff."); - char *c = xmprintf("spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- " - "/usr/bin/valgrind --leak-check=full sledjchisl", - scUser, scCache, scRoot); - sendTmuxCmd(Ttab, c); - free(c); - } - else - I("NOT Starting the web stuff."); - } - else if ((STOP == currentMode) && (NULL == ourSims->target)) - { - // Stop all the sims. - forEachSim(NULL, stopSims); - I("Closing all the other windows."); - // First figure out what panes and windows are left. - snprintf(toybuf, sizeof(toybuf), "echo 'IDs={' >%s/IDs_ALL.lua", scTemp); - system(toybuf); - doTmuxCmd("list-panes -s -F '\"#{window_id}.#{pane_id}\",' >> %s/IDs_ALL.lua", scTemp); - snprintf(toybuf, sizeof(toybuf), "echo '}\nreturn IDs' >>%s/IDs_ALL.lua", scTemp); - system(toybuf); - snprintf(toybuf, sizeof(toybuf), "%s/IDs_ALL.lua", scTemp); - qtreetbl_t *IDs = Lua2tree(toybuf, "IDs"); - - qtreetbl_obj_t obj0; - memset((void*)&obj0, 0, sizeof(obj0)); - IDs->lock(IDs); - while(IDs->getnext(IDs, &obj0, false) == true) - { - qLua *q0 = obj0.data; - - if ('0' != q0->v.s[1]) - doTmuxCmd("kill-pane -t %s", q0->v.s); - } - IDs->unlock(IDs); - freeLuaTree(IDs); - - char *c = xmprintf("rm -fr %s/*", scTemp); - if (!WIFEXITED(system(c))) - E("rm command failed! %s", c); - free(c); - } -//////////////////////////////////////////////////////////////////////////////////////////////////// -// End of OpenSim wrangling section. -//////////////////////////////////////////////////////////////////////////////////////////////////// - - /* double sum; -- cgit v1.1