From b9994af643b6329f691d55290f5d9443674131ef Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sat, 7 Aug 2021 19:48:01 -0400 Subject: [PATCH] database cleanup mode --- ctdlvisor.c | 19 ++++++++++++++++++- run-citadel.sh | 27 ++++++++++++++++++++------- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/ctdlvisor.c b/ctdlvisor.c index ece2e9d..64e6c04 100644 --- a/ctdlvisor.c +++ b/ctdlvisor.c @@ -182,6 +182,7 @@ void main_loop(void) { int main(int argc, char **argv) { int a; int migrate_mode = 0; + int database_cleanup_mode = 0; fprintf(stderr, "ctdlvisor: Welcome to the Citadel System running in a container.\n"); fprintf(stderr, "ctdlvisor: command line arguments: "); @@ -211,7 +212,7 @@ int main(int argc, char **argv) { symlink(CTDL_DIR "/keys", "/usr/local/webcit/keys"); /* parse command-line arguments */ - while ((a=getopt(argc, argv, "cm")) != EOF) switch(a) { + while ((a=getopt(argc, argv, "cmd")) != EOF) switch(a) { // test this binary for compatibility and exit case 'c': @@ -224,6 +225,11 @@ int main(int argc, char **argv) { migrate_mode = 1; break; + // run database_cleanup.sh only + case 'd': + database_cleanup_mode = 1; + break; + // any other parameter makes it crash and burn default: fprintf(stderr, "usage\n"); @@ -244,6 +250,17 @@ int main(int argc, char **argv) { kill(citserver_pid, SIGTERM); } + // "database cleanup mode" means we just start the server and then run database_cleanup.sh interactively + else if (database_cleanup_mode) { + citserver_pid = start_citadel(); + fprintf(stderr, "ctdlvisor: waiting a moment for citserver to initialize...\n"); + sleep(5); + char bin[1024]; + sprintf(bin, "/usr/local/citadel/database_cleanup.sh -h %s", CTDL_DIR); + system(bin); + kill(citserver_pid, SIGTERM); + } + // Otherwise, it's just a normal happy day in Citadel land. else { signal(SIGTERM, signal_handler); diff --git a/run-citadel.sh b/run-citadel.sh index a763998..398c779 100755 --- a/run-citadel.sh +++ b/run-citadel.sh @@ -33,7 +33,12 @@ do CTDL_DIR=${OPTARG} ;; *) - echo "$0: usage: $0 [-v volume_name] [-h home_directory] [-m] [-v] container_image_name [other parameters]" + echo + echo "$0: usage: $0 [-v volume_name] [-h home_directory] [-m] [-d] container_image_name" + echo " -v volume_name Use or create a Citadel database stored in a Docker volume called 'volume_name'" + echo " -h home_directory Use or create a Citadel database stored in 'home_directory' on the host system" + echo " -m Enter migrate mode, to copy a remote Citadel installation to this host" + echo " -d Attempt to recover a corrupt database" exit 1 ;; esac @@ -60,18 +65,26 @@ if ( ${migrate_mode} && ${database_cleanup_mode} ) ; then exit 3 fi -docker version >/dev/null 2>&1 || { - echo Docker engine is not installed on this host. - exit 1 -} +docker run -it --rm $1 -c || exit 1 + +n_args="" +c_args="" + +if ${migrate_mode} ; then + c_args="-m" # Tell ctdlvisor to run ctdlmigrate +elif ${database_cleanup_mode} ; then + c_args="-d" # Tell ctdlvisor to run database_cleanup.sh +else + n_args="--network host" # Only open ports if we're running in normal mode +fi exec docker run \ --name citadel \ -it \ --rm \ - --network host \ + ${n_args} \ --mount type=${CTDL_VOL},source=${CTDL_DIR},target=/citadel-data \ - $* + $1 ${c_args} # Explanation of the above options: # -- 2.30.2