comparison docker/libervia_cont.sh @ 24:f0a59c8f3490

docker: added docker presence check + if image are not present locally on run, download them without catching the output (so we can se the progress)
author Goffi <goffi@goffi.org>
date Mon, 20 Oct 2014 13:12:31 +0200
parents b10f01885949
children 25b7452c2d5a
comparison
equal deleted inserted replaced
23:b10f01885949 24:f0a59c8f3490
14 # GNU Affero General Public License for more details. 14 # GNU Affero General Public License for more details.
15 15
16 # You should have received a copy of the GNU Affero General Public License 16 # You should have received a copy of the GNU Affero General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. 17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 18
19 VERSION="0.1.0" 19 VERSION="0.2.0"
20 ACCOUNT="salutatoi" 20 ACCOUNT="salutatoi"
21 21
22 CONTAINERS="prosody sat_pubsub salut sat libervia" 22 CONTAINERS="prosody sat_pubsub salut sat libervia"
23 23
24 DETACH="-d" 24 DETACH="-d"
25 TERM="-ti" 25 TERM="-ti"
26 26
27 VOLUME_CONT="$ACCOUNT/data" 27 VOLUME_NAME="data"
28 VOLUME_CONT="$ACCOUNT/$VOLUME_NAME"
28 VOLUME_ALIAS="sat_data" 29 VOLUME_ALIAS="sat_data"
29 VOLUME="--volumes-from $VOLUME_ALIAS" 30 VOLUME="--volumes-from $VOLUME_ALIAS"
30 31
31 PUBLIC=0 32 PUBLIC=0
32 33
40 LIBERVIA_PORTS="8080 8443" 41 LIBERVIA_PORTS="8080 8443"
41 PORT_8080_NAME="HTTP" 42 PORT_8080_NAME="HTTP"
42 PORT_8443_NAME="HTTPS" 43 PORT_8443_NAME="HTTPS"
43 NO_PORT="No public port" 44 NO_PORT="No public port"
44 45
46 DOCKER_EXE="docker"
47
45 USAGE="Usage: $0 [run|stop|update|backup|ports] [ARGS...]" 48 USAGE="Usage: $0 [run|stop|update|backup|ports] [ARGS...]"
46 49
47 HELP_SITE="http://wiki.goffi.org/wiki/Docker/en" 50 HELP_SITE="http://wiki.goffi.org/wiki/Docker/en"
48 HELP_MUC="sat@chat.jabberfr.org" 51 HELP_MUC="sat@chat.jabberfr.org"
49 52
103 ARG="$ARG -p $port:$port" 106 ARG="$ARG -p $port:$port"
104 done 107 done
105 echo $ARG 108 echo $ARG
106 } 109 }
107 110
111 download_missing() {
112 # download images wich are not present locally
113 for cont in $VOLUME_NAME $CONTAINERS; do
114 image="$ACCOUNT/$cont"
115 docker inspect $image:latest > /dev/null 2>&1
116 if [ $? -ne 0 ]; then
117 printf "$image is not present locally, downloading it\n"
118 docker pull $image:latest
119 if [ $? -eq 0 ]; then
120 printf "\nDownload of latest $image finished\n\n"
121 else
122 printf "\nError while downloading $image, please check your connection and logs\n"
123 return 1
124 fi
125 fi
126 done
127 }
128
129 check_docker() {
130 which $DOCKER_EXE > /dev/null 2>&1
131 if [ $? -ne 0 ]; then
132 printf "Docker is not installed or not accessible, please install it.\nYou can check http://wiki.goffi.org/wiki/Docker/en for instructions\n"
133 return 1
134 fi
135 }
136
108 parse_run_args() { 137 parse_run_args() {
109 # manage arguments for run command 138 # manage arguments for run command
110 139
111 while [ $# -gt 0 ]; do 140 while [ $# -gt 0 ]; do
112 case "$1" in 141 case "$1" in
142 ;; 171 ;;
143 esac 172 esac
144 done 173 done
145 } 174 }
146 175
176 check_docker || exit 1
147 177
148 if [ $# -ge 1 ];then 178 if [ $# -ge 1 ];then
149 case $1 in 179 case $1 in
150 run) CMD=RUN;; 180 run) CMD=RUN;;
151 stop) CMD=STOP;; 181 stop) CMD=STOP;;
163 fi 193 fi
164 194
165 case $CMD in 195 case $CMD in
166 RUN) 196 RUN)
167 parse_run_args "$@" 197 parse_run_args "$@"
198 download_missing || exit 1
199
168 printf "Running data container... " 200 printf "Running data container... "
169 docker_id=$(docker run -d -ti --name $VOLUME_ALIAS $VOLUME_CONT 2>&1) 201 docker_id=$(docker run -d -ti --name $VOLUME_ALIAS $VOLUME_CONT 2>&1)
170 if [ $? -eq 0 ]; then 202 if [ $? -eq 0 ]; then
171 printf "OK ($docker_id)\n" 203 printf "OK ($docker_id)\n"
172 else 204 else