From 9055f90dccd3eaafa14c1a41b61ad5418b9f7c96 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sat, 29 Aug 2015 02:31:03 -0400 Subject: [PATCH] Add helper function for inspecting the state of a container This function - `is_container_status` - can be used to inspect whether a container is any of the following: - Dead - OOMKilled - Paused - Restarting - Running It can be useful for deeper inspection as to plugin state --- plugins/common/functions | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/plugins/common/functions b/plugins/common/functions index 66d787b05..56cd23c0a 100755 --- a/plugins/common/functions +++ b/plugins/common/functions @@ -233,6 +233,18 @@ is_container_running () { fi } +is_container_status () { + local CID=$1 + local TEMPLATE="{{.State.$2}}" + local CONTAINER_STATUS=$(docker inspect -f "$TEMPLATE" "$CID" || true) + + if [[ "$CONTAINER_STATUS" == "true" ]]; then + return 0 + else + return 1 + fi +} + is_app_running() { local APP="$1" verify_app_name $APP