database cleanup mode
[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
37                         echo "$0: usage: $0 [-v volume_name] [-h home_directory] [-m] [-d] container_image_name"
38                         echo "  -v volume_name          Use or create a Citadel database stored in a Docker volume called 'volume_name'"
39                         echo "  -h home_directory       Use or create a Citadel database stored in 'home_directory' on the host system"
40                         echo "  -m                      Enter migrate mode, to copy a remote Citadel installation to this host"
41                         echo "  -d                      Attempt to recover a corrupt database"
42                         exit 1
43                         ;;
44         esac
45 done
46 shift $((OPTIND-1))
47
48 if ( ${volume_mode} && ${bind_mode} ) ; then
49         echo "$0: -v and -h cannot both be specified."
50         exit 2
51 fi
52
53 if ${volume_mode} ; then
54         CTDL_VOL=volume
55 elif ${bind_mode} ; then
56         CTDL_VOL=bind
57 else
58         volume_mode=true
59         CTDL_VOL=volume
60         CTDL_DIR=citadel-data
61 fi
62
63 if ( ${migrate_mode} && ${database_cleanup_mode} ) ; then
64         echo "$0: -m and -d cannot both be specified."
65         exit 3
66 fi
67
68 docker run -it --rm $1 -c || exit 1
69
70 n_args=""
71 c_args=""
72
73 if ${migrate_mode} ; then
74         c_args="-m"                             # Tell ctdlvisor to run ctdlmigrate
75 elif ${database_cleanup_mode} ; then
76         c_args="-d"                             # Tell ctdlvisor to run database_cleanup.sh
77 else
78         n_args="--network host"                 # Only open ports if we're running in normal mode
79 fi
80
81 exec docker run \
82         --name citadel \
83         -it \
84         --rm \
85         ${n_args} \
86         --mount type=${CTDL_VOL},source=${CTDL_DIR},target=/citadel-data \
87         $1 ${c_args}
88
89 #       Explanation of the above options:
90 #
91 #       --name citadel                  Create a container named "citadel"
92 #       -it                             Run in the foreground
93 #       --rm                            Delete the container when it exits
94 #       --network host                  Bind directly to the host's network ports instead of creating a separate interface
95 #       --mount                         This identifies where on the host our persistent Citadel database is found