From 23468032b335c5e000b908f38ed5776ed1209342 Mon Sep 17 00:00:00 2001 From: Lars Kellogg-Stedman Date: Wed, 12 Jul 2017 16:16:46 -0400 Subject: [PATCH] healthchecks: implement service-specific checks This introduces health checks for a number of OpenStack services. Change-Id: I9882d5047c960499dae279eda5d9cbacc01ac5d3 Implements: blueprint container-healthchecks --- healthcheck/README.md | 19 +++++++++++++++++++ healthcheck/common.sh | 15 +++++++++++++++ healthcheck/glance-api | 8 ++++++++ healthcheck/heat-api | 8 +++++--- healthcheck/heat-api-cfn | 7 +++++++ healthcheck/keystone-admin | 7 +++++++ healthcheck/keystone-public | 7 +++++++ healthcheck/nova-api | 7 +++++++ 8 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 healthcheck/README.md create mode 100644 healthcheck/common.sh create mode 100755 healthcheck/glance-api create mode 100755 healthcheck/heat-api-cfn create mode 100755 healthcheck/keystone-admin create mode 100755 healthcheck/keystone-public create mode 100755 healthcheck/nova-api diff --git a/healthcheck/README.md b/healthcheck/README.md new file mode 100644 index 000000000..22abeee87 --- /dev/null +++ b/healthcheck/README.md @@ -0,0 +1,19 @@ +# Health check commands + +The scripts in this directory are meant to implement the +[container-healthcheck][] blueprint. They are written to be compatible +with the Docker [HEALTHCHECK][] api. + +[container-healthcheck]: https://blueprints.launchpad.net/tripleo/+spec/container-healthchecks +[healthcheck]: https://docs.docker.com/engine/reference/builder/#healthcheck + +The scripts expect to source +`/usr/share/tripleo-common/healthcheck/common.sh`. If you +want to run scripts without installing to that file, you can set the +`HEALTHCHECKS_DIR` environment variable, e.g: + + $ export HEALTHCHECKS_DIR=$PWD + $ ./heat-api + {"versions": [{"status": "CURRENT", "id": "v1.0", "links": [{"href": "http://192.168.24.1:8004/v1/", "rel": "self"}]}]} + 300 192.168.24.1:8004 0.002 seconds + diff --git a/healthcheck/common.sh b/healthcheck/common.sh new file mode 100644 index 000000000..ad090bfb6 --- /dev/null +++ b/healthcheck/common.sh @@ -0,0 +1,15 @@ +: ${HEALTHCHECK_CURL_MAX_TIME:=10} +: ${HEALTHCHECK_CURL_USER_AGENT:=curl-healthcheck} +: ${HEALTHCHECK_CURL_WRITE_OUT:='\n%{http_code} %{remote_ip}:%{remote_port} %{time_total} seconds\n'} + +healthcheck_curl () { + curl -q --fail \ + --max-time "${HEALTHCHECK_CURL_MAX_TIME}" \ + --user-agent "${HEALTHCHECK_CURL_USER_AGENT}" \ + --write-out "${HEALTHCHECK_CURL_WRITE_OUT}" \ + "$@" || return 1 +} + +get_config_val () { + crudini --get "$1" "$2" "$3" 2> /dev/null || echo "$4" +} diff --git a/healthcheck/glance-api b/healthcheck/glance-api new file mode 100755 index 000000000..1f220a790 --- /dev/null +++ b/healthcheck/glance-api @@ -0,0 +1,8 @@ +#!/bin/sh + +. ${HEALTHCHECK_SCRIPTS:-/usr/share/tripleo-common/healthcheck}/common.sh + +bind_host=$(get_config_val /etc/glance/glance-api.conf DEFAULT bind_host 127.0.0.1) +bind_port=$(get_config_val /etc/glance/glance-api.conf DEFAULT bind_port 9292) + +healthcheck_curl http://${bind_host}:${bind_port}/ diff --git a/healthcheck/heat-api b/healthcheck/heat-api index db85faf70..0f981c8e1 100755 --- a/healthcheck/heat-api +++ b/healthcheck/heat-api @@ -1,5 +1,7 @@ #!/bin/sh -bind_host=$(crudini --get /etc/heat/heat.conf heat_api bind_host 2> /dev/null || echo 127.0.0.1) -bind_port=$(crudini --get /etc/heat/heat.conf heat_api bind_port 2> /dev/null || echo 8004) -curl --fail http://${bind_host}:${bind_port}/ || exit 1 +. ${HEALTHCHECK_SCRIPTS:-/usr/share/tripleo-common/healthcheck}/common.sh + +bind_host=$(get_config_val /etc/heat/heat.conf heat_api bind_host 127.0.0.1) +bind_port=$(get_config_val /etc/heat/heat.conf heat_api bind_port 8004) +healthcheck_curl http://${bind_host}:${bind_port}/ diff --git a/healthcheck/heat-api-cfn b/healthcheck/heat-api-cfn new file mode 100755 index 000000000..4120494c2 --- /dev/null +++ b/healthcheck/heat-api-cfn @@ -0,0 +1,7 @@ +#!/bin/sh + +. ${HEALTHCHECK_SCRIPTS:-/usr/share/tripleo-common/healthcheck}/common.sh + +bind_host=$(get_config_val /etc/heat/heat.conf heat_api_cfn bind_host 127.0.0.1) +bind_port=$(get_config_val /etc/heat/heat.conf heat_api_cfn bind_port 8000) +healthcheck_curl http://${bind_host}:${bind_port}/ diff --git a/healthcheck/keystone-admin b/healthcheck/keystone-admin new file mode 100755 index 000000000..6e1cc819f --- /dev/null +++ b/healthcheck/keystone-admin @@ -0,0 +1,7 @@ +#!/bin/sh + +. ${HEALTHCHECK_SCRIPTS:-/usr/share/tripleo-common/healthcheck}/common.sh + +bind_host=$(get_config_val /etc/keystone/keystone.conf DEFAULT admin_bind_host 127.0.0.1) +bind_port=$(get_config_val /etc/keystone/keystone.conf DEFAULT admin_port 5000) +healthcheck_curl http://${bind_host}:${bind_port}/ diff --git a/healthcheck/keystone-public b/healthcheck/keystone-public new file mode 100755 index 000000000..2be61b996 --- /dev/null +++ b/healthcheck/keystone-public @@ -0,0 +1,7 @@ +#!/bin/sh + +. ${HEALTHCHECK_SCRIPTS:-/usr/share/tripleo-common/healthcheck}/common.sh + +bind_host=$(get_config_val /etc/keystone/keystone.conf DEFAULT public_bind_host 127.0.0.1) +bind_port=$(get_config_val /etc/keystone/keystone.conf DEFAULT public_port 5000) +healthcheck_curl http://${bind_host}:${bind_port}/ diff --git a/healthcheck/nova-api b/healthcheck/nova-api new file mode 100755 index 000000000..792e33df0 --- /dev/null +++ b/healthcheck/nova-api @@ -0,0 +1,7 @@ +#!/bin/sh + +. ${HEALTHCHECK_SCRIPTS:-/usr/share/tripleo-common/healthcheck}/common.sh + +bind_host=$(get_config_val /etc/nova/nova.conf DEFAULT osapi_compute_listen 127.0.0.1) +bind_port=$(get_config_val /etc/nova/nova.conf DEFAULT osapi_compute_listen_port 8774) +healthcheck_curl http://${bind_host}:${bind_port}/