aboutsummaryrefslogtreecommitdiff
path: root/docker/base
diff options
context:
space:
mode:
authorZuul <zuul@review.opendev.org>2019-12-13 10:38:52 +0000
committerGerrit Code Review <review@openstack.org>2019-12-13 10:38:52 +0000
commite946ef652fe0bda062c14f6cea106896ea9fe287 (patch)
tree315c0da913709980394e881e226be47137674381 /docker/base
parent3c3d567d33931213ac862e04a740bcf6d7e72c35 (diff)
parent79851d7929027050d0d1e76aaa28e83c141dcc55 (diff)
downloadkolla-e946ef652fe0bda062c14f6cea106896ea9fe287.tar.gz
kolla-e946ef652fe0bda062c14f6cea106896ea9fe287.zip
Merge "Build images with healthcheck scripts for core services"
Diffstat (limited to 'docker/base')
-rw-r--r--docker/base/Dockerfile.j29
-rwxr-xr-xdocker/base/healthcheck_curl12
-rwxr-xr-xdocker/base/healthcheck_filemod15
-rwxr-xr-xdocker/base/healthcheck_listen8
-rwxr-xr-xdocker/base/healthcheck_port8
-rwxr-xr-xdocker/base/healthcheck_socket10
6 files changed, 62 insertions, 0 deletions
diff --git a/docker/base/Dockerfile.j2 b/docker/base/Dockerfile.j2
index c1b4e1c06..e75e44179 100644
--- a/docker/base/Dockerfile.j2
+++ b/docker/base/Dockerfile.j2
@@ -460,6 +460,15 @@ ENTRYPOINT ["dumb-init", "--single-child", "--"]
{% endif %}
+{% if docker_healthchecks %}
+{% block healthcheck_installation %}
+
+COPY healthcheck_curl healthcheck_filemod healthcheck_listen healthcheck_port healthcheck_socket /usr/local/bin/
+RUN chmod 755 /usr/local/bin/healthcheck_*
+
+{% endblock %}
+{% endif %}
+
RUN touch /usr/local/bin/kolla_extend_start \
&& chmod 755 /usr/local/bin/kolla_start /usr/local/bin/kolla_extend_start /usr/local/bin/kolla_set_configs /usr/local/bin/kolla_copy_cacerts \
&& chmod 440 /etc/sudoers \
diff --git a/docker/base/healthcheck_curl b/docker/base/healthcheck_curl
new file mode 100755
index 000000000..2ef8538ba
--- /dev/null
+++ b/docker/base/healthcheck_curl
@@ -0,0 +1,12 @@
+#!/bin/bash
+: ${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_OUTPUT:='/dev/null'}
+
+export NSS_SDB_USE_CACHE=no
+curl -g -k -q -s -S --fail -o "${HEALTHCHECK_CURL_OUTPUT}" \
+ --max-time "${HEALTHCHECK_CURL_MAX_TIME}" \
+ --user-agent "${HEALTHCHECK_CURL_USER_AGENT}" \
+ --write-out "${HEALTHCHECK_CURL_WRITE_OUT}" \
+ "$@" || exit 1
diff --git a/docker/base/healthcheck_filemod b/docker/base/healthcheck_filemod
new file mode 100755
index 000000000..007643d9b
--- /dev/null
+++ b/docker/base/healthcheck_filemod
@@ -0,0 +1,15 @@
+#!/bin/bash
+file_path=$1
+limit_seconds=$2
+
+# if the file doesn't exist, return 1
+if [ ! -f $file_path ]; then
+ echo "${file_path} does not exist for file modification check"
+ exit 1
+fi
+curr_time=$(date +%s)
+last_mod=$(stat -c '%Y' $file_path)
+limit_epoch=$(( curr_time-limit_seconds ))
+if [ ${limit_epoch} -gt ${last_mod} ]; then
+ exit 1
+fi
diff --git a/docker/base/healthcheck_listen b/docker/base/healthcheck_listen
new file mode 100755
index 000000000..70273339c
--- /dev/null
+++ b/docker/base/healthcheck_listen
@@ -0,0 +1,8 @@
+#!/bin/bash
+process=$1
+
+shift 1
+args=$@
+ports=${args// /|}
+pids=$(pgrep -d '|' -f $process)
+ss -lnp | grep -qE ":($ports).*,pid=($pids),"
diff --git a/docker/base/healthcheck_port b/docker/base/healthcheck_port
new file mode 100755
index 000000000..9531bd77a
--- /dev/null
+++ b/docker/base/healthcheck_port
@@ -0,0 +1,8 @@
+#!/bin/bash
+process=$1
+
+shift 1
+args=$@
+ports=${args// /|}
+pids=$(pgrep -d '|' -f $process)
+ss -ntp | grep -qE ":($ports).*,pid=($pids),"
diff --git a/docker/base/healthcheck_socket b/docker/base/healthcheck_socket
new file mode 100755
index 000000000..cd65bae69
--- /dev/null
+++ b/docker/base/healthcheck_socket
@@ -0,0 +1,10 @@
+#!/bin/bash
+process=$1
+socket=$2
+
+# lsof truncate command name to 15 characters and this behaviour
+# cannot be disabled
+if [ ${#process} -gt 15 ] ; then
+ process=${process:0:15}
+fi
+lsof -Fc -Ua $socket | grep -q "c$process"