comparison docker/libervia_cont.sh @ 113:885818d29012

docker (libervia_cont): replaced printf by eprintf for error messages
author Goffi <goffi@goffi.org>
date Mon, 29 Feb 2016 22:06:03 +0100
parents a573bddf8039
children 37e100fd30ef
comparison
equal deleted inserted replaced
112:a573bddf8039 113:885818d29012
142 printf "$image is not present locally, downloading it\n" 142 printf "$image is not present locally, downloading it\n"
143 docker pull $image:latest 143 docker pull $image:latest
144 if [ $? -eq 0 ]; then 144 if [ $? -eq 0 ]; then
145 printf "\nDownload of latest $image finished\n\n" 145 printf "\nDownload of latest $image finished\n\n"
146 else 146 else
147 printf "\nError while downloading $image, please check your connection and logs\n" 147 eprintf "\nError while downloading $image, please check your connection and logs\n"
148 return 1 148 return 1
149 fi 149 fi
150 fi 150 fi
151 done 151 done
152 } 152 }
259 else 259 else
260 echo $docker_id | grep Conflict > /dev/null 2>&1 260 echo $docker_id | grep Conflict > /dev/null 2>&1
261 if [ $? -eq 0 ]; then 261 if [ $? -eq 0 ]; then
262 printf "A data container already exists ($VOLUME_ALIAS), use \"docker ps -a\" to see it\n" 262 printf "A data container already exists ($VOLUME_ALIAS), use \"docker ps -a\" to see it\n"
263 else 263 else
264 printf "Error, please check data volume\nerror message: $docker_id\n" 264 eprintf "Error, please check data volume\nerror message: $docker_id\n"
265 exit 1 265 exit 1
266 fi 266 fi
267 fi 267 fi
268 printf "\nRunning Libervia\n\n" 268 printf "\nRunning Libervia\n\n"
269 # we first check if we need to mount TLS directory 269 # we first check if we need to mount TLS directory
280 ;; 280 ;;
281 sat_pubsub) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME --name sat_pubsub --link=prosody:prosody";; 281 sat_pubsub) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME --name sat_pubsub --link=prosody:prosody";;
282 salut) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME --name salut --link=prosody:prosody";; 282 salut) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME --name salut --link=prosody:prosody";;
283 sat) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME -P $(public_ports_arg $CONT) --name sat --link=prosody:prosody";; 283 sat) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME -P $(public_ports_arg $CONT) --name sat --link=prosody:prosody";;
284 libervia) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME --volumes-from sat $DK_TLS -P $(public_ports_arg $CONT) --name libervia --link=sat:sat";; 284 libervia) OPTS="$DK_DETACH $DK_TERM $DK_VOLUME --volumes-from sat $DK_TLS -P $(public_ports_arg $CONT) --name libervia --link=sat:sat";;
285 *) printf "Unkown container $CONT\n"; exit 1 285 *) eprintf "Unkown container $CONT\n"; exit 1
286 esac 286 esac
287 printf "Launching $CONT... " 287 printf "Launching $CONT... "
288 docker_id=$(docker run $OPTS $SAT_CONT_DK_EXTRA $ACCOUNT/$CONT 2>&1) 288 docker_id=$(docker run $OPTS $SAT_CONT_DK_EXTRA $ACCOUNT/$CONT 2>&1)
289 if [ $? -eq 0 ]; then 289 if [ $? -eq 0 ]; then
290 printf "OK ($docker_id)\n" 290 printf "OK ($docker_id)\n"
291 else 291 else
292 printf "Error, please check container or ask help on XMPP MUC sat@chat.jabberfr.org\nerror message: $docker_id\n" 292 eprintf "Error, please check container or ask help on XMPP MUC sat@chat.jabberfr.org\nerror message: $docker_id\n"
293 printf "Abandon\n" 293 eprintf "Abandon\n"
294 exit 1 294 exit 1
295 fi 295 fi
296 done 296 done
297 printf '\nLibervia is launched and should be reachable in a couple of seconds.\nYou can check logs with "docker logs -f libervia" (or any other container name).\n' 297 printf '\nLibervia is launched and should be reachable in a couple of seconds.\nYou can check logs with "docker logs -f libervia" (or any other container name).\n'
298 printf "An \"admin\" account has been created, you can check its password on $VOLUME_ALIAS container, in file /home/sat/ADMIN_PWD. Config can be tuned on this container.\n" 298 printf "An \"admin\" account has been created, you can check its password on $VOLUME_ALIAS container, in file /home/sat/ADMIN_PWD. Config can be tuned on this container.\n"
305 for CONT in $CONTAINERS; do 305 for CONT in $CONTAINERS; do
306 REVERSED="$CONT $REVERSED" 306 REVERSED="$CONT $REVERSED"
307 done; 307 done;
308 for CONT in $REVERSED; do 308 for CONT in $REVERSED; do
309 printf "\nStopping container $CONT" 309 printf "\nStopping container $CONT"
310 docker stop $CONT > /dev/null 2>&1 || printf "... Error while stopping $CONT\n" 310 docker stop $CONT > /dev/null 2>&1 || eprintf "... Error while stopping $CONT\n"
311 printf "\rDeleting container $CONT" 311 printf "\rDeleting container $CONT"
312 docker rm -v $CONT > /dev/null 2>&1 || printf "... Error while removing $CONT\n" 312 docker rm -v $CONT > /dev/null 2>&1 || eprintf "... Error while removing $CONT\n"
313 done 313 done
314 printf "\n" 314 printf "\n"
315 ;; 315 ;;
316 RESTART) 316 RESTART)
317 printf "restarting containers...\n" 317 printf "restarting containers...\n"
342 errors=0 342 errors=0
343 for CONT in $CONTAINERS data; do 343 for CONT in $CONTAINERS data; do
344 printf "\n*** updating $CONT ***\n" 344 printf "\n*** updating $CONT ***\n"
345 docker pull $ACCOUNT/$CONT:latest 345 docker pull $ACCOUNT/$CONT:latest
346 if [ $? -ne 0 ]; then 346 if [ $? -ne 0 ]; then
347 printf "\nError while updating $ACCOUNT/$CONT\n" 347 eprintf "\nError while updating $ACCOUNT/$CONT\n"
348 errors=1 348 errors=1
349 fi 349 fi
350 done 350 done
351 if [ $errors -eq 0 ]; then 351 if [ $errors -eq 0 ]; then
352 printf "\n\nImages are up-to-date\n" 352 printf "\n\nImages are up-to-date\n"
353 else 353 else
354 printf "\n\nSome errors happened while updating images\n" 354 eprintf "\n\nSome errors happened while updating images\n"
355 exit 1 355 exit 1
356 fi 356 fi
357 ;; 357 ;;
358 BACKUP) 358 BACKUP)
359 case $# in 359 case $# in
368 printf "backing up data container to ${SAT_CONT_BACKUP_DIR}${filename}\n\n" 368 printf "backing up data container to ${SAT_CONT_BACKUP_DIR}${filename}\n\n"
369 docker run --rm $DK_VOLUME -v "$SAT_CONT_BACKUP_DIR:/backup" $MAINT_CONT tar zcvf "/backup/$filename" -C / -h volumes 369 docker run --rm $DK_VOLUME -v "$SAT_CONT_BACKUP_DIR:/backup" $MAINT_CONT tar zcvf "/backup/$filename" -C / -h volumes
370 if [ $? -eq 0 ]; then 370 if [ $? -eq 0 ]; then
371 printf "\nBackup finished and available at ${SAT_CONT_BACKUP_DIR}${filename}\n" 371 printf "\nBackup finished and available at ${SAT_CONT_BACKUP_DIR}${filename}\n"
372 else 372 else
373 printf "\nBackup Error !\n" 373 eprintf "\nBackup Error !\n"
374 exit 1 374 exit 1
375 fi 375 fi
376 ;; 376 ;;
377 RESTORE) 377 RESTORE)
378 if [ $# -ne 1 ]; then 378 if [ $# -ne 1 ]; then
379 printf "syntaxe is $0 restore <backup_file.tar.gz>\n" 379 printf "syntaxe is $0 restore <backup_file.tar.gz>\n"
380 exit 1 380 exit 1
381 fi 381 fi
382 docker run --name $VOLUME_ALIAS $VOLUME_CONT > /dev/null 2>&1 382 docker run --name $VOLUME_ALIAS $VOLUME_CONT > /dev/null 2>&1
383 if [ $? -ne 0 ]; then 383 if [ $? -ne 0 ]; then
384 printf "Can't create $VOLUME_ALIAS container.\n\ 384 eprintf "Can't create $VOLUME_ALIAS container.\n\
385 If you have an existing one, please remove it with \"docker rm -v $VOLUME_ALIAS\" (/!\\ it will remove *ALL* your data)\n\n\ 385 If you have an existing one, please remove it with \"docker rm -v $VOLUME_ALIAS\" (/!\\ it will remove *ALL* your data)\n\n\
386 Hint: you can also rename your current data container with \"docker rename $VOLUME_ALIAS new_container_name\"\n" 386 Hint: you can also rename your current data container with \"docker rename $VOLUME_ALIAS new_container_name\"\n"
387 exit 1 387 exit 1
388 fi 388 fi
389 389
396 fi 396 fi
397 docker run --rm $DK_VOLUME -v "$HOST_BACKUP_DIR:/backup" $MAINT_CONT tar zxvf "/backup/$HOST_BACKUP_NAME" -C / -h volumes 397 docker run --rm $DK_VOLUME -v "$HOST_BACKUP_DIR:/backup" $MAINT_CONT tar zxvf "/backup/$HOST_BACKUP_NAME" -C / -h volumes
398 if [ $? -eq 0 ]; then 398 if [ $? -eq 0 ]; then
399 printf "\nRestore finished\n" 399 printf "\nRestore finished\n"
400 else 400 else
401 printf "\nRestore Error !\n" 401 eprintf "\nRestore Error !\n"
402 exit 1 402 exit 1
403 fi 403 fi
404 ;; 404 ;;
405 PORTS) 405 PORTS)
406 list_ports 406 list_ports
454 printf "usage: $0 stats [--no-stream]\n" 454 printf "usage: $0 stats [--no-stream]\n"
455 exit 1 455 exit 1
456 fi 456 fi
457 docker stats $1 $CONTAINERS 457 docker stats $1 $CONTAINERS
458 ;; 458 ;;
459 *) printf "Error: unknown command !" 459 *) eprintf "Error: unknown command !"
460 exit 2 460 exit 2
461 esac 461 esac