diff options
author | onefang | 2021-07-24 01:09:50 +1000 |
---|---|---|
committer | onefang | 2021-07-24 01:09:50 +1000 |
commit | 0657d65d79ad308cd45f27bb3d82dc74e4afc2d5 (patch) | |
tree | f63fab934c125bd6f7827d05c4fe8f87607d1f6a /src/sledjchisl/sledjchisl.c | |
parent | One more logging level change. (diff) | |
download | opensim-SC-0657d65d79ad308cd45f27bb3d82dc74e4afc2d5.zip opensim-SC-0657d65d79ad308cd45f27bb3d82dc74e4afc2d5.tar.gz opensim-SC-0657d65d79ad308cd45f27bb3d82dc74e4afc2d5.tar.bz2 opensim-SC-0657d65d79ad308cd45f27bb3d82dc74e4afc2d5.tar.xz |
First hack at grouping sims in tmux tabs.
Tmux panes are a pain, so this needs more work.
Diffstat (limited to '')
-rw-r--r-- | src/sledjchisl/sledjchisl.c | 124 |
1 files 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 | |||
713 | // portH is the HTTP port for the sim, portI is the UDP port for the sim. | 713 | // portH is the HTTP port for the sim, portI is the UDP port for the sim. |
714 | int num, locX, locY, sizeX, sizeY, sizeZ, portH, portI, maxPrims; | 714 | int num, locX, locY, sizeX, sizeY, sizeZ, portH, portI, maxPrims; |
715 | char *name, *tab, *UUID, *regionType, *estate, *owner; | 715 | char *name, *tab, *UUID, *regionType, *estate, *owner; |
716 | int win, pane; | ||
716 | // char *nmbr; | 717 | // char *nmbr; |
717 | }; | 718 | }; |
718 | 719 | ||
@@ -6961,24 +6962,23 @@ jit library is loaded or the JIT compiler will not be activated. | |||
6961 | if (strcmp(pw->pw_name, scUser) == 0) | 6962 | if (strcmp(pw->pw_name, scUser) == 0) |
6962 | { | 6963 | { |
6963 | snprintf(toybuf, sizeof(toybuf), | 6964 | snprintf(toybuf, sizeof(toybuf), |
6964 | "%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'", | 6965 | "%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'", |
6965 | "; select-pane -t 0 -T 'SledjChisl'; select-pane -t 1 -T 'ROBUST'", | 6966 | Tcmd, scRun, Tsocket, Tconsole, Ttab, Tconsole, scRoot); |
6966 | Tcmd, scRun, Tsocket, Tconsole, Ttab, Tconsole, scRoot); | ||
6967 | } | 6967 | } |
6968 | else | 6968 | else |
6969 | { | 6969 | { |
6970 | // 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. | 6970 | // 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. |
6971 | // 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. | 6971 | // 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. |
6972 | snprintf(toybuf, sizeof(toybuf), | 6972 | snprintf(toybuf, sizeof(toybuf), |
6973 | "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'", | 6973 | "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'", |
6974 | scUser, Tcmd, scRun, Tsocket, Tconsole, Ttab, Tconsole, scRoot); | 6974 | scUser, Tcmd, scRun, Tsocket, Tconsole, Ttab, Tconsole, scRoot); |
6975 | } | 6975 | } |
6976 | i = system(toybuf); | 6976 | i = system(toybuf); |
6977 | if (!WIFEXITED(i)) | 6977 | if (!WIFEXITED(i)) |
6978 | E("tmux new-session command failed! %s", toybuf); | 6978 | E("tmux new-session command failed! %s", toybuf); |
6979 | else | 6979 | else |
6980 | { | 6980 | { |
6981 | snprintf(toybuf, sizeof(toybuf), "%s %s/%s select-pane -t 0 -T 'SledjChisl'", Tcmd, scRun, Tsocket); | 6981 | snprintf(toybuf, sizeof(toybuf), "%s %s/%s select-pane -t 1 -T 'SledjChisl'", Tcmd, scRun, Tsocket); |
6982 | i = system(toybuf); | 6982 | i = system(toybuf); |
6983 | if (!WIFEXITED(i)) | 6983 | if (!WIFEXITED(i)) |
6984 | E("tmux select-pane command failed!"); | 6984 | E("tmux select-pane command failed!"); |
@@ -7554,11 +7554,12 @@ fcgiDone: | |||
7554 | /* | 7554 | /* |
7555 | sims = -- Note these are .shini / tmux tab short names. | 7555 | sims = -- Note these are .shini / tmux tab short names. |
7556 | { | 7556 | { |
7557 | {["type"] = "Important"; "Welcome", "Sandbox", "Shops"}, | 7557 | {['type'] = 'Welcome'; ['panes'] = 0; "Welcome"}, |
7558 | {["type"] = "Important"; ["panes"] = 2; "Sandbox", "Shops"}, | ||
7558 | {["type"] = "Rentals"; "Karen", "Bob"}, | 7559 | {["type"] = "Rentals"; "Karen", "Bob"}, |
7559 | {["type"] = "Freebies"; "Gifts", "Free"}, | 7560 | {["type"] = "Freebies"; "Gifts", "Free"}, |
7560 | {["type"] = "unsorted"; "New"}, -- NOTE - this is where new ones go to by default. | 7561 | {["type"] = "unsorted"; "New"}, -- NOTE - this is where new ones go to by default. |
7561 | {["type"] = "Water"; ["number"] = 90; "Water0", "Water1", "Water2", "Water3", "Water4"}, | 7562 | {["type"] = "Water"; ["number"] = 90; ["panes"] = 6; "Water0", "Water1", "Water2", "Water3", "Water4"}, |
7562 | {["type"] = "Heavies"; ["number"] = 70; "DP", "ARSE"}, | 7563 | {["type"] = "Heavies"; ["number"] = 70; "DP", "ARSE"}, |
7563 | } | 7564 | } |
7564 | */ | 7565 | */ |
@@ -7587,14 +7588,22 @@ sims = -- Note these are .shini / tmux tab short names. | |||
7587 | if (lua_istable(L, -1)) | 7588 | if (lua_istable(L, -1)) |
7588 | { | 7589 | { |
7589 | const char *type = "unsorted"; | 7590 | const char *type = "unsorted"; |
7591 | int panes = 4, win = 0, startNum = 0, pane = 0; | ||
7590 | 7592 | ||
7591 | lua_getfield(L, -1, "type"); | 7593 | lua_getfield(L, -1, "type"); |
7592 | lua_getfield(L, -2, "number"); | 7594 | lua_getfield(L, -2, "number"); |
7593 | if (LUA_TNIL != lua_type(L, -2)) type = lua_tostring(L, -2); | 7595 | lua_getfield(L, -3, "panes"); |
7594 | if (LUA_TNIL != lua_type(L, -1)) number = lua_tonumber(L, -1); | 7596 | if (LUA_TNIL != lua_type(L, -3)) type = lua_tostring(L, -3); |
7595 | lua_pop(L, 2); | 7597 | if (LUA_TNIL != lua_type(L, -2)) number = lua_tonumber(L, -2); |
7598 | if (LUA_TNIL != lua_type(L, -1)) panes = lua_tonumber(L, -1); | ||
7599 | lua_pop(L, 3); | ||
7600 | startNum = number; | ||
7601 | if (panes) | ||
7602 | win = startNum - 1; | ||
7603 | else | ||
7604 | pane = 2; | ||
7596 | 7605 | ||
7597 | T("Doing sims of type %s starting at number %d", type, number); | 7606 | T("Doing sims of type %s starting at number %d, window %d, %d panes per window", type, startNum, win, panes); |
7598 | lua_pushnil(L); | 7607 | lua_pushnil(L); |
7599 | while(lua_next(L, -2) != 0) | 7608 | while(lua_next(L, -2) != 0) |
7600 | { | 7609 | { |
@@ -7617,6 +7626,8 @@ sims = -- Note these are .shini / tmux tab short names. | |||
7617 | simd = ini->get(ini, "SIM DATA", NULL, false); | 7626 | simd = ini->get(ini, "SIM DATA", NULL, false); |
7618 | name = simd->name; | 7627 | name = simd->name; |
7619 | nm = simd->tab; | 7628 | nm = simd->tab; |
7629 | simd->win = win; | ||
7630 | simd->pane = pane; | ||
7620 | } | 7631 | } |
7621 | 7632 | ||
7622 | if (NULL != target) | 7633 | if (NULL != target) |
@@ -7676,34 +7687,52 @@ sims = -- Note these are .shini / tmux tab short names. | |||
7676 | E("sed command failed!"); | 7687 | E("sed command failed!"); |
7677 | free(cmd); | 7688 | free(cmd); |
7678 | 7689 | ||
7679 | I("%s is starting up in tab [%d:%s], from %s/sim%d. %i %i", name, number, nm, scTemp, number, doWait, count); | 7690 | I("%s is starting up in tab [%d:%s] pane .%d, from %s/sim%d.", name, win, type, pane, scTemp, number); |
7680 | memset(toybuf, 0, sizeof(toybuf)); | 7691 | memset(toybuf, 0, sizeof(toybuf)); |
7681 | 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'", | 7692 | if (0 == panes) |
7682 | Tcmd, scRun, Tsocket, nm, Tconsole, number, scRoot, scTemp, number); | 7693 | doTmuxCmd("split-window -hp 50 -d -t '%s:0.1'", Tconsole); |
7683 | int r = system(toybuf); | 7694 | else if (0 == pane) |
7684 | if (!WIFEXITED(r)) | 7695 | { |
7685 | E("tmux new-window command failed!"); | 7696 | doTmuxCmd("new-window -dc '%s/current/bin' -n '%s' -t '%s:%d'", scRoot, type, Tconsole, win); |
7686 | else | 7697 | if (2 <= panes) |
7698 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, win); | ||
7699 | if (4 <= panes) | ||
7700 | { | ||
7701 | doTmuxCmd("split-window -vp 50 -d -t '%s:%d.1'", Tconsole, win); | ||
7702 | doTmuxCmd("split-window -vp 50 -d -t '%s:%d.0'", Tconsole, win); | ||
7703 | } | ||
7704 | if (8 <= panes) | ||
7705 | { | ||
7706 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.3'", Tconsole, win); | ||
7707 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.2'", Tconsole, win); | ||
7708 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.1'", Tconsole, win); | ||
7709 | doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, win); | ||
7710 | } | ||
7711 | /* | ||
7712 | tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pane_index} #{pane_id}' | ||
7713 | 0 %39 | ||
7714 | 1 %42 | ||
7715 | 2 %40 | ||
7716 | 3 %41 | ||
7717 | */ | ||
7718 | } | ||
7719 | cmd = xmprintf("%d.%d", simd->win, simd->pane); | ||
7720 | doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, cmd, nm); | ||
7687 | { | 7721 | { |
7688 | snprintf(toybuf, sizeof(toybuf), "%s %s/%s select-pane -t %s.0 -T '%s'", Tcmd, scRun, Tsocket, nm, name); | 7722 | memset(toybuf, 0, sizeof(toybuf)); |
7689 | r = system(toybuf); | 7723 | snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d; exit", scTemp, number); |
7690 | if (!WIFEXITED(r)) | 7724 | sendTmuxCmd(cmd, toybuf); |
7691 | E("tmux select-pane command failed!"); | 7725 | if (0 == doWait) |
7692 | else | ||
7693 | { | 7726 | { |
7694 | if (0 == doWait) | 7727 | memset(toybuf, 0, sizeof(toybuf)); |
7695 | { | 7728 | snprintf(toybuf, sizeof(toybuf), "INITIALIZATION COMPLETE FOR %s", name); |
7696 | memset(toybuf, 0, sizeof(toybuf)); | 7729 | waitTmuxText(cmd, toybuf); |
7697 | snprintf(toybuf, sizeof(toybuf), "INITIALIZATION COMPLETE FOR %s", name); | 7730 | I("%s is done starting up.", name); |
7698 | waitTmuxText(nm, toybuf); | 7731 | la = waitLoadAverage(la, loadAverageInc, simTimeOut); |
7699 | I("%s is done starting up.", name); | ||
7700 | la = waitLoadAverage(la, loadAverageInc, simTimeOut); | ||
7701 | } | ||
7702 | else | ||
7703 | I("Not waiting for %s to finish starting up.", name); | ||
7704 | count++; | ||
7705 | } | 7732 | } |
7733 | count++; | ||
7706 | } | 7734 | } |
7735 | free(cmd); | ||
7707 | free(newPath); | 7736 | free(newPath); |
7708 | free(path); | 7737 | free(path); |
7709 | } | 7738 | } |
@@ -7718,6 +7747,7 @@ sims = -- Note these are .shini / tmux tab short names. | |||
7718 | time_t curtime; | 7747 | time_t curtime; |
7719 | char date[DATE_TIME_LEN]; | 7748 | char date[DATE_TIME_LEN]; |
7720 | 7749 | ||
7750 | cmd = xmprintf("%d.%d", simd->win, simd->pane); | ||
7721 | 7751 | ||
7722 | // TODO - should collect names of existing backups, both tmux / ini name and proper name. | 7752 | // TODO - should collect names of existing backups, both tmux / ini name and proper name. |
7723 | // Scan backups directory once before this for loop, add details to sims list. | 7753 | // 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. | |||
7729 | I("%s is being backed up to %s/backups/%s-%s.oar.", name, scRoot, nm, date); | 7759 | I("%s is being backed up to %s/backups/%s-%s.oar.", name, scRoot, nm, date); |
7730 | memset(toybuf, 0, sizeof(toybuf)); | 7760 | memset(toybuf, 0, sizeof(toybuf)); |
7731 | snprintf(toybuf, sizeof(toybuf), "save oar --all %s/backups/%s-%s.oar", scRoot, nm, date); | 7761 | snprintf(toybuf, sizeof(toybuf), "save oar --all %s/backups/%s-%s.oar", scRoot, nm, date); |
7732 | sendTmuxCmd(nm, toybuf); | 7762 | sendTmuxCmd(cmd, toybuf); |
7733 | // if (0 == doWait) | 7763 | // if (0 == doWait) |
7734 | { | 7764 | { |
7735 | memset(toybuf, 0, sizeof(toybuf)); | 7765 | memset(toybuf, 0, sizeof(toybuf)); |
7736 | snprintf(toybuf, sizeof(toybuf), "Finished writing out OAR for %s", name); | 7766 | snprintf(toybuf, sizeof(toybuf), "Finished writing out OAR for %s", name); |
7737 | waitTmuxText(nm, toybuf); | 7767 | waitTmuxText(cmd, toybuf); |
7738 | I("%s is done backing up.", name); | 7768 | I("%s is done backing up.", name); |
7739 | // TODO - should delete / gitAR the old ones now. | 7769 | // TODO - should delete / gitAR the old ones now. |
7740 | // Have a config option for delete / gitAR. | 7770 | // Have a config option for delete / gitAR. |
7741 | la = waitLoadAverage(la, loadAverageInc, simTimeOut); | 7771 | la = waitLoadAverage(la, loadAverageInc, simTimeOut); |
7742 | } | 7772 | } |
7773 | free(cmd); | ||
7743 | } | 7774 | } |
7744 | break; | 7775 | break; |
7745 | } | 7776 | } |
@@ -7763,8 +7794,10 @@ sims = -- Note these are .shini / tmux tab short names. | |||
7763 | { | 7794 | { |
7764 | if (checkSimIsRunning(nm)) | 7795 | if (checkSimIsRunning(nm)) |
7765 | { | 7796 | { |
7766 | I("%s is stopping.", name); | 7797 | cmd = xmprintf("%d.%d", simd->win, simd->pane); |
7767 | sendTmuxCmd(nm, "quit"); | 7798 | I("%s is stopping in pane .", name, simd->win, simd->pane); |
7799 | sendTmuxCmd(cmd, "quit"); | ||
7800 | free(cmd); | ||
7768 | // There's three things that might happen - | 7801 | // There's three things that might happen - |
7769 | // Sim will quit, tmux tab will go away before we can see the shutdown message. | 7802 | // Sim will quit, tmux tab will go away before we can see the shutdown message. |
7770 | // Sim will quit, tmux tab wont go away. Dunno yet if waitTmuxText() will still work. | 7803 | // 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. | |||
7789 | } | 7822 | } |
7790 | nextSim: | 7823 | nextSim: |
7791 | number++; | 7824 | number++; |
7792 | //if (2 < number) break; | 7825 | if (panes) |
7826 | { | ||
7827 | pane = (number - startNum) % panes; | ||
7828 | if (0 == pane) | ||
7829 | win++; | ||
7830 | } | ||
7831 | //if (4 < number) break; | ||
7793 | } | 7832 | } |
7794 | lua_pop(L, 1); // removes 'value'; keeps 'key' for next iteration | 7833 | lua_pop(L, 1); // removes 'value'; keeps 'key' for next iteration |
7795 | } | 7834 | } |
@@ -7802,12 +7841,11 @@ nextSim: | |||
7802 | } | 7841 | } |
7803 | 7842 | ||
7804 | 7843 | ||
7805 | |||
7806 | if ((START == currentMode) && checkSimIsRunning("ROBUST") && (NULL == target)) | 7844 | if ((START == currentMode) && checkSimIsRunning("ROBUST") && (NULL == target)) |
7807 | { | 7845 | { |
7808 | // Start up the web stuff. TODO - remove this once we handle the fcgi stuff ourselves. | 7846 | // Start up the web stuff. TODO - remove this once we handle the fcgi stuff ourselves. |
7809 | T("Starting the web stuff."); | 7847 | I("Starting the web stuff."); |
7810 | char *d = xmprintf("%s.{left}", Ttab); | 7848 | char *d = xmprintf("%s.{bottom}", Ttab); |
7811 | char *c = xmprintf("cd %s/current/src;" | 7849 | char *c = xmprintf("cd %s/current/src;" |
7812 | " spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- " | 7850 | " spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- " |
7813 | "/usr/bin/valgrind --leak-check=full build/toybox/generated/unstripped/toybox sledjchisl", | 7851 | "/usr/bin/valgrind --leak-check=full build/toybox/generated/unstripped/toybox sledjchisl", |