# HG changeset patch # User Goffi # Date 1456530340 -3600 # Node ID e69883c1ec30e25dd957c6718eb9219c1e9e0c70 # Parent 61ff3bef94a63139cc4f1f6975adbfc2bf2e42f2 docker (libervia_cont): added a "status" command: - if libervia container is not running, it exits with error code 1 - if libervia container is running but no server is launched, it exits with error code 2 - if libervia container is running and server is launcher, it exits with error code 0 (success) server detection is done by doing a simple grep on logs, that's not perfectly reliable (ports can be changed in configuration, even if that doesn't really make sense in Docker context) but should be good enough for this purpose. diff -r 61ff3bef94a6 -r e69883c1ec30 docker/libervia_cont.sh --- a/docker/libervia_cont.sh Fri Feb 26 23:32:07 2016 +0100 +++ b/docker/libervia_cont.sh Sat Feb 27 00:45:40 2016 +0100 @@ -17,6 +17,7 @@ # along with this program. If not, see . VERSION="0.3.0" +APP_NAME="Libervia" ACCOUNT="salutatoi" # environment variables that can be used for configuration: @@ -27,6 +28,7 @@ # SAT_CONT_PORT_ is used to specify port when -p is used, must be an exposed port CONTAINERS="prosody sat_pubsub salut sat libervia" +TEST_CONT="libervia" # container used to test status DK_DETACH="-d" DK_TERM="-ti" @@ -54,7 +56,7 @@ DOCKER_EXE="docker" -USAGE="Usage: $0 [start|stop|restart|update|backup|restore|ports|config] [ARGS...]" +USAGE="Usage: $0 [start|stop|restart|status|update|backup|restore|ports|config] [ARGS...]" HELP_SITE="https://wiki.goffi.org/wiki/Docker/en" HELP_MUC="sat@chat.jabberfr.org" @@ -198,6 +200,7 @@ start) CMD=START;; stop) CMD=STOP;; restart) CMD=RESTART;; + status) CMD=STATUS;; update) CMD=UPDATE;; backup) CMD=BACKUP;; restore) CMD=RESTORE;; @@ -284,6 +287,26 @@ printf "restarting containers...\n" "$0" stop && "$0" start "$@" ;; + STATUS) + docker inspect $TEST_CONT > /dev/null 2>&1 + if [ $? -eq 0 ]; then + printf "$APP_NAME is running" + # we test the presence of "starting on xxxx" (where xxxx is one of the exposed ports) + # this is not really reliable as ports can be changed in configuration + # but in most case it should work OK + PORTS_REGEX=$(get_dyn_var $TEST_CONT ports | sed 's/ /\\|/') + docker logs $TEST_CONT | grep "starting on \($PORTS_REGEX\)" > /dev/null 2>&1 + if [ $? -ne 0 ]; then + printf " but no server is started\n" + exit 2 + fi + printf "\n" + exit 0 + else + printf "$APP_NAME is not running\n" + exit 1 + fi + ;; UPDATE) printf "updating images...\n" errors=0