From 7738de6f011821e26d0e9b6a24caccaca8a300fe Mon Sep 17 00:00:00 2001 From: onefang Date: Sat, 4 Jun 2022 09:47:44 +1000 Subject: Add a web option to sledjchisl, to start the web stuff. --- src/sledjchisl/sledjchisl.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/src/sledjchisl/sledjchisl.c b/src/sledjchisl/sledjchisl.c index 3a99afa..317d079 100644 --- a/src/sledjchisl/sledjchisl.c +++ b/src/sledjchisl/sledjchisl.c @@ -65,6 +65,8 @@ config SLEDJCHISL stop "Welcome sim" Stop a sim, or everything. -a when stopping everything will close down all tmux windows and panes. + web + Only start the web server part. build Rebuild everything. test @@ -167,10 +169,11 @@ typedef enum RESTART = 3, STATUS = 4, BUILD = 5, - TEST = 6, - UNGITAR = 7, - UPDATE = 8, - STOP = 9 + WEB = 6, + TEST = 7, + UNGITAR = 8, + UPDATE = 9, + STOP = 10 } modes; modes currentMode = START; @@ -183,6 +186,7 @@ char *modeStrings[] = "restart", "status", "build", + "web", "test", "ungitAR", "update", @@ -2866,6 +2870,7 @@ byTab has the short name as the key, simData as the value. } case BUILD : + case WEB : { // Done elsewhere. break; @@ -8594,6 +8599,8 @@ void sledjchisl_main(void) currentMode = STATUS; else if (strcmp(toys.optargs[0], "build") == 0) currentMode = BUILD; + else if (strcmp(toys.optargs[0], "web") == 0) + currentMode = WEB; else if (strcmp(toys.optargs[0], "test") == 0) currentMode = TEST; else if (strcmp(toys.optargs[0], "ungitar") == 0) @@ -8888,7 +8895,7 @@ Copy correct config/config.ini to there. V("Not running inside the proper tmux server. %s == %s", eTMUX, toybuf); } - if (!isTmux) + if ((!isTmux) && (WEB != currentMode)) { // Let's see if the proper tmux server is even running. i = shellMe("%s %s/%s -q list-sessions 2>/dev/null | grep -q %s:", Tcmd, scRun, Tsocket, Tconsole); if (WIFEXITED(i)) @@ -8928,7 +8935,7 @@ Copy correct config/config.ini to there. // Make the FCGI socket world read / write, coz we can't set it to group www-data, since -G only works for root, and we ain't root. // TODO - BIG SECURITY HOLE??? "bash -c 'export PATH=%s:$PATH; printf \"\\033]0;FCGI web server\\007\"; sleep 2;" // The sleep is so that both are not creating the .shini files at the same time. - "spawn-fcgi -n -u %s -s %s/%s -M 0666 -G www-data -- /usr/bin/valgrind --leak-check=full %s/current/bin/sledjchisl %s; " + "/usr/bin/valgrind --leak-check=full %s/current/bin/sledjchisl web %s;" "cd %s; bash'" , pre, Tcmd, scRun, Tsocket, scBin, @@ -8938,7 +8945,7 @@ Copy correct config/config.ini to there. Tconsole, Tconsole, scBin, - scUser, scRun, webSocket, scRoot, FLAG(v) ? "-v" : "", + scRoot, FLAG(v) ? "-v" : "", scRoot ); free(pre); @@ -8961,6 +8968,21 @@ Copy correct config/config.ini to there. E("tmux list-sessions command failed! %s", toybuf); } +// TODO - doesn't solve the "rebuild sledjchisl, replace sledjchisl, restart web server" problem, coz there's still two sledjchisl running, the one that started the tmux, and the one running the tmux. +// But the simple solution of just running things in the background didn't help. +// So spend more time fixing all of that. Later. Need around tuit. + if ((!isWeb) && (WEB == currentMode)) + { + C("Spawning web server via spawn-fcgi"); + snprintf(toybuf, sizeof(toybuf), + "spawn-fcgi -n -u %s -s %s/%s -M 0666 -G www-data -- /usr/bin/valgrind --leak-check=full %s/current/bin/sledjchisl %s", + scUser, scRun, webSocket, scRoot, FLAG(v) ? "-v" : "" + ); + if (shellMeFail(toybuf)) + E("spawn-fcgi command failed! %s", toybuf); + goto finished; + } + if ((!isWeb) && ((BUILD == currentMode) || (START == currentMode))) { //////////////////////////////////////////////////////////////////////////////////////////////////// -- cgit v1.1