Fleshing out the command line options for run-citadel.sh
authorArt Cancro <ajc@citadel.org>
Fri, 6 Aug 2021 19:23:31 +0000 (15:23 -0400)
committerArt Cancro <ajc@citadel.org>
Fri, 6 Aug 2021 19:23:31 +0000 (15:23 -0400)
Dockerfile
ctdlvisor.c
run-citadel.sh

index 8dc69f82e0e847ad8da475e2735276bbe1a3a574..cf9baea3d997f6ed8ccd4645877541d54000e7bb 100644 (file)
@@ -1,3 +1,5 @@
+# Dockerfile for Citadel
+
 FROM bitnami/minideb:latest
 
 VOLUME /citadel-data
@@ -5,25 +7,41 @@ VOLUME /citadel-data
 # Install prerequisites
 RUN install_packages make build-essential zlib1g-dev libldap2-dev libssl-dev gettext libical-dev libexpat1-dev curl libcurl4-openssl-dev git autoconf automake netbase libreadline-dev
 
-# Download and build Citadel
-WORKDIR /tmp/ctdl_build
-RUN sh -c 'git clone git://git.citadel.org/appl/gitroot/citadel.git'
-RUN sh -c 'cd /tmp/ctdl_build/citadel/libcitadel && ./bootstrap && ./configure --prefix=/usr && make && make install'
-RUN sh -c 'cd /tmp/ctdl_build/citadel/citadel && ./bootstrap && ./configure && make && make install'
-RUN sh -c 'cd /tmp/ctdl_build/citadel/webcit && ./bootstrap && ./configure && make && make install'
-RUN sh -c 'cd /tmp/ctdl_build/citadel/textclient && ./bootstrap && ./configure --prefix=/usr && make && make install'
-RUN sh -c 'cd /tmp && rm -vfr /tmp/ctdl_build'
-RUN sh -c 'rm -vrf /usr/local/citadel/data /usr/local/citadel/files /usr/local/citadel/keys /usr/local/webcit/keys'
+# Deploy "ctdlvisor", a small supervisor program which runs inside the container to wrangle the various services
+ADD ctdlvisor.c /tmp
 
-# ctdlvisor is a supervisor process that handles all of the components
-ADD ctdlvisor.c /tmp/ctdl_build
-RUN sh -c 'cd /tmp/ctdl_build && cc ctdlvisor.c -o /usr/local/bin/ctdlvisor'
+# Download and build Citadel
+RUN sh -c 'mkdir /tmp/ctdl_build && \
+       cd /tmp/ctdl_build && \
+       git clone git://git.citadel.org/appl/gitroot/citadel.git && \
+       cd /tmp/ctdl_build/citadel/libcitadel && \
+       ./bootstrap && \
+       ./configure --prefix=/usr && \
+       make && \
+       make install && \
+       cd /tmp/ctdl_build/citadel/citadel && \
+       ./bootstrap && \
+       ./configure && \
+       make && \
+       make install && \
+       cd /tmp/ctdl_build/citadel/webcit && \
+       ./bootstrap && \
+       ./configure && \
+       make && \
+       make install && \
+       cd /tmp/ctdl_build/citadel/textclient && \
+       ./bootstrap && \
+       ./configure --prefix=/usr --ctdldir=/citadel_data && \
+       make && make install && \
+       cd /tmp && \
+       cc ctdlvisor.c -o /usr/local/bin/ctdlvisor && \
+       rm -vf /tmp/ctdlvisor.c && \
+       cd /tmp && \
+       rm -vfr /tmp/ctdl_build && \
+       rm -vrf /usr/local/citadel/data /usr/local/citadel/files /usr/local/citadel/keys /usr/local/webcit/keys'
 
 # Ports
 EXPOSE 25 80 110 119 143 443 465 504 563 587 993 995 2020 5222
 
-# We don't need the workdir anymore
-RUN rm -fr /tmp/ctdl_build
-
 # Let's go!
 ENTRYPOINT ["/usr/local/bin/ctdlvisor"]
index 18b420207ce0cc12f4440666e5e73f0027c93426..ece2e9dd34fa83495250e84d453a2589cbdadbf7 100644 (file)
@@ -179,31 +179,6 @@ 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;
@@ -279,8 +254,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();
        }
 
index 6ff9a03a203f9f8ee137ca7d8e23f63b9239a86e..a763998e9862f83a88494d17e862f17e966cfcb5 100755 (executable)
@@ -5,18 +5,60 @@
 # 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.
 
-# If you want to keep your Citadel data in a specific directory on the host,
-# set CTDL_VOL to "bind" and CTDL_DIR to the full pathname of that directory.
-# This is what you want if you are switching from Easy Install to Docker.
-#
-#CTDL_VOL=bind
-#CTDL_DIR=/usr/local/citadel
 
-# If you want to keep your Citadel data in a Docker volume,
-# set CTDL_VOL to "volume" and CTDL_DIR to the name of the volume.
-#
-CTDL_VOL=volume
-CTDL_DIR=citadel-data
+# Parse the command line arguments
+
+migrate_mode=false
+database_cleanup_mode=false
+volume_mode=false
+bind_mode=false
+
+while getopts ":mdv:h:" o
+do
+       case "${o}" in
+               m)
+                       echo "migrate mode"
+                       migrate_mode=true
+                       ;;
+               d)
+                       echo "database cleanup mode";
+                       database_cleanup_mode=true
+                       ;;
+               v)
+                       volume_mode=true
+                       CTDL_DIR=${OPTARG}
+                       ;;
+               h)
+                       bind_mode=true
+                       CTDL_DIR=${OPTARG}
+                       ;;
+               *)
+                       echo "$0: usage: $0 [-v volume_name] [-h home_directory] [-m] [-v] container_image_name [other parameters]"
+                       exit 1
+                       ;;
+       esac
+done
+shift $((OPTIND-1))
+
+if ( ${volume_mode} && ${bind_mode} ) ; then
+       echo "$0: -v and -h cannot both be specified."
+       exit 2
+fi
+
+if ${volume_mode} ; then
+       CTDL_VOL=volume
+elif ${bind_mode} ; then
+       CTDL_VOL=bind
+else
+       volume_mode=true
+       CTDL_VOL=volume
+       CTDL_DIR=citadel-data
+fi
+
+if ( ${migrate_mode} && ${database_cleanup_mode} ) ; then
+       echo "$0: -m and -d cannot both be specified."
+       exit 3
+fi
 
 docker version >/dev/null 2>&1 || {
        echo Docker engine is not installed on this host.