Fleshing out the command line options for run-citadel.sh
[citadel-docker.git] / run-citadel.sh
1 #!/bin/bash
2
3 # This is a simple startup script to run Citadel in a Docker container.
4 # If you know your way around Docker, you don't have to use it; feel free to do whatever you want.
5 # The container expects a persistent volume called "citadel-data" in which it will keep everything.
6 # The remainder of the container is ephermal and can be deleted at any time.
7
8
9 # Parse the command line arguments
10
11 migrate_mode=false
12 database_cleanup_mode=false
13 volume_mode=false
14 bind_mode=false
15
16 while getopts ":mdv:h:" o
17 do
18         case "${o}" in
19                 m)
20                         echo "migrate mode"
21                         migrate_mode=true
22                         ;;
23                 d)
24                         echo "database cleanup mode";
25                         database_cleanup_mode=true
26                         ;;
27                 v)
28                         volume_mode=true
29                         CTDL_DIR=${OPTARG}
30                         ;;
31                 h)
32                         bind_mode=true
33                         CTDL_DIR=${OPTARG}
34                         ;;
35                 *)
36                         echo "$0: usage: $0 [-v volume_name] [-h home_directory] [-m] [-v] container_image_name [other parameters]"
37                         exit 1
38                         ;;
39         esac
40 done
41 shift $((OPTIND-1))
42
43 if ( ${volume_mode} && ${bind_mode} ) ; then
44         echo "$0: -v and -h cannot both be specified."
45         exit 2
46 fi
47
48 if ${volume_mode} ; then
49         CTDL_VOL=volume
50 elif ${bind_mode} ; then
51         CTDL_VOL=bind
52 else
53         volume_mode=true
54         CTDL_VOL=volume
55         CTDL_DIR=citadel-data
56 fi
57
58 if ( ${migrate_mode} && ${database_cleanup_mode} ) ; then
59         echo "$0: -m and -d cannot both be specified."
60         exit 3
61 fi
62
63 docker version >/dev/null 2>&1 || {
64         echo Docker engine is not installed on this host.
65         exit 1
66 }
67
68 exec docker run \
69         --name citadel \
70         -it \
71         --rm \
72         --network host \
73         --mount type=${CTDL_VOL},source=${CTDL_DIR},target=/citadel-data \
74         $*
75
76 #       Explanation of the above options:
77 #
78 #       --name citadel                  Create a container named "citadel"
79 #       -it                             Run in the foreground
80 #       --rm                            Delete the container when it exits
81 #       --network host                  Bind directly to the host's network ports instead of creating a separate interface
82 #       --mount                         This identifies where on the host our persistent Citadel database is found