From: Art Cancro Date: Thu, 7 Jan 2021 19:26:41 +0000 (-0500) Subject: appimage supervisor is functionally complete X-Git-Tag: v939~170 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=012e0d72fdf6337ccc34b9a75cabf924fd95d472 appimage supervisor is functionally complete --- 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 5aca68859..000000000 Binary files a/appimage/citadel.AppDir/ctdlvisor and /dev/null differ 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); +}