From 924d3cb5a15eb60e729f477f18a597040d17e9b8 Mon Sep 17 00:00:00 2001 From: Johan Lundberg Date: Wed, 15 Apr 2015 15:20:04 +0200 Subject: Added script ping-check and new pre_start statements for flog_app and flog_nginx --- global/overlay/etc/puppet/manifests/cosmos-site.pp | 8 +++++--- global/overlay/usr/local/bin/ping-check | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) create mode 100755 global/overlay/usr/local/bin/ping-check diff --git a/global/overlay/etc/puppet/manifests/cosmos-site.pp b/global/overlay/etc/puppet/manifests/cosmos-site.pp index c313a0a..88696a4 100644 --- a/global/overlay/etc/puppet/manifests/cosmos-site.pp +++ b/global/overlay/etc/puppet/manifests/cosmos-site.pp @@ -764,11 +764,13 @@ node 'sto-tug-kvm2.swamid.se' { sunet::docker_run {'flog_app': image => 'docker.sunet.se/flog/flog_app', volumes => ['/opt/flog/dotenv:/opt/flog/.env','/var/log/flog/:/opt/flog/logs/'], + pre_start => '/usr/local/bin/ping-check flog_db.docker && run-parts /usr/local/etc/docker.d', } -> sunet::docker_run {'flog_nginx': - image => 'docker.sunet.se/flog/nginx', - ports => ['80:80', '443:443'], - volumes => ['/opt/flog/nginx/sites-enabled/:/etc/nginx/sites-enabled/','/opt/flog/nginx/certs/:/etc/nginx/certs', '/var/log/flog_nginx/:/var/log/nginx'], + image => 'docker.sunet.se/flog/nginx', + ports => ['80:80', '443:443'], + volumes => ['/opt/flog/nginx/sites-enabled/:/etc/nginx/sites-enabled/','/opt/flog/nginx/certs/:/etc/nginx/certs', '/var/log/flog_nginx/:/var/log/nginx'], + pre_start => '/usr/local/bin/ping-check flog_app.docker && run-parts /usr/local/etc/docker.d', } } diff --git a/global/overlay/usr/local/bin/ping-check b/global/overlay/usr/local/bin/ping-check new file mode 100755 index 0000000..26c99ed --- /dev/null +++ b/global/overlay/usr/local/bin/ping-check @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +# +# Ping until reply or MAX_TRIES. One try == 1s. +# + +MAX_TRIES=10 +LOGTAG="sunet_docker_ping_check" + +count=0 +until ping -c1 $1 &> /dev/null +do + if [ $count -gt $MAX_TRIES ] + then + logger -t "$LOGTAG" "No response from $1 after $MAX_TRIES tries." + exit 1 + fi + sleep 1 + count=$[$count+1] +done -- cgit v1.1 From a441b737ad5b17203123f26034c846af3dca4100 Mon Sep 17 00:00:00 2001 From: Johan Lundberg Date: Wed, 15 Apr 2015 16:15:33 +0200 Subject: Changed ping-check to be run with run-parts --- global/overlay/etc/puppet/manifests/cosmos-site.pp | 2 -- .../overlay/usr/local/etc/docker.d/30flog | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100755 sto-tug-kvm2.swamid.se/overlay/usr/local/etc/docker.d/30flog diff --git a/global/overlay/etc/puppet/manifests/cosmos-site.pp b/global/overlay/etc/puppet/manifests/cosmos-site.pp index 88696a4..4249f7f 100644 --- a/global/overlay/etc/puppet/manifests/cosmos-site.pp +++ b/global/overlay/etc/puppet/manifests/cosmos-site.pp @@ -764,13 +764,11 @@ node 'sto-tug-kvm2.swamid.se' { sunet::docker_run {'flog_app': image => 'docker.sunet.se/flog/flog_app', volumes => ['/opt/flog/dotenv:/opt/flog/.env','/var/log/flog/:/opt/flog/logs/'], - pre_start => '/usr/local/bin/ping-check flog_db.docker && run-parts /usr/local/etc/docker.d', } -> sunet::docker_run {'flog_nginx': image => 'docker.sunet.se/flog/nginx', ports => ['80:80', '443:443'], volumes => ['/opt/flog/nginx/sites-enabled/:/etc/nginx/sites-enabled/','/opt/flog/nginx/certs/:/etc/nginx/certs', '/var/log/flog_nginx/:/var/log/nginx'], - pre_start => '/usr/local/bin/ping-check flog_app.docker && run-parts /usr/local/etc/docker.d', } } diff --git a/sto-tug-kvm2.swamid.se/overlay/usr/local/etc/docker.d/30flog b/sto-tug-kvm2.swamid.se/overlay/usr/local/etc/docker.d/30flog new file mode 100755 index 0000000..a90610d --- /dev/null +++ b/sto-tug-kvm2.swamid.se/overlay/usr/local/etc/docker.d/30flog @@ -0,0 +1,20 @@ +#!/bin/bash +# +# Wait for dependent flog docker containers to be registered in local DNS. +# + +PING_CHECK="/usr/local/bin/ping-check" + +logtag="flog_docker_pre-post[$ACTION]" +logger -t "${logtag}" "$NAME ($IMAGE), CID: '$CID'" + +if [ "x$ACTION" = "xpre-start" ]; then + if [ "x$NAME" = "xflog_app" ]; then + ${PING_CHECK} flog_db.docker + exit $? + if [ "x$NAME" = "xflog_nginx" ]; then + ${PING_CHECK} flog_app.docker + exit $? + fi + exit 0 +fi -- cgit v1.1 From a1f6be0730d25fd6f4ecff0d91bc75a8a250c0fe Mon Sep 17 00:00:00 2001 From: Johan Lundberg Date: Wed, 15 Apr 2015 16:29:46 +0200 Subject: Bash skillz lacking... --- sto-tug-kvm2.swamid.se/overlay/usr/local/etc/docker.d/30flog | 1 + 1 file changed, 1 insertion(+) diff --git a/sto-tug-kvm2.swamid.se/overlay/usr/local/etc/docker.d/30flog b/sto-tug-kvm2.swamid.se/overlay/usr/local/etc/docker.d/30flog index a90610d..2b477a2 100755 --- a/sto-tug-kvm2.swamid.se/overlay/usr/local/etc/docker.d/30flog +++ b/sto-tug-kvm2.swamid.se/overlay/usr/local/etc/docker.d/30flog @@ -12,6 +12,7 @@ if [ "x$ACTION" = "xpre-start" ]; then if [ "x$NAME" = "xflog_app" ]; then ${PING_CHECK} flog_db.docker exit $? + fi if [ "x$NAME" = "xflog_nginx" ]; then ${PING_CHECK} flog_app.docker exit $? -- cgit v1.1