X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=ctdlvisor.c;h=7c5632abd9eb55baa8a4ffdf9cf5c81a7d40cc7e;hb=HEAD;hp=d1d024e934ff86e276aea6f41508ba5f734b67b4;hpb=fe0492aeb42727ec6c9bc17772a3899180fb4892;p=citadel-docker.git diff --git a/ctdlvisor.c b/ctdlvisor.c index d1d024e..7c5632a 100644 --- a/ctdlvisor.c +++ b/ctdlvisor.c @@ -2,7 +2,7 @@ // the various Citadel System components, when we are running in // a container. // -// Copyright (c) 2021 by the citadel.org team +// Copyright (c) 2021-2023 by the citadel.org team // // This program is open source software. Use, duplication, or disclosure // is subject to the terms of the GNU General Public License, version 3. @@ -29,7 +29,7 @@ char *logging_flag = "-x1"; // Call this instead of exit() just for common diagnostics etc. void ctdlvisor_exit(int code) { - printf("ctdlvisor: exit code %d\n", code); + fprintf(stderr, "ctdlvisor: exit code %d\n", code); exit(code); } @@ -182,8 +182,10 @@ void main_loop(void) { int main(int argc, char **argv) { int a; - int migrate_mode = 0; + int export_mode = 0; + int import_mode = 0; int database_cleanup_mode = 0; + char bin[1024]; fprintf(stderr, "ctdlvisor: Welcome to the Citadel System running in a container.\n"); fprintf(stderr, "ctdlvisor: command line arguments: "); @@ -213,17 +215,22 @@ int main(int argc, char **argv) { symlink(CTDL_DIR "/keys", "/usr/local/webcit/keys"); /* parse command-line arguments */ - while ((a=getopt(argc, argv, "cmdx:")) != EOF) switch(a) { + while ((a=getopt(argc, argv, "ceidx:")) != EOF) switch(a) { // test this binary for compatibility and exit case 'c': - fprintf(stderr, "%s: binary compatibility confirmed\n", argv[0]); + fprintf(stderr, "%s: binary compatibility CONFIRMED! You CAN run Citadel in a container on this system.\n", argv[0]); exit(0); break; - // run ctdlmigrate only - case 'm': - migrate_mode = 1; + // export your database + case 'e': + export_mode = 1; + break; + + // import your database + case 'i': + import_mode = 1; break; // run database_cleanup.sh only @@ -239,30 +246,27 @@ int main(int argc, char **argv) { // any other parameter makes it crash and burn default: - fprintf(stderr, "%s: usage: %s [-c] [-m] [-d] [-x log_level]\n"); + fprintf(stderr, "%s: usage: %s [-c] [-e] [-i] [-d] [-x log_level]\n", argv[0], argv[0]); exit(1); } signal(SIGHUP, signal_handler); - // "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, "/usr/local/citadel/ctdlmigrate -h %s", CTDL_DIR); + // "export mode" means we only run ctdldump + if (export_mode) { + sprintf(bin, "/usr/local/citadel/ctdldump -y -h %s", CTDL_DIR); + system(bin); + } + + // "import mode" means we only run ctdlload + else if (import_mode) { + sprintf(bin, "/usr/local/citadel/ctdlload -y -h %s", CTDL_DIR); system(bin); - 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);