Mercurial > sat_docs
diff 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 |
line wrap: on
line diff
--- a/docker/libervia_cont.sh Sun Oct 19 19:44:47 2014 +0200 +++ b/docker/libervia_cont.sh Mon Oct 20 13:12:31 2014 +0200 @@ -16,7 +16,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -VERSION="0.1.0" +VERSION="0.2.0" ACCOUNT="salutatoi" CONTAINERS="prosody sat_pubsub salut sat libervia" @@ -24,7 +24,8 @@ DETACH="-d" TERM="-ti" -VOLUME_CONT="$ACCOUNT/data" +VOLUME_NAME="data" +VOLUME_CONT="$ACCOUNT/$VOLUME_NAME" VOLUME_ALIAS="sat_data" VOLUME="--volumes-from $VOLUME_ALIAS" @@ -42,6 +43,8 @@ PORT_8443_NAME="HTTPS" NO_PORT="No public port" +DOCKER_EXE="docker" + USAGE="Usage: $0 [run|stop|update|backup|ports] [ARGS...]" HELP_SITE="http://wiki.goffi.org/wiki/Docker/en" @@ -105,6 +108,32 @@ echo $ARG } +download_missing() { + # download images wich are not present locally + for cont in $VOLUME_NAME $CONTAINERS; do + image="$ACCOUNT/$cont" + docker inspect $image:latest > /dev/null 2>&1 + if [ $? -ne 0 ]; then + printf "$image is not present locally, downloading it\n" + docker pull $image:latest + if [ $? -eq 0 ]; then + printf "\nDownload of latest $image finished\n\n" + else + printf "\nError while downloading $image, please check your connection and logs\n" + return 1 + fi + fi + done +} + +check_docker() { + which $DOCKER_EXE > /dev/null 2>&1 + if [ $? -ne 0 ]; then + printf "Docker is not installed or not accessible, please install it.\nYou can check http://wiki.goffi.org/wiki/Docker/en for instructions\n" + return 1 + fi +} + parse_run_args() { # manage arguments for run command @@ -144,6 +173,7 @@ done } +check_docker || exit 1 if [ $# -ge 1 ];then case $1 in @@ -165,6 +195,8 @@ case $CMD in RUN) parse_run_args "$@" + download_missing || exit 1 + printf "Running data container... " docker_id=$(docker run -d -ti --name $VOLUME_ALIAS $VOLUME_CONT 2>&1) if [ $? -eq 0 ]; then