comparison docker/libervia_cont.sh @ 103:e69883c1ec30

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.
author Goffi <goffi@goffi.org>
date Sat, 27 Feb 2016 00:45:40 +0100
parents 61ff3bef94a6
children b59491821a8a
comparison
equal deleted inserted replaced
102:61ff3bef94a6 103:e69883c1ec30
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.3.0" 19 VERSION="0.3.0"
20 APP_NAME="Libervia"
20 ACCOUNT="salutatoi" 21 ACCOUNT="salutatoi"
21 22
22 # environment variables that can be used for configuration: 23 # environment variables that can be used for configuration:
23 # SAT_CONT_TLS_DIR for TLS certificates directory 24 # SAT_CONT_TLS_DIR for TLS certificates directory
24 # SAT_CONT_DOMAIN for the host name 25 # SAT_CONT_DOMAIN for the host name
25 # SAT_CONT_BACKUP_DIR is the directory where tar.gz backup will be written 26 # SAT_CONT_BACKUP_DIR is the directory where tar.gz backup will be written
26 # SAT_CONT_DK_EXTRA is used for extra options (used with all containers but sat_data) 27 # SAT_CONT_DK_EXTRA is used for extra options (used with all containers but sat_data)
27 # SAT_CONT_PORT_<port> is used to specify port when -p is used, <port> must be an exposed port 28 # SAT_CONT_PORT_<port> is used to specify port when -p is used, <port> must be an exposed port
28 29
29 CONTAINERS="prosody sat_pubsub salut sat libervia" 30 CONTAINERS="prosody sat_pubsub salut sat libervia"
31 TEST_CONT="libervia" # container used to test status
30 32
31 DK_DETACH="-d" 33 DK_DETACH="-d"
32 DK_TERM="-ti" 34 DK_TERM="-ti"
33 35
34 VOLUME_NAME="data" 36 VOLUME_NAME="data"
52 PORT_8443_NAME="HTTPS" 54 PORT_8443_NAME="HTTPS"
53 NO_PORT="No public port" 55 NO_PORT="No public port"
54 56
55 DOCKER_EXE="docker" 57 DOCKER_EXE="docker"
56 58
57 USAGE="Usage: $0 [start|stop|restart|update|backup|restore|ports|config] [ARGS...]" 59 USAGE="Usage: $0 [start|stop|restart|status|update|backup|restore|ports|config] [ARGS...]"
58 60
59 HELP_SITE="https://wiki.goffi.org/wiki/Docker/en" 61 HELP_SITE="https://wiki.goffi.org/wiki/Docker/en"
60 HELP_MUC="sat@chat.jabberfr.org" 62 HELP_MUC="sat@chat.jabberfr.org"
61 63
62 CONT_CERT_DIR="/usr/share/sat/certificates" 64 CONT_CERT_DIR="/usr/share/sat/certificates"
196 if [ $# -ge 1 ];then 198 if [ $# -ge 1 ];then
197 case $1 in 199 case $1 in
198 start) CMD=START;; 200 start) CMD=START;;
199 stop) CMD=STOP;; 201 stop) CMD=STOP;;
200 restart) CMD=RESTART;; 202 restart) CMD=RESTART;;
203 status) CMD=STATUS;;
201 update) CMD=UPDATE;; 204 update) CMD=UPDATE;;
202 backup) CMD=BACKUP;; 205 backup) CMD=BACKUP;;
203 restore) CMD=RESTORE;; 206 restore) CMD=RESTORE;;
204 ports) CMD=PORTS;; 207 ports) CMD=PORTS;;
205 config) CMD=CONFIG;; 208 config) CMD=CONFIG;;
282 ;; 285 ;;
283 RESTART) 286 RESTART)
284 printf "restarting containers...\n" 287 printf "restarting containers...\n"
285 "$0" stop && "$0" start "$@" 288 "$0" stop && "$0" start "$@"
286 ;; 289 ;;
290 STATUS)
291 docker inspect $TEST_CONT > /dev/null 2>&1
292 if [ $? -eq 0 ]; then
293 printf "$APP_NAME is running"
294 # we test the presence of "starting on xxxx" (where xxxx is one of the exposed ports)
295 # this is not really reliable as ports can be changed in configuration
296 # but in most case it should work OK
297 PORTS_REGEX=$(get_dyn_var $TEST_CONT ports | sed 's/ /\\|/')
298 docker logs $TEST_CONT | grep "starting on \($PORTS_REGEX\)" > /dev/null 2>&1
299 if [ $? -ne 0 ]; then
300 printf " but no server is started\n"
301 exit 2
302 fi
303 printf "\n"
304 exit 0
305 else
306 printf "$APP_NAME is not running\n"
307 exit 1
308 fi
309 ;;
287 UPDATE) 310 UPDATE)
288 printf "updating images...\n" 311 printf "updating images...\n"
289 errors=0 312 errors=0
290 for CONT in $CONTAINERS data; do 313 for CONT in $CONTAINERS data; do
291 printf "\n*** updating $CONT ***\n" 314 printf "\n*** updating $CONT ***\n"