From b238d7c2652563c3dcceb2c6ea4d9f3490827fc4 Mon Sep 17 00:00:00 2001 From: Jason Martin Date: Sun, 12 Jul 2015 20:08:43 -0700 Subject: [PATCH] Give consul time to install its HUP signal handler to avoid immediate shutdown when invoked via knife ssh (or any short-lived pty), fixes #125. --- README.md | 8 ++++++++ attributes/default.rb | 3 +++ recipes/service.rb | 3 ++- templates/default/consul-init.erb | 1 + 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15ede472..7286dcea 100644 --- a/README.md +++ b/README.md @@ -280,6 +280,14 @@ Installs and configures [Consul][1] client, server and UI. nil + + ['consul']['startup_sleep'] + Integer + + Delay to return-of-control when invoked via an init.d script. Protects consul from an early HUP. + + 3 + ### Databag Attributes (optional) diff --git a/attributes/default.rb b/attributes/default.rb index b1f22dd3..79f11805 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -138,3 +138,6 @@ default['consul']['atlas_autojoin'] = false default['consul']['atlas_cluster'] = nil default['consul']['atlas_token'] = nil + +# Init script startup delay +default['consul']['startup_sleep'] = 3 diff --git a/recipes/service.rb b/recipes/service.rb index 56bda013..433bc705 100644 --- a/recipes/service.rb +++ b/recipes/service.rb @@ -224,7 +224,8 @@ source init_tmpl mode init_mode variables( - consul_logfile: node['consul']['logfile'] + consul_logfile: node['consul']['logfile'], + startup_sleep: node['consul']['startup_sleep'] ) notifies :restart, 'service[consul]', :immediately end diff --git a/templates/default/consul-init.erb b/templates/default/consul-init.erb index 6d1dab1a..14fc07e7 100644 --- a/templates/default/consul-init.erb +++ b/templates/default/consul-init.erb @@ -48,6 +48,7 @@ case "$1" in CONSULPID=$! echo $CONSULPID > "$PIDFILE" TIMEOUT="$STARTIMEOUT" + sleep <%= @startup_sleep %> while [ $TIMEOUT -gt 0 ]; do if is_running; then break