Puppet Function: cd4peadm::db_status_check
- Defined in:
- lib/puppet/functions/cd4peadm/db_status_check.rb
- Function type:
- Ruby 4.x API
Overview
Runs pg_isready on the target node using the given container runtime This is used to confirm the database is up and running before attempting to write to it. Will retry 15 times, with 5 seconds in between checks.
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/puppet/functions/cd4peadm/db_status_check.rb', line 4 Puppet::Functions.create_function(:'cd4peadm::db_status_check') do # @param target The target node to check # @param db_container The container name of the database # @param db_user A valid user id with permissions to access the database # @param runtime The runtime to use to run the command # @return boolean - true if pg_isready returns healthy, false if not dispatch :db_status_check do param 'Target', :target param 'String', :db_container param 'String', :db_user param 'String', :runtime return_type 'Boolean' end def db_status_check(target, db_container, db_user, runtime) max_attempts = 15 sleep_duration_secs = 5 call_function('out::message', "Checking database availability on #{target}") for i in 1..max_attempts do attempt = "Attempt #{i} of #{max_attempts}:" ret = call_function('run_command', "#{runtime} exec #{db_container} pg_isready -U #{db_user}", target, { '_run_as' => 'root', '_catch_errors' => true, } ) ret = ret.to_data[0]['value']['exit_code'] return true if ret == 0 call_function('out::message', "#{attempt} pg_isready returned #{ret}") sleep sleep_duration_secs end return false end end |