Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 18 additions & 9 deletions lib/puppet/provider/puppetdb_conn_validator/puppet_https.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def attempt_connection
end
return true
rescue Errno::ECONNREFUSED => e
Puppet.warning "Unable to connect to puppetdb server (#{host}:#{port}): #{e.inspect} "
Puppet.notice "Unable to connect to puppetdb server (#{host}:#{port}): #{e.inspect} "
return false
end
end
Expand All @@ -38,17 +38,26 @@ def attempt_connection
setup from the local puppet environment to authenticate."

def exists?
start_time = Time.now
timeout = resource[:timeout]

success = attempt_connection
unless success
# It can take several seconds for the puppetdb server to start up;
# especially on the first install. Therefore, our first connection attempt
# may fail. Here we have somewhat arbitrarily chosen to retry one time
# after ten seconds if that situation arises. May want to revisit this,
# but it seems to work OK for the common use case.
Puppet.notice("Failed to connect to puppetdb; sleeping 10 seconds before retry")
sleep 10
success = attempt_connection
while (Time.now - start_time) < timeout
# It can take several seconds for the puppetdb server to start up;
# especially on the first install. Therefore, our first connection attempt
# may fail. Here we have somewhat arbitrarily chosen to retry every 10
# seconds until the configurable timeout has expired.
Puppet.notice("Failed to connect to puppetdb; sleeping 2 seconds before retry")
sleep 2
success = attempt_connection
end
end

unless success
Puppet.notice("Failed to connect to puppetdb within timeout window of #{timeout} seconds; giving up.")
end

success
end

Expand Down
14 changes: 14 additions & 0 deletions lib/puppet/type/puppetdb_conn_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,18 @@
desc 'The port that the puppetdb server should be listening on.'
end

newparam(:timeout) do
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.'
defaultto 15

validate do |value|
# This will raise an error if the string is not convertible to an integer
Integer(value)
end

munge do |value|
Integer(value)
end
end

end
24 changes: 15 additions & 9 deletions manifests/master/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
# be installed. You may specify an explicit version
# number, 'present', or 'latest'. Defaults to
# 'present'.
# ['puppetdb_startup_timeout'] - The maximum amount of time that the module
# should wait for puppetdb to start up; this is most
# important during the initial install of puppetdb.
# Defaults to 15 seconds.
# ['restart_puppet'] - If true, the module will restart the puppet master when
# necessary. The default is 'true'. If set to 'false',
# you must restart the service manually in order to pick
Expand All @@ -43,15 +47,16 @@
# TODO: finish porting this to use params
#
class puppetdb::master::config(
$puppetdb_server = $::clientcert,
$puppetdb_port = 8081,
$manage_routes = true,
$manage_storeconfigs = true,
$puppet_confdir = $puppetdb::params::puppet_confdir,
$puppet_conf = $puppetdb::params::puppet_conf,
$puppetdb_version = $puppetdb::params::puppetdb_version,
$terminus_package = $puppetdb::params::terminus_package,
$puppet_service_name = $puppetdb::params::puppet_service_name,
$puppetdb_server = $::clientcert,
$puppetdb_port = 8081,
$manage_routes = true,
$manage_storeconfigs = true,
$puppet_confdir = $puppetdb::params::puppet_confdir,
$puppet_conf = $puppetdb::params::puppet_conf,
$puppetdb_version = $puppetdb::params::puppetdb_version,
$terminus_package = $puppetdb::params::terminus_package,
$puppet_service_name = $puppetdb::params::puppet_service_name,
$puppetdb_startup_timeout = $puppetdb::params::puppetdb_startup_timeout,
$restart_puppet = true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should also be aligned. Also, if we want to be Puppet 2.6 compatible then the last parameter should not have a trailing ,

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that PuppetDB is compatible with Puppet 2.6, but it wouldn't hurt to remove this anyway. Thanks for the note!

) inherits puppetdb::params {

Expand All @@ -64,6 +69,7 @@
puppetdb_conn_validator { 'puppetdb_conn':
puppetdb_server => $puppetdb_server,
puppetdb_port => $puppetdb_port,
timeout => $puppetdb_startup_timeout,
require => Package[$terminus_package],
}

Expand Down
3 changes: 2 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@
$terminus_package = 'puppetdb-terminus'
}

$puppet_conf = "${puppet_confdir}/puppet.conf"
$puppet_conf = "${puppet_confdir}/puppet.conf"
$puppetdb_startup_timeout = 15
}