aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--src/sledjchisl/sledjchisl.c193
1 files changed, 122 insertions, 71 deletions
diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c
index e6caa67..42d4547 100644
--- a/src/sledjchisl/sledjchisl.c
+++ b/src/sledjchisl/sledjchisl.c
@@ -713,7 +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 int window, pane;
717// char *nmbr; 717// char *nmbr;
718}; 718};
719 719
@@ -877,6 +877,11 @@ ourSims->tbl->put(ourSims->tbl, sim, ini, sizeof(qlisttbl_t));
877 " -e 's#\\[Const]#\\[Const] ; fakeVariableCozOpenSim='' ; pushd ../current/bin; ./sledjchisl $1 `basename $0`; popd ; exit 0#'" 877 " -e 's#\\[Const]#\\[Const] ; fakeVariableCozOpenSim='' ; pushd ../current/bin; ./sledjchisl $1 `basename $0`; popd ; exit 0#'"
878 " -e 's/mysim=\"[[:digit:]]*\"/mysim=\"%s\"/'" 878 " -e 's/mysim=\"[[:digit:]]*\"/mysim=\"%s\"/'"
879 " -e 's/sim\\$\\{Const\\|mysim\\}/\\$\\{Const\\|mysim\\}/g'" 879 " -e 's/sim\\$\\{Const\\|mysim\\}/\\$\\{Const\\|mysim\\}/g'"
880 " -e '/\\[Startup\\]/d'"
881 " -e '/PIDFile.*/d'"
882 " -e '/LogFile.*/d'"
883 " -e '/StatsLogFile.*/d'"
884 " -e '/ConsoleHistoryFile.*/d'"
880 " %s >%s", simd->tab, path, newPath); 885 " %s >%s", simd->tab, path, newPath);
881 886
882 I("Writing .shini file %s", newPath); 887 I("Writing .shini file %s", newPath);
@@ -7569,15 +7574,15 @@ sims = -- Note these are .shini / tmux tab short names.
7569 {["type"] = "Rentals"; "Karen", "Bob"}, 7574 {["type"] = "Rentals"; "Karen", "Bob"},
7570 {["type"] = "Freebies"; "Gifts", "Free"}, 7575 {["type"] = "Freebies"; "Gifts", "Free"},
7571 {["type"] = "unsorted"; "New"}, -- NOTE - this is where new ones go to by default. 7576 {["type"] = "unsorted"; "New"}, -- NOTE - this is where new ones go to by default.
7572 {["type"] = "Water"; ["number"] = 90; ["panes"] = 6; "Water0", "Water1", "Water2", "Water3", "Water4"}, 7577 {["type"] = "Water"; ["number"] = 20; ["panes"] = 6; "Water0", "Water1", "Water2", "Water3", "Water4"},
7573 {["type"] = "Heavies"; ["number"] = 70; "DP", "ARSE"}, 7578 {["type"] = "Heavies"; ["number"] = 18; "DP", "ARSE"},
7574} 7579}
7575*/ 7580*/
7576 memset(toybuf, 0, sizeof(toybuf)); 7581 memset(toybuf, 0, sizeof(toybuf));
7577 snprintf(toybuf, sizeof(toybuf), "%s/sims.lua", scEtc); 7582 snprintf(toybuf, sizeof(toybuf), "%s/sims.lua", scEtc);
7578 if (0 == lstat(toybuf, &st)) 7583 if (0 == lstat(toybuf, &st))
7579 { 7584 {
7580 int number = 1, count = 1; 7585 int count = 0, window = 0, panes = 4, pane = 0;
7581 7586
7582 I("Loading configuration file - %s", toybuf); 7587 I("Loading configuration file - %s", toybuf);
7583 status = luaL_loadfile(L, toybuf); 7588 status = luaL_loadfile(L, toybuf);
@@ -7598,22 +7603,27 @@ sims = -- Note these are .shini / tmux tab short names.
7598 if (lua_istable(L, -1)) 7603 if (lua_istable(L, -1))
7599 { 7604 {
7600 const char *type = "unsorted"; 7605 const char *type = "unsorted";
7601 int panes = 4, win = 0, startNum = 0, pane = 0;
7602 7606
7607 panes = 4;
7603 lua_getfield(L, -1, "type"); 7608 lua_getfield(L, -1, "type");
7604 lua_getfield(L, -2, "number"); 7609 lua_getfield(L, -2, "number");
7605 lua_getfield(L, -3, "panes"); 7610 lua_getfield(L, -3, "panes");
7606 if (LUA_TNIL != lua_type(L, -3)) type = lua_tostring(L, -3); 7611 if (LUA_TNIL != lua_type(L, -3)) type = lua_tostring(L, -3);
7607 if (LUA_TNIL != lua_type(L, -2)) number = lua_tonumber(L, -2); 7612 if (LUA_TNIL != lua_type(L, -2)) window = lua_tonumber(L, -2) - 1;
7608 if (LUA_TNIL != lua_type(L, -1)) panes = lua_tonumber(L, -1); 7613 if (LUA_TNIL != lua_type(L, -1)) panes = lua_tonumber(L, -1);
7609 lua_pop(L, 3); 7614 lua_pop(L, 3);
7610 startNum = number; 7615 if (0 == panes)
7611 if (panes) 7616 {
7612 win = startNum - 1;
7613 else
7614 pane = 2; 7617 pane = 2;
7618 window = 0;
7619 }
7620 else if (0 != pane)
7621 {
7622 pane = 0;
7623 window++;
7624 }
7615 7625
7616 T("Doing sims of type %s starting at number %d, window %d, %d panes per window", type, startNum, win, panes); 7626 T("Doing sims of type %s, window %d, %d panes per window", type, window, panes);
7617 lua_pushnil(L); 7627 lua_pushnil(L);
7618 while(lua_next(L, -2) != 0) 7628 while(lua_next(L, -2) != 0)
7619 { 7629 {
@@ -7636,7 +7646,7 @@ sims = -- Note these are .shini / tmux tab short names.
7636 simd = ini->get(ini, "SIM DATA", NULL, false); 7646 simd = ini->get(ini, "SIM DATA", NULL, false);
7637 name = simd->name; 7647 name = simd->name;
7638 nm = simd->tab; 7648 nm = simd->tab;
7639 simd->win = win; 7649 simd->window = window;
7640 simd->pane = pane; 7650 simd->pane = pane;
7641 } 7651 }
7642 7652
@@ -7660,14 +7670,13 @@ sims = -- Note these are .shini / tmux tab short names.
7660 if (strcmp(target, toybuf) == 0) 7670 if (strcmp(target, toybuf) == 0)
7661 cont = FALSE; 7671 cont = FALSE;
7662 memset(toybuf, 0, sizeof(toybuf)); 7672 memset(toybuf, 0, sizeof(toybuf));
7663 snprintf(toybuf, sizeof(toybuf), "sim%d.ini", number); 7673 snprintf(toybuf, sizeof(toybuf), "sim%d.ini", count);
7664 if (strcmp(target, toybuf) == 0) 7674 if (strcmp(target, toybuf) == 0)
7665 cont = FALSE; 7675 cont = FALSE;
7666 if (cont) 7676 if (cont)
7667 goto nextSim; 7677 goto nextSim;
7668 } 7678 }
7669 7679
7670 doWait = (count % bulkSims);
7671 switch (currentMode) 7680 switch (currentMode)
7672 { 7681 {
7673 case START : // "start sim01" "start 'Welcome sim'" "start Welcome.ini" "start Welcome" "start" start everything 7682 case START : // "start sim01" "start 'Welcome sim'" "start Welcome.ini" "start Welcome" "start" start everything
@@ -7675,62 +7684,91 @@ sims = -- Note these are .shini / tmux tab short names.
7675 if (!checkSimIsRunning(nm)) 7684 if (!checkSimIsRunning(nm))
7676 { 7685 {
7677 char *path = xmprintf("%s/%s.shini", scEtc, nm); 7686 char *path = xmprintf("%s/%s.shini", scEtc, nm);
7678 char *newPath = xmprintf("%s/sim%d/%s.ini", scTemp, number, nm); // Coz OpenSim. 7687 char *newPath = xmprintf("%s/sim%d/%s.ini", scTemp, count, nm); // Coz OpenSim.
7679 char *cmd = xmprintf("rm -fr %s/sim%d; mkdir -p %s/sim%d; sed -E"
7680 " -e 's/InternalPort[[:space:]]*=[[:space:]]*[[:digit:]]+/InternalPort = %d/'"
7681 " -e 's/InternalPort[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/InternalPort = %d/'"
7682 " -e 's/http_listener_port[[:space:]]*=[[:space:]]*[[:digit:]]+/http_listener_port = %d/'"
7683 " -e 's/http_listener_port[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/http_listener_port = %d/'"
7684 " %s >%s",
7685 scTemp, number,
7686 scTemp, number,
7687 8004 + number * 2,
7688 8004 + number * 2,
7689 8005 + number * 2,
7690 8005 + number * 2,
7691 path, newPath);
7692 int j;
7693
7694 D("Writing .ini file %s with ports %d %d", newPath, 8004 + number * 2, 8005 + number * 2);
7695 j = system(cmd);
7696 if (!WIFEXITED(j))
7697 E("sed command failed!");
7698 free(cmd);
7699 7688
7700 I("%s is starting up in tab [%d:%s] pane .%d, from %s/sim%d.", name, win, type, pane, scTemp, number);
7701 memset(toybuf, 0, sizeof(toybuf)); 7689 memset(toybuf, 0, sizeof(toybuf));
7702 if (0 == panes) 7690 if (0 == panes)
7703 doTmuxCmd("split-window -hp 50 -d -t '%s:0.1'", Tconsole); 7691 doTmuxCmd("split-window -hp 50 -d -t '%s:0.1'", Tconsole);
7704 else if (0 == pane) 7692 else if (0 == pane)
7705 { 7693 {
7706 doTmuxCmd("new-window -dc '%s/current/bin' -n '%s' -t '%s:%d'", scRoot, type, Tconsole, win); 7694 doTmuxCmd("new-window -dc '%s/current/bin' -n '%s' -t '%s:%d'", scRoot, type, Tconsole, window);
7707 if (2 <= panes) 7695 if (2 <= panes)
7708 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, win); 7696 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, window);
7709 if (4 <= panes) 7697 if (4 <= panes)
7710 { 7698 {
7711 doTmuxCmd("split-window -vp 50 -d -t '%s:%d.1'", Tconsole, win); 7699 doTmuxCmd("split-window -vp 50 -d -t '%s:%d.1'", Tconsole, window);
7712 doTmuxCmd("split-window -vp 50 -d -t '%s:%d.0'", Tconsole, win); 7700 doTmuxCmd("split-window -vp 50 -d -t '%s:%d.0'", Tconsole, window);
7713 } 7701 }
7714 if (8 <= panes) 7702 if (8 <= panes)
7715 { 7703 {
7716 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.3'", Tconsole, win); 7704 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.3'", Tconsole, window);
7717 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.2'", Tconsole, win); 7705 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.2'", Tconsole, window);
7718 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.1'", Tconsole, win); 7706 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.1'", Tconsole, window);
7719 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, win); 7707 doTmuxCmd("split-window -hp 50 -d -t '%s:%d.0'", Tconsole, window);
7720 } 7708 }
7721/* 7709/* TODO -
7722tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pane_index} #{pane_id}' 7710tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pane_index} #{pane_id}'
77230 %39 77110 %39
77241 %42 77121 %42
77252 %40 77132 %40
77263 %41 77143 %41
7715
7716I can get the tabs to show their ID. session:window.pane $sessionID $=ExactSessionMatch @windowID @=ExactWindowMatch %paneID
7717 "The pane ID is passed to the child process of the pane in the TMUX_PANE environment variable."
7718 Tuck the window and pane ID into the tmp ini file we are about to make, so other runs of sledjchisl can find it.
7719
7720Leave empty panes as is.
7721Don't bother to close panes unless we are doing a full stop.
7722
7723Is there a "switch to pane 1" command? Nope
7724 Ctrc A digit Move to that numbered window.
7725 Ctrl A arrow key Move to the pane in that direction.
7726 Ctrl A n Move to the next window.
7727 Ctrl A p Move to the previous window.
7728 Ctrl A w Choose the current window interactively.
7729 Ctrl A o Move to the next pane.
7730 Ctrl A ; Move to the previously selected pane.
7731 Ctrl A l Move to the previously selected window.
7732 Ctrl A Ctrl o Rotate panes"forwards". I do this accidently sometimes, coz MC.
7733 Ctrl A Alt o Rotate panes"backwards".
7734 Ctrl A z Toggle zooming into the current pane.
7727*/ 7735*/
7728 } 7736 }
7729 cmd = xmprintf("%d.%d", simd->win, simd->pane); 7737 I("%s is starting up in tab [%d:%s] pane .%d, from %s/sim%d.", name, window, type, pane, scTemp, count);
7738
7739 char *cmd = xmprintf("rm -fr %s/sim%d; mkdir -p %s/sim%d; sed -E"
7740 " -e 's@\\[Region\\]@"
7741 "\\[Startup\\]\\n"
7742 " PIDFile = \"\\$\\{Paths\\|CachePath\\}\\/\\$\\{Const\\|mysim\\}\\.pid\"\\n"
7743 " LogFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSim_\\$\\{Const\\|mysim\\}\\.log\"\\n"
7744 " StatsLogFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSimStats_\\$\\{Const\\|mysim\\}\\.log\"\\n"
7745 " ConsoleHistoryFile = \"\\$\\{Paths\\|LogPath\\}\\/OpenSimConsoleHistory_\\$\\{Const\\|mysim\\}\\.txt\"\\n"
7746 "\\n\\[Region\\]@'"
7747 " -e 's/InternalPort[[:space:]]*=[[:space:]]*[[:digit:]]+/InternalPort = %d/'"
7748 " -e 's/InternalPort[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/InternalPort = %d/'"
7749 " -e 's/http_listener_port[[:space:]]*=[[:space:]]*[[:digit:]]+/http_listener_port = %d/'"
7750 " -e 's/http_listener_port[[:space:]]*=[[:space:]]*\"[[:digit:]]+\"/http_listener_port = %d/'"
7751 " %s >%s",
7752 scTemp, count,
7753 scTemp, count,
7754 8004 + count * 2,
7755 8004 + count * 2,
7756 8005 + count * 2,
7757 8005 + count * 2,
7758 path, newPath);
7759 int j;
7760
7761 D("Writing .ini file %s with ports %d %d", newPath, 8004 + count * 2, 8005 + count * 2);
7762 j = system(cmd);
7763 if (!WIFEXITED(j))
7764 E("sed command failed!");
7765 free(cmd);
7766
7767 cmd = xmprintf("%d.%d", simd->window, simd->pane);
7730 doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, cmd, nm); 7768 doTmuxCmd("select-pane -t %s:%s -T '%s'", Tconsole, cmd, nm);
7731 { 7769 {
7732 memset(toybuf, 0, sizeof(toybuf)); 7770 memset(toybuf, 0, sizeof(toybuf));
7733 snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d; exit", scTemp, number); 7771 snprintf(toybuf, sizeof(toybuf), "mono OpenSim.exe -inidirectory=%s/sim%d", scTemp, count);
7734 sendTmuxCmd(cmd, toybuf); 7772 sendTmuxCmd(cmd, toybuf);
7735 if (0 == doWait) 7773 if (0 == doWait)
7736 { 7774 {
@@ -7741,6 +7779,7 @@ tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pa
7741 la = waitLoadAverage(la, loadAverageInc, simTimeOut); 7779 la = waitLoadAverage(la, loadAverageInc, simTimeOut);
7742 } 7780 }
7743 count++; 7781 count++;
7782 doWait = (count % bulkSims);
7744 } 7783 }
7745 free(cmd); 7784 free(cmd);
7746 free(newPath); 7785 free(newPath);
@@ -7757,7 +7796,7 @@ tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pa
7757 time_t curtime; 7796 time_t curtime;
7758 char date[DATE_TIME_LEN]; 7797 char date[DATE_TIME_LEN];
7759 7798
7760 cmd = xmprintf("%d.%d", simd->win, simd->pane); 7799 cmd = xmprintf("%d.%d", simd->window, simd->pane);
7761 7800
7762// TODO - should collect names of existing backups, both tmux / ini name and proper name. 7801// TODO - should collect names of existing backups, both tmux / ini name and proper name.
7763// Scan backups directory once before this for loop, add details to sims list. 7802// Scan backups directory once before this for loop, add details to sims list.
@@ -7804,14 +7843,16 @@ tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pa
7804 { 7843 {
7805 if (checkSimIsRunning(nm)) 7844 if (checkSimIsRunning(nm))
7806 { 7845 {
7807 cmd = xmprintf("%d.%d", simd->win, simd->pane); 7846 cmd = xmprintf("%d.%d", simd->window, simd->pane);
7808 I("%s is stopping in pane .", name, simd->win, simd->pane); 7847 I("%s is stopping in pane %d.%d.", name, simd->window, simd->pane);
7809 sendTmuxCmd(cmd, "quit"); 7848 sendTmuxCmd(cmd, "quit");
7810 free(cmd); 7849 free(cmd);
7811 // There's three things that might happen - 7850 // There's three things that might happen -
7812 // Sim will quit, tmux tab will go away before we can see the shutdown message. 7851 // Sim will quit, tmux pane will go away before we can see the shutdown message.
7813 // Sim will quit, tmux tab wont go away. Dunno yet if waitTmuxText() will still work. 7852 // pane-exited hook might be useful here.
7814 // Sim fails to quit, error message on the tab that we want to read, wont see the shutdown message. 7853 // Sim will quit, tmux pane wont go away. Dunno yet if waitTmuxText() will still work.
7854 // pane-died hook might be useful here.
7855 // Sim fails to quit, error message on the pane that we want to read, wont see the shutdown message.
7815 // Also sim might not have finished starting up, and may even not be accepting comands yet. 7856 // Also sim might not have finished starting up, and may even not be accepting comands yet.
7816 // TODO - cater for and test them all. 7857 // TODO - cater for and test them all.
7817 // Could also loop on checkSimIsRunning(sim) 7858 // Could also loop on checkSimIsRunning(sim)
@@ -7831,12 +7872,14 @@ tmux -S /opt/opensim_SC-DG/var/run/opensim-tmux.socket list-panes -t 31 -F '#{pa
7831 } 7872 }
7832 } 7873 }
7833nextSim: 7874nextSim:
7834 number++; 7875// if (panes)
7835 if (panes)
7836 { 7876 {
7837 pane = (number - startNum) % panes; 7877 pane++;
7838 if (0 == pane) 7878 if (pane >= panes)
7839 win++; 7879 {
7880 pane = 0;
7881 window++;
7882 }
7840 } 7883 }
7841//if (4 < number) break; 7884//if (4 < number) break;
7842 } 7885 }
@@ -7851,21 +7894,29 @@ nextSim:
7851 } 7894 }
7852 7895
7853 7896
7854 if ((START == currentMode) && checkSimIsRunning("ROBUST") && (NULL == target)) 7897 if (START == currentMode)
7855 { 7898 {
7856 // Start up the web stuff. TODO - remove this once we handle the fcgi stuff ourselves. 7899 if (checkSimIsRunning("ROBUST") && (NULL == target))
7857 I("Starting the web stuff."); 7900 {
7858 char *d = xmprintf("%s.{bottom}", Ttab); 7901 // Start up the web stuff. TODO - remove this once we handle the fcgi stuff ourselves.
7859 char *c = xmprintf("cd %s/current/src;" 7902 I("Starting the web stuff.");
7860 " spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- " 7903 char *d = xmprintf("%s.{bottom}", Ttab);
7861 "/usr/bin/valgrind --leak-check=full build/toybox/generated/unstripped/toybox sledjchisl", 7904 char *c = xmprintf("cd %s/current/src;"
7862 scRoot, scUser, scCache); 7905 " spawn-fcgi -n -u %s -s %s/sledjchisl.socket -M 0660 -G www-data -- "
7863 sendTmuxCmd(d, c); 7906 "/usr/bin/valgrind --leak-check=full build/toybox/generated/unstripped/toybox sledjchisl",
7864 free(c); 7907 scRoot, scUser, scCache);
7865 free(d); 7908 sendTmuxCmd(d, c);
7909 free(c);
7910 free(d);
7911 }
7912 else
7913 I("NOT Starting the web stuff.");
7914 }
7915 else if ((STOP == currentMode) && (NULL == target))
7916 {
7917I("Closing all the panes.");
7918// TODO - Wait for all the sims to stop, close all the sim panes, even the empty ones.
7866 } 7919 }
7867 else
7868 I("NOT Starting the web stuff.");
7869 7920
7870 7921
7871/* 7922/*