]> code.citadel.org Git - citadel-docker.git/blobdiff - run-citadel.sh
Fleshing out the command line options for run-citadel.sh
[citadel-docker.git] / run-citadel.sh
index fa2e60fa7b886bdbb85be6aa60f728931fd764ea..a763998e9862f83a88494d17e862f17e966cfcb5 100755 (executable)
@@ -1,9 +1,82 @@
 #!/bin/bash
 
-docker run \
+# This is a simple startup script to run Citadel in a Docker container.
+# If you know your way around Docker, you don't have to use it; feel free to do whatever you want.
+# 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.
+
+
+# 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.
+       exit 1
+}
+
+exec docker run \
        --name citadel \
-       -v citadel-data:/usr/local/citadel/data \
-       -v citadel-files:/usr/local/citadel/files \
-       -v citadel-keys:/usr/local/citadel/keys \
-       -d \
-       $1
+       -it \
+       --rm \
+       --network host \
+       --mount type=${CTDL_VOL},source=${CTDL_DIR},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