From 0657d65d79ad308cd45f27bb3d82dc74e4afc2d5 Mon Sep 17 00:00:00 2001 From: onefang Date: Sat, 24 Jul 2021 01:09:50 +1000 Subject: First hack at grouping sims in tmux tabs. Tmux panes are a pain, so this needs more work. --- src/sledjchisl/sledjchisl.c | 124 +++++++++++++++++++++++++++++--------------- 1 file changed, 81 insertions(+), 43 deletions(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 54adecd..9c4957a 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -713,6 +713,7 @@ struct _simData // portH is the HTTP port for the sim, portI is the UDP port for the sim. int num, locX, locY, sizeX, sizeY, sizeZ, portH, portI, maxPrims; char *name, *tab, *UUID, *regionType, *estate, *owner; + int win, pane; // char *nmbr; }; @@ -6961,24 +6962,23 @@ jit library is loaded or the JIT compiler will not be activated. if (strcmp(pw->pw_name, scUser) == 0) { snprintf(toybuf, sizeof(toybuf), - "%s %s/%s new-session -d -s %s -n '%s' \\; split-window -bhp 50 -t '%s:' bash -c '/usr/bin/valgrind --leak-check=full ./sledjchisl; cd %s; bash'", - "; select-pane -t 0 -T 'SledjChisl'; select-pane -t 1 -T 'ROBUST'", - Tcmd, scRun, Tsocket, Tconsole, Ttab, Tconsole, scRoot); + "%s %s/%s new-session -d -s %s -n '%s' \\; split-window -vp 50 -t '%s:' bash -c '/usr/bin/valgrind --leak-check=full ./sledjchisl; cd %s; bash'", + Tcmd, scRun, Tsocket, Tconsole, Ttab, Tconsole, scRoot); } else { // The sudo is only so that the session is owned by opensim, otherwise it's owned by whoever ran this script, which is a likely security hole. // After the session is created, we rely on the scRun directory to be group sticky, so that anyone in the opensim group can attach to the tmux socket. snprintf(toybuf, sizeof(toybuf), - "sudo -Hu %s %s %s/%s new-session -d -s %s -n '%s' \\; split-window -bhp 50 -t '%s:' bash -c '/usr/bin/valgrind --leak-check=full ./sledjchisl; cd %s; bash'", - scUser, Tcmd, scRun, Tsocket, Tconsole, Ttab, Tconsole, scRoot); + "sudo -Hu %s %s %s/%s new-session -d -s %s -n '%s' \\; split-window -vp 50 -t '%s:' bash -c '/usr/bin/valgrind --leak-check=full ./sledjchisl; cd %s; bash'", + scUser, Tcmd, scRun, Tsocket, Tconsole, Ttab, Tconsole, scRoot); } i = system(toybuf); if (!WIFEXITED(i)) E("tmux new-session command failed! %s", toybuf); else { - snprintf(toybuf, sizeof(toybuf), "%s %s/%s select-pane -t 0 -T 'SledjChisl'", Tcmd, scRun, Tsocket); + snprintf(toybuf, sizeof(toybuf), "%s %s/%s select-pane -t 1 -T 'SledjChisl'", Tcmd, scRun, Tsocket); i = system(toybuf); if (!WIFEXITED(i)) E("tmux select-pane command failed!"); @@ -7554,11 +7554,12 @@ fcgiDone: /* sims = -- Note these are .shini / tmux tab short names. { - {["type"] = "Important"; "Welcome", "Sandbox", "Shops"}, + {['type'] = 'Welcome'; ['panes'] = 0; "Welcome"}, + {["type"] = "Important"; ["panes"] = 2; "Sandbox", "Shops"}, {["type"] = "Rentals"; "Karen", "Bob"}, {["type"] = "Freebies"; "Gifts", "Free"}, {["type"] = "unsorted"; "New"}, -- NOTE - this is where new ones go to by default. - {["type"] = "Water"; ["number"] = 90; "Water0", "Water1", "Water2", "Water3", "Water4"}, + {["type"] = "Water"; ["number"] = 90; ["panes"] = 6; "Water0", "Water1", "Water2", "Water3", "Water4"}, {["type"] = "Heavies"; ["number"] = 70; "DP", "ARSE"}, } */ @@ -7587,14 +7588,22 @@ sims = -- Note these are .shini / tmux tab short names. if (lua_istable(L, -1)) { const char *type = "unsorted"; + int panes = 4, win = 0, startNum = 0, pane = 0; lua_getfield(L, -1, "type"); lua_getfield(L, -2, "number"); - if (LUA_TNIL != lua_type(L, -2)) type = lua_tostring(L, -2); - if (LUA_TNIL != lua_type(L, -1)) number = lua_tonumber(L, -1); - lua_pop(L, 2); + lua_getfield(L, -3, "panes"); + if (LUA_TNIL != lua_type(L, -3)) type = lua_tostring(L, -3); + if (LUA_TNIL != lua_type(L, -2)) number = lua_tonumber(L, -2); + if (LUA_TNIL != lua_type(L, -1)) panes = lua_tonumber(L, -1); + lua_pop(L, 3); + startNum = number; + if (panes) + win = startNum - 1; + else + pane = 2; - T("Doing sims of type %s starting at number %d", type, number); + T("Doing sims of type %s starting at number %d, window %d, %d panes per window", type, startNum, win, panes); lua_pushnil(L); while(lua_next(L, -2) != 0) { @@ -7617,6 +7626,8 @@ sims = -- Note these are .shini / tmux tab short names. simd = ini->get(ini, "SIM DATA", NULL, false); name = simd->name; nm = simd->tab; + simd->win = win; + simd->pane = pane; } if (NULL != target) @@ -7676,34 +7687,52 @@ sims = -- Note these are .shini / tmux tab short names. E("sed command failed!"); free(cmd); - I("%s is starting up in tab [%d:%s], from %s/sim%d. %i %i", name, number, nm, scTemp, number, doWait, count); + I("%s is starting up in tab [%d:%s] pane .%d, from %s/sim%d.", name, win, type, pane, scTemp, number); memset(toybuf, 0, sizeof(toybuf)); - snprintf(toybuf, sizeof(toybuf), "%s %s/%s new-window -dn '%s' -t '%s:%d' 'cd %s/current/bin; mono OpenSim.exe -inidirectory=%s/sim%d'", - Tcmd, scRun, Tsocket, nm, Tconsole, number, scRoot, scTemp, number); - int r = system(toybuf); - if (!WIFEXITED(r)) - E("tmux new-window command failed!"); - else + if (0 == panes) + doTmuxCmd("split-window -hp 50 -d -t '%s:0.1'", Tconsole); + else if (0 == pane) + { + doTmuxCmd("new-window -dc '%s/current/bin' -n '%s' -t '%s:%d'", scRoot, type, Tconsole, win); + if (2 <= panes) + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, win); + if (4 <= panes) + { + doTmuxCmd("split-window -vp 50 -d -t '%s:%d.1'", Tconsole, win); + doTmuxCmd("split-window -vp 50 -d -t '%s:%d.0'", Tconsole, win); + } + if (8 <= panes) + { + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.3'", Tconsole, win); + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.2'", Tconsole, win); + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.1'", Tconsole, win); + doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, win); + } +/* +tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pane_index} #{pane_id}' +0 %39 +1 %42 +2 %40 +3 %41 +*/ + } + cmd = xmprintf("%d.%d", simd->win, simd->pane); + doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, cmd, nm); { - snprintf(toybuf, sizeof(toybuf), "%s %s/%s select-pane -t %s.0 -T '%s'", Tcmd, scRun, Tsocket, nm, name); - r = system(toybuf); - if (!WIFEXITED(r)) - E("tmux select-pane command failed!"); - else + memset(toybuf, 0, sizeof(toybuf)); + snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d; exit", scTemp, number); + sendTmuxCmd(cmd, toybuf); + if (0 == doWait) { - if (0 == doWait) - { - memset(toybuf, 0, sizeof(toybuf)); - snprintf(toybuf, sizeof(toybuf), "INITIALIZATION COMPLETE FOR %s", name); - waitTmuxText(nm, toybuf); - I("%s is done starting up.", name); - la = waitLoadAverage(la, loadAverageInc, simTimeOut); - } - else - I("Not waiting for %s to finish starting up.", name); - count++; + memset(toybuf, 0, sizeof(toybuf)); + snprintf(toybuf, sizeof(toybuf), "INITIALIZATION COMPLETE FOR %s", name); + waitTmuxText(cmd, toybuf); + I("%s is done starting up.", name); + la = waitLoadAverage(la, loadAverageInc, simTimeOut); } + count++; } + free(cmd); free(newPath); free(path); } @@ -7718,6 +7747,7 @@ sims = -- Note these are .shini / tmux tab short names. time_t curtime; char date[DATE_TIME_LEN]; + cmd = xmprintf("%d.%d", simd->win, simd->pane); // TODO - should collect names of existing backups, both tmux / ini name and proper name. // Scan backups directory once before this for loop, add details to sims list. @@ -7729,17 +7759,18 @@ sims = -- Note these are .shini / tmux tab short names. I("%s is being backed up to %s/backups/%s-%s.oar.", name, scRoot, nm, date); memset(toybuf, 0, sizeof(toybuf)); snprintf(toybuf, sizeof(toybuf), "save oar --all %s/backups/%s-%s.oar", scRoot, nm, date); - sendTmuxCmd(nm, toybuf); + sendTmuxCmd(cmd, toybuf); // if (0 == doWait) { memset(toybuf, 0, sizeof(toybuf)); snprintf(toybuf, sizeof(toybuf), "Finished writing out OAR for %s", name); - waitTmuxText(nm, toybuf); + waitTmuxText(cmd, toybuf); I("%s is done backing up.", name); // TODO - should delete / gitAR the old ones now. // Have a config option for delete / gitAR. la = waitLoadAverage(la, loadAverageInc, simTimeOut); } + free(cmd); } break; } @@ -7763,8 +7794,10 @@ sims = -- Note these are .shini / tmux tab short names. { if (checkSimIsRunning(nm)) { - I("%s is stopping.", name); - sendTmuxCmd(nm, "quit"); + cmd = xmprintf("%d.%d", simd->win, simd->pane); + I("%s is stopping in pane .", name, simd->win, simd->pane); + sendTmuxCmd(cmd, "quit"); + free(cmd); // There's three things that might happen - // Sim will quit, tmux tab will go away before we can see the shutdown message. // Sim will quit, tmux tab wont go away. Dunno yet if waitTmuxText() will still work. @@ -7789,7 +7822,13 @@ sims = -- Note these are .shini / tmux tab short names. } nextSim: number++; -//if (2 < number) break; + if (panes) + { + pane = (number - startNum) % panes; + if (0 == pane) + win++; + } +//if (4 < number) break; } lua_pop(L, 1); // removes 'value'; keeps 'key' for next iteration } @@ -7802,12 +7841,11 @@ nextSim: } - if ((START == currentMode) && checkSimIsRunning("ROBUST") && (NULL == target)) { // Start up the web stuff. TODO - remove this once we handle the fcgi stuff ourselves. - T("Starting the web stuff."); - char *d = xmprintf("%s.{left}", Ttab); + I("Starting the web stuff."); + char *d = xmprintf("%s.{bottom}", Ttab); char *c = xmprintf("cd %s/current/src;" " spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- " "/usr/bin/valgrind --leak-check=full build/toybox/generated/unstripped/toybox sledjchisl", -- cgit v1.1