From fda5b37d1404c736c457952aaf22115cf412b317 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 5 Aug 2021 15:29:36 -0400 Subject: [PATCH] I found the '--network host' option in Docker, so now we don't have to launch the container with each port mapped individually. --- Dockerfile | 2 +- ctdlvisor.c | 12 ++++++------ run-citadel.sh | 24 ++++++++++-------------- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/Dockerfile b/Dockerfile index 96547e0..0f81cbb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,4 @@ RUN sh -c 'cd /tmp/ctdl_build && cc ctdlvisor.c -o /usr/local/bin/ctdlvisor' EXPOSE 25 80 110 119 143 443 465 504 563 587 993 995 2020 5222 # Let's go! -ENTRYPOINT /usr/local/bin/ctdlvisor +ENTRYPOINT ["/usr/local/bin/ctdlvisor"] diff --git a/ctdlvisor.c b/ctdlvisor.c index 086f1a6..18b4202 100644 --- a/ctdlvisor.c +++ b/ctdlvisor.c @@ -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); diff --git a/run-citadel.sh b/run-citadel.sh index 486a2e4..4119296 100755 --- a/run-citadel.sh +++ b/run-citadel.sh @@ -5,22 +5,18 @@ # The container expects a persistent volume called "citadel-data" in which it will keep everything. # The remainder of the container is ephermal and can be deleted at any time. -docker run \ +exec docker run \ --name citadel \ -it \ --rm \ - -p 25:25 \ - -p 80:80 \ - -p 110:110 \ - -p 119:119 \ - -p 143:143 \ - -p 443:443 \ - -p 465:465 \ - -p 504:504 \ - -p 563:563 \ - -p 587:587 \ - -p 993:993 \ - -p 995:995 \ - -p 5222:5222 \ + --network host \ --mount type=bind,source=/root/citadel/citadel,target=/citadel-data \ $* + +# Explanation of the above options: +# +# --name citadel Create a container named "citadel" +# -it Run in the foreground +# --rm Delete the container when it exits +# --network host Bind directly to the host's network ports instead of creating a separate interface +# --mount This identifies where on the host our persistent Citadel database is found -- 2.30.2