Skip to content

Commit d1cd651

Browse files
committed
Merge pull request #18 from cprice-puppet/feature/master/configurable-puppetdb-startup-timeout
Make puppetdb startup timeout configurable
2 parents 75532a0 + 783b595 commit d1cd651

4 files changed

Lines changed: 49 additions & 19 deletions

File tree

lib/puppet/provider/puppetdb_conn_validator/puppet_https.rb

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def attempt_connection
2626
end
2727
return true
2828
rescue Errno::ECONNREFUSED => e
29-
Puppet.warning "Unable to connect to puppetdb server (#{host}:#{port}): #{e.inspect} "
29+
Puppet.notice "Unable to connect to puppetdb server (#{host}:#{port}): #{e.inspect} "
3030
return false
3131
end
3232
end
@@ -38,17 +38,26 @@ def attempt_connection
3838
setup from the local puppet environment to authenticate."
3939

4040
def exists?
41+
start_time = Time.now
42+
timeout = resource[:timeout]
43+
4144
success = attempt_connection
4245
unless success
43-
# It can take several seconds for the puppetdb server to start up;
44-
# especially on the first install. Therefore, our first connection attempt
45-
# may fail. Here we have somewhat arbitrarily chosen to retry one time
46-
# after ten seconds if that situation arises. May want to revisit this,
47-
# but it seems to work OK for the common use case.
48-
Puppet.notice("Failed to connect to puppetdb; sleeping 10 seconds before retry")
49-
sleep 10
50-
success = attempt_connection
46+
while (Time.now - start_time) < timeout
47+
# It can take several seconds for the puppetdb server to start up;
48+
# especially on the first install. Therefore, our first connection attempt
49+
# may fail. Here we have somewhat arbitrarily chosen to retry every 10
50+
# seconds until the configurable timeout has expired.
51+
Puppet.notice("Failed to connect to puppetdb; sleeping 2 seconds before retry")
52+
sleep 2
53+
success = attempt_connection
54+
end
5155
end
56+
57+
unless success
58+
Puppet.notice("Failed to connect to puppetdb within timeout window of #{timeout} seconds; giving up.")
59+
end
60+
5261
success
5362
end
5463

lib/puppet/type/puppetdb_conn_validator.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,18 @@
2323
desc 'The port that the puppetdb server should be listening on.'
2424
end
2525

26+
newparam(:timeout) do
27+
desc 'The max number of seconds that the validator should wait before giving up and deciding that puppetdb is not running; defaults to 15 seconds.'
28+
defaultto 15
29+
30+
validate do |value|
31+
# This will raise an error if the string is not convertible to an integer
32+
Integer(value)
33+
end
34+
35+
munge do |value|
36+
Integer(value)
37+
end
38+
end
39+
2640
end

manifests/master/config.pp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
# be installed. You may specify an explicit version
2424
# number, 'present', or 'latest'. Defaults to
2525
# 'present'.
26+
# ['puppetdb_startup_timeout'] - The maximum amount of time that the module
27+
# should wait for puppetdb to start up; this is most
28+
# important during the initial install of puppetdb.
29+
# Defaults to 15 seconds.
2630
# ['restart_puppet'] - If true, the module will restart the puppet master when
2731
# necessary. The default is 'true'. If set to 'false',
2832
# you must restart the service manually in order to pick
@@ -43,15 +47,16 @@
4347
# TODO: finish porting this to use params
4448
#
4549
class puppetdb::master::config(
46-
$puppetdb_server = $::clientcert,
47-
$puppetdb_port = 8081,
48-
$manage_routes = true,
49-
$manage_storeconfigs = true,
50-
$puppet_confdir = $puppetdb::params::puppet_confdir,
51-
$puppet_conf = $puppetdb::params::puppet_conf,
52-
$puppetdb_version = $puppetdb::params::puppetdb_version,
53-
$terminus_package = $puppetdb::params::terminus_package,
54-
$puppet_service_name = $puppetdb::params::puppet_service_name,
50+
$puppetdb_server = $::clientcert,
51+
$puppetdb_port = 8081,
52+
$manage_routes = true,
53+
$manage_storeconfigs = true,
54+
$puppet_confdir = $puppetdb::params::puppet_confdir,
55+
$puppet_conf = $puppetdb::params::puppet_conf,
56+
$puppetdb_version = $puppetdb::params::puppetdb_version,
57+
$terminus_package = $puppetdb::params::terminus_package,
58+
$puppet_service_name = $puppetdb::params::puppet_service_name,
59+
$puppetdb_startup_timeout = $puppetdb::params::puppetdb_startup_timeout,
5560
$restart_puppet = true,
5661
) inherits puppetdb::params {
5762

@@ -64,6 +69,7 @@
6469
puppetdb_conn_validator { 'puppetdb_conn':
6570
puppetdb_server => $puppetdb_server,
6671
puppetdb_port => $puppetdb_port,
72+
timeout => $puppetdb_startup_timeout,
6773
require => Package[$terminus_package],
6874
}
6975

manifests/params.pp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,6 @@
6262
$terminus_package = 'puppetdb-terminus'
6363
}
6464

65-
$puppet_conf = "${puppet_confdir}/puppet.conf"
65+
$puppet_conf = "${puppet_confdir}/puppet.conf"
66+
$puppetdb_startup_timeout = 15
6667
}

0 commit comments

Comments
 (0)