X-Git-Url: https://code.citadel.org/?p=citadel-docker.git;a=blobdiff_plain;f=run-citadel.sh;h=f021bf5e52e8f7099a06dd41ab79cf10f9a1f8a7;hp=fa2e60fa7b886bdbb85be6aa60f728931fd764ea;hb=HEAD;hpb=e5d08c815bbbda67664caf98854e7684b1a6b5b8 diff --git a/run-citadel.sh b/run-citadel.sh index fa2e60f..3372da6 100755 --- a/run-citadel.sh +++ b/run-citadel.sh @@ -1,9 +1,87 @@ #!/bin/bash -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 +# 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. + +migrate_mode=false +database_cleanup_mode=false +volume_mode=false +bind_mode=false + +# Parse the command line arguments +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 + echo "$0: usage: $0 [-v volume_name] [-h home_directory] [-m] [-d] container_image_name" + echo " -v volume_name Use or create a Citadel database stored in a Docker volume called 'volume_name'" + echo " -h home_directory Use or create a Citadel database stored in 'home_directory' on the host system" + echo " -m Enter migrate mode, to copy a remote Citadel installation to this host" + echo " -d Attempt to recover a corrupt database" + 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=bind + CTDL_DIR=/usr/local/citadel + mkdir /usr/local/citadel >/dev/null 2>/dev/null +fi + +if ( ${migrate_mode} && ${database_cleanup_mode} ) ; then + echo "$0: -m and -d cannot both be specified." + exit 3 +fi + +docker run -i --rm citadel -c || exit 1 + +n_args="" +c_args="" + +if ${migrate_mode} ; then + c_args="-m" # Tell ctdlvisor to run ctdlmigrate +elif ${database_cleanup_mode} ; then + c_args="-d" # Tell ctdlvisor to run database_cleanup.sh +else + n_args="--network=host" # Only open ports if we're running in normal mode +fi + +exec docker run \ + --name=citadel \ + -i \ + --rm \ + ${n_args} \ + --mount type=${CTDL_VOL},source=${CTDL_DIR},target=/citadel-data \ + citadel \ + ${c_args}