From 012e0d72fdf6337ccc34b9a75cabf924fd95d472 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 7 Jan 2021 14:26:41 -0500 Subject: [PATCH] appimage supervisor is functionally complete --- appimage/build_appimage.sh | 50 ++++++++++--- appimage/citadel.AppDir/AppRun | 2 +- appimage/citadel.AppDir/ctdlvisor | Bin 8996 -> 0 bytes appimage/citadel.AppDir/ctdlvisor.c | 73 ------------------- appimage/ctdlvisor.c | 108 ++++++++++++++++++++++++++++ 5 files changed, 149 insertions(+), 84 deletions(-) delete mode 100755 appimage/citadel.AppDir/ctdlvisor delete mode 100644 appimage/citadel.AppDir/ctdlvisor.c create mode 100644 appimage/ctdlvisor.c diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh index 1fcc7cea7..ce502807f 100755 --- a/appimage/build_appimage.sh +++ b/appimage/build_appimage.sh @@ -1,18 +1,42 @@ #!/bin/bash -CTDLROOT=../citadel +rm -fr /usr/local/citadel /usr/local/webcit +# Build libcitadel +pushd ../libcitadel || exit 1 +./bootstrap || exit 1 +./configure || exit 1 +make || exit 1 +make install || exit 1 +popd + +# Build the Citadel server +pushd ../citadel || exit 1 +./bootstrap || exit 1 +./configure --prefix=/usr/local/citadel || exit 1 +make || exit 1 +make install || exit 1 +popd + +# Build WebCit +pushd ../webcit || exit 1 +./bootstrap || exit 1 +./configure --prefix=/usr/local/webcit || exit 1 +make || exit 1 +make install || exit 1 +popd + +# Build the appimage supervisor +cc ctdlvisor.c -o ctdlvisor || exit 1 + +# Clear out our build directories rm -frv citadel.AppDir/usr mkdir -p citadel.AppDir/usr/bin mkdir -p citadel.AppDir/usr/lib -pushd citadel.AppDir -cc ctdlvisor.c -o ctdlvisor || exit 1 -popd - -for bin in $CTDLROOT/citadel/citserver $CTDLROOT/webcit/webcit +# Copy over all the libraries we used +for bin in /usr/local/citadel/citserver /usr/local/webcit/webcit do - cp -v $bin citadel.AppDir/usr/bin/ for x in `ldd $bin | awk ' { print $3 } ' | grep -v -e '^$' | grep -v 'libc.so' | grep -v 'libpthread.so' | grep -v 'libresolv.so'` do cp -v -L $x citadel.AppDir/usr/lib/ @@ -20,7 +44,13 @@ do done ldconfig -v citadel.AppDir/usr/lib -ARCH=x86_64 appimagetool citadel.AppDir/ +# Copy over our application trees +for x in citadel webcit +do + mkdir -p citadel.AppDir/usr/local/$x + rsync -va /usr/local/$x/ ./citadel.AppDir/usr/local/$x/ +done -# Hint: do this on your build server first! -# apt-get install make build-essential autoconf zlib1g-dev libldap2-dev libssl-dev gettext libical-dev libexpat1-dev libcurl4-openssl-dev +cp ctdlvisor citadel.AppDir/usr/bin/ + +ARCH=x86_64 appimagetool citadel.AppDir/ diff --git a/appimage/citadel.AppDir/AppRun b/appimage/citadel.AppDir/AppRun index 83c86a45b..bb068bf8e 100755 --- a/appimage/citadel.AppDir/AppRun +++ b/appimage/citadel.AppDir/AppRun @@ -2,4 +2,4 @@ export LD_LIBRARY_PATH=$APPDIR/usr/lib export PATH=$APPDIR/usr/bin -exec $APPDIR/ctdlvisor +exec ctdlvisor diff --git a/appimage/citadel.AppDir/ctdlvisor b/appimage/citadel.AppDir/ctdlvisor deleted file mode 100755 index 5aca68859ec02abbb36f616a49f540fc4484f166..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 8996 zcmeHMZERcB89ui2)wFTkQXo)9%|@rtEl$&glG2r3Cvodk?gznvu`S#<_Dy2y*pYqR zrl6IIv>*!#W#dPgrl}GLjUPz-LR~d2=~_`uLs~)Gv@teSXrP1-trJ-lZ3XXn&poew zePc7EY1$u-<@=uZc|XoM?>!&)obyO1vcv6i2~KWtmmp4S&?IC%g?MGPWEIvURtQbp zEY^tzAocibQbN?qFc2rlNSF)fZGQ)I2)niIgwj-A8+Lc|qvSWHtRg5XOkJ?86sPY$eYv732h=_jq zEK|~@wC`OrLHWfMk_FXdhH1ot1yi=W8+KIB&zpQoaZr_4D=wE+`?_ ziH=k2LzH7|~p#ydM zGw#^cKy2{d=gF4;$bR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 ztXHVU%|z-zGMCB9dhZwv?hfgpJ^iS-)e6p67$$_?fB&A~?twmN*(CDfROmY+dwYWs zeeaGP_k^N)G}s#nkvn;}8qeireboi5rrEDl^?~Say&SOU?mh}vG&Y(t1RVfa_ptI# z*I{VL^8xGP_MkC}iv?jZeBEFbYTW@lY@L_BPO+_IdjUB#sp4`NFDIALCt~RYs;dv| zMQszww4Toyh*!Dw6fc1n1yIFH$FYXW%S&fPda6ST2WdM0XhuEgeDQ c7f8|Mo>mb{>khoqQr@#vLh{wh%kxV7-{D=YB>(^b diff --git a/appimage/citadel.AppDir/ctdlvisor.c b/appimage/citadel.AppDir/ctdlvisor.c deleted file mode 100644 index b2e6a184f..000000000 --- a/appimage/citadel.AppDir/ctdlvisor.c +++ /dev/null @@ -1,73 +0,0 @@ -#include -#include -#include -#include - - - - -pid_t start_citadel() { - pid_t pid = fork(); - if (pid == 0) { - execlp("citserver", "citserver", "-x9", "-h/usr/local/citadel", NULL); - exit(1); - } - else { - return(pid); - } -} - - -pid_t start_webcit() { - pid_t pid = fork(); - if (pid == 0) { - execlp("/bin/bash", "bash", "-c", "sleep 7", NULL); - exit(1); - } - else { - return(pid); - } -} - - -pid_t start_webcits() { - pid_t pid = fork(); - if (pid == 0) { - execlp("/bin/bash", "bash", "-c", "sleep 9", NULL); - exit(1); - } - else { - return(pid); - } -} - - - - - -main() { - int status; - pid_t who_exited; - - pid_t citserver_pid = start_citadel(); - //pid_t webcit_pid = start_webcit(); - //pid_t webcits_pid = start_webcits(); - - do { - printf("LD_LIBRARY_PATH = %s\n", getenv("LD_LIBRARY_PATH")); - printf("PATH = %s\n", getenv("PATH")); - - - printf("waiting...\n"); - who_exited = waitpid(-1, &status, 0); - printf("pid=%d exited, status=%d\n", who_exited, status); - - if (who_exited == citserver_pid) citserver_pid = start_citadel(); - //if (who_exited == webcit_pid) webcit_pid = start_webcit(); - //if (who_exited == webcits_pid) webcits_pid = start_webcits(); - - sleep(1); // for sanity - - } while(who_exited >= 0); - exit(0); -} diff --git a/appimage/ctdlvisor.c b/appimage/ctdlvisor.c new file mode 100644 index 000000000..63230afae --- /dev/null +++ b/appimage/ctdlvisor.c @@ -0,0 +1,108 @@ +// +// This is a supervisor program that handles start/stop/restart of +// the various Citadel System components, when we are running on +// an AppImage instance. +// +// Copyright (c) 2021 by the citadel.org team +// +// This program is open source software. It runs great on the +// Linux operating system (and probably elsewhere). You can use, +// copy, and run it under the terms of the GNU General Public +// License version 3. Richard Stallman is an asshole communist. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + + +#include +#include +#include +#include +#include + + +pid_t start_citadel() { + char bin[1024]; + sprintf(bin, "%s/usr/local/citadel/citserver", getenv("APPDIR")); + pid_t pid = fork(); + if (pid == 0) { + printf("Executing %s\n", bin); + execlp(bin, "citserver", "-x9", "-h/usr/local/citadel", NULL); + perror("execlp"); + exit(errno); + } + else { + return(pid); + } +} + + +pid_t start_webcit() { + char bin[1024]; + sprintf(bin, "%s/usr/local/webcit/webcit", getenv("APPDIR")); + pid_t pid = fork(); + if (pid == 0) { + printf("Executing %s\n", bin); + execlp(bin, "webcit", "-x9", "-p80", "uds", "/usr/local/citadel", NULL); + perror("execlp"); + exit(errno); + } + else { + return(pid); + } +} + + +pid_t start_webcits() { + char bin[1024]; + sprintf(bin, "%s/usr/local/webcit/webcit", getenv("APPDIR")); + pid_t pid = fork(); + if (pid == 0) { + printf("Executing %s\n", bin); + execlp(bin, "webcit", "-x9", "-s", "-p443", "uds", "/usr/local/citadel", NULL); + perror("execlp"); + exit(errno); + } + else { + return(pid); + } +} + + +main() { + int status; + pid_t who_exited; + + pid_t citserver_pid = start_citadel(); + pid_t webcit_pid = start_webcit(); + pid_t webcits_pid = start_webcits(); + + do { + printf("LD_LIBRARY_PATH = %s\n", getenv("LD_LIBRARY_PATH")); + printf("PATH = %s\n", getenv("PATH")); + printf("APPDIR = %s\n", getenv("APPDIR")); + + printf("waiting...\n"); + who_exited = waitpid(-1, &status, 0); + printf("pid=%d exited, status=%d\n", who_exited, status); + + if (who_exited == citserver_pid) { + if (WEXITSTATUS(status) == 0) { + printf("ctdlvisor: citserver exited normally - ending AppImage session\n"); + exit(0); + } + citserver_pid = start_citadel(); + } + + if (who_exited == webcit_pid) webcit_pid = start_webcit(); + if (who_exited == webcits_pid) webcits_pid = start_webcits(); + + sleep(1); // slow down any accidental loops + + } while (who_exited >= 0); + + printf("ctdlvisor: exiting.\n"); + exit(0); +} -- 2.30.2