From 76a0216278f0a014d3533de9150adbc9f74085ab Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 21 Apr 2021 12:44:07 -0400 Subject: [PATCH] working on ctdlmigrate in the appimage --- appimage/README.txt | 5 ++-- appimage/build_appimage.sh | 4 ++- appimage/citadel.AppDir/AppRun | 8 +++++- appimage/ctdlvisor.c | 52 +++++++++++++++++++++++++++++----- 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/appimage/README.txt b/appimage/README.txt index 5443d2a98..6aff8531e 100644 --- a/appimage/README.txt +++ b/appimage/README.txt @@ -15,9 +15,8 @@ this is that we can supply ready-to-run binaries that will run on any Linux/Linu without modification or dependencies. If you are an end user, stop here, go download the binary package, and use it. Enjoy it and have fun. -Still with us? Then you must be a new member of the Citadel team and you're packaging -the software for a new architecture or something. So here's what you have to do to build -the binary: +Still with us? Then you must be a new member of the build team. So here's what you have +to do to build the binary: 1. Download the Citadel source tree (if you're reading this, you've already done that). 2. Install all system dependencies. The same ones needed for Easy Install are fine. diff --git a/appimage/build_appimage.sh b/appimage/build_appimage.sh index 28d24eccb..ed363a5e0 100755 --- a/appimage/build_appimage.sh +++ b/appimage/build_appimage.sh @@ -1,5 +1,7 @@ #!/bin/bash +rm -vf citadel-*appimage + export CITADEL_BUILD_DIR=/tmp/citadel-build-$$ export WEBCIT_BUILD_DIR=/tmp/webcit-build-$$ rm -fr $CITADEL_BUILD_DIR $WEBCIT_BUILD_DIR @@ -37,7 +39,7 @@ mkdir -p citadel.AppDir/usr/bin mkdir -p citadel.AppDir/usr/lib # Copy over all the libraries we used -for bin in $CITADEL_BUILD_DIR/citserver $WEBCIT_BUILD_DIR/webcit +for bin in $CITADEL_BUILD_DIR/citserver $WEBCIT_BUILD_DIR/webcit $CITADEL_BUILD_DIR/ctdlmigrate do for x in `ldd $bin | awk ' { print $3 } ' | grep -v -e '^$' | grep -v 'libc.so' | grep -v 'libpthread.so' | grep -v 'libresolv.so'` do diff --git a/appimage/citadel.AppDir/AppRun b/appimage/citadel.AppDir/AppRun index ff2fe0e61..e498fe428 100755 --- a/appimage/citadel.AppDir/AppRun +++ b/appimage/citadel.AppDir/AppRun @@ -23,7 +23,7 @@ ulimit -c unlimited usage() { echo ${APPIMAGE}: usage: ${APPIMAGE} '[-h data_directory] [-p http_port] [-s https_port] command' - echo 'command must be one of: run, test, install, database_cleanup' + echo 'command must be one of: run, test, install, database_cleanup, migrate' exit 2 } @@ -199,6 +199,12 @@ case ${1} in export PATH=$APPDIR/usr/bin:$PATH exec $APPDIR/usr/local/citadel/database_cleanup.sh -h $CTDL_DIR ;; + migrate) + export APPDIR CTDL_DIR HTTP_PORT HTTPS_PORT + export LD_LIBRARY_PATH=$APPDIR/usr/lib + export PATH=$APPDIR/usr/bin + exec ctdlvisor -m -h $CTDL_DIR + ;; *) echo Unexpected command: ${1} usage diff --git a/appimage/ctdlvisor.c b/appimage/ctdlvisor.c index c9be7e139..7e2c25b29 100644 --- a/appimage/ctdlvisor.c +++ b/appimage/ctdlvisor.c @@ -200,12 +200,34 @@ void main_loop(void) { int main(int argc, char **argv) { + int a; + int migrate_mode = 0; if (getenv("APPDIR") == NULL) { fprintf(stderr, "ctdlvisor: APPDIR is not set. This program must be run from within an AppImage.\n"); ctdlvisor_exit(1); } + /* parse command-line arguments */ + while ((a=getopt(argc, argv, "cm")) != EOF) switch(a) { + + // test this binary for compatibility and exit + case 'c': + fprintf(stderr, "%s: binary compatibility confirmed\n", argv[0]); + exit(0); + break; + + // run ctdlmigrate only + case 'm': + migrate_mode = 1; + break; + + // any other parameter makes it crash and burn + default: + fprintf(stderr, "usage\n"); + exit(1); + } + fprintf(stderr, "ctdlvisor: Welcome to the Citadel System, brought to you using AppImage.\n"); fprintf(stderr, "ctdlvisor: LD_LIBRARY_PATH = %s\n", getenv("LD_LIBRARY_PATH")); fprintf(stderr, "ctdlvisor: PATH = %s\n", getenv("PATH")); @@ -219,15 +241,31 @@ int main(int argc, char **argv) { ctdlvisor_exit(errno); } - signal(SIGTERM, signal_handler); signal(SIGHUP, signal_handler); - signal(SIGINT, signal_handler); - signal(SIGQUIT, signal_handler); - citserver_pid = start_citadel(); - webcit_pid = start_webcit(); - webcits_pid = start_webcits(); + // "migrate mode" means we just start the server and then run ctdlmigrate interactively. + if (migrate_mode) { + citserver_pid = start_citadel(); + fprintf(stderr, "ctdlvisor: waiting a moment for citserver to initialize...\n"); + sleep(5); + char bin[1024]; + sprintf(bin, "%s/usr/local/citadel/ctdlmigrate", getenv("APPDIR")); + system(bin); + kill(citserver_pid, SIGTERM); + } + + // Otherwise, it's just a normal happy day in Citadel land. + else { + signal(SIGTERM, signal_handler); + signal(SIGINT, signal_handler); + signal(SIGQUIT, signal_handler); + + citserver_pid = start_citadel(); + webcit_pid = start_webcit(); + webcits_pid = start_webcits(); + + main_loop(); + } - main_loop(); ctdlvisor_exit(0); } -- 2.30.2