]> code.citadel.org Git - citadel-docker.git/blobdiff - ctdlvisor.c
Burn the cache when the upstream repo changes
[citadel-docker.git] / ctdlvisor.c
index 086f1a64fbacc6bfdc269e4249386ad474a8de9d..64e6c04c441b63e0e4ce4c1b8670e2ccdc94cbf1 100644 (file)
@@ -93,7 +93,7 @@ pid_t start_citadel() {
        pid_t pid = fork();
        if (pid == 0) {
                fprintf(stderr, "ctdlvisor: executing citserver\n");
-               //detach_from_tty();
+               detach_from_tty();
                execlp("/usr/local/citadel/citserver", "citserver", "-x9", "-h", CTDL_DIR, NULL);
                exit(errno);
        }
@@ -108,7 +108,7 @@ pid_t start_webcit() {
        pid_t pid = fork();
        if (pid == 0) {
                fprintf(stderr, "ctdlvisor: executing webcit (http)\n");
-               //detach_from_tty();
+               detach_from_tty();
                execlp("/usr/local/webcit/webcit", "webcit", "-x9", "-p", "80", "uds", CTDL_DIR, NULL);
                exit(errno);
        }
@@ -123,7 +123,7 @@ pid_t start_webcits() {
        pid_t pid = fork();
        if (pid == 0) {
                fprintf(stderr, "ctdlvisor: executing webcit (https)\n");
-               //detach_from_tty();
+               detach_from_tty();
                execlp("/usr/local/webcit/webcit", "webcit", "-x9", "-s", "-p", "443", "uds", CTDL_DIR, NULL);
                exit(errno);
        }
@@ -143,18 +143,18 @@ void main_loop(void) {
                who_exited = waitpid(-1, &status, 0);
                fprintf(stderr, "ctdlvisor: pid=%d exited, status=%d, exitcode=%d\n", who_exited, status, WEXITSTATUS(status));
 
-               // A *deliberate* exit of citserver will cause ctdlvisor to shut the whole AppImage down.
+               // A *deliberate* exit of citserver will cause ctdlvisor to shut the whole container down.
                // If it crashes, however, we will start it back up.
                if (who_exited == citserver_pid) {
                        citserver_exit_code = WEXITSTATUS(status);
                        if ((WIFEXITED(status)) && (citserver_exit_code == 0)) {
-                               fprintf(stderr, "ctdlvisor: citserver exited normally - ending AppImage session\n");
+                               fprintf(stderr, "ctdlvisor: citserver exited normally - ending container session\n");
                                shutting_down = 1;
                                kill(webcit_pid, SIGTERM);
                                kill(webcits_pid, SIGTERM);
                        }
                        else if ((WIFEXITED(status)) && (citserver_exit_code >= 101) && (citserver_exit_code <= 109)) {
-                               fprintf(stderr, "ctdlvisor: citserver exited intentionally - ending AppImage session\n");
+                               fprintf(stderr, "ctdlvisor: citserver exited intentionally - ending container session\n");
                                shutting_down = 1;
                                kill(webcit_pid, SIGTERM);
                                kill(webcits_pid, SIGTERM);
@@ -179,34 +179,10 @@ void main_loop(void) {
 }
 
 
-void install_client_link(void) {                       // FIXME this is all furkokt and needs to be rethought now that it's docker and not appimage
-
-       FILE *fp;
-       char path_to_link[PATH_MAX];
-       snprintf(path_to_link, sizeof path_to_link, CTDL_DIR "citadel");
-       fp = fopen(path_to_link, "w");
-       if (!fp) {
-               fprintf(stderr, "%s\n", strerror(errno));
-               return;
-       }
-
-       fprintf(fp,     "#!/bin/bash\n"
-                       "export APPDIR=%s\n"
-                       "export LD_LIBRARY_PATH=${APPDIR}/usr/bin:$LD_LIBRARY_PATH\n"
-                       "export PATH=${APPDIR}/usr/bin:$PATH\n"
-                       "exec citadel\n"
-       ,
-                       getenv("APPDIR")
-       );
-
-       fchmod(fileno(fp), 0755);
-       fclose(fp);
-}
-
-
 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: ");
@@ -236,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':
@@ -249,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");
@@ -269,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);
@@ -279,8 +271,6 @@ int main(int argc, char **argv) {
                webcit_pid = start_webcit();                    // start WebCit HTTP
                webcits_pid = start_webcits();                  // start WebCit HTTPS
 
-               install_client_link();
-       
                main_loop();
        }