def self.ensure_running(port = nil)
port ||= `puppet config print masterport`.chomp
begin
running = (%x{curl -sS --cert #{::Utils.puppet_info[:config]['certdir']}/`hostname`.pem --key #{::Utils.puppet_info[:config]['ssldir']}/private_keys/`hostname`.pem -k -H "Accept: s" https://localhost:#{port}/production/certificate_revocation_list/ca 2>&1} =~ /CRL/)
unless running
system('puppet resource service puppetserver ensure="running" enable=true > /dev/null 2>&1 &')
stages = %w{. o O @ *}
rest = 0.4
timeout = 5
Timeout::timeout(timeout*60) {
while not running do
running = (%x{curl -sS --cert #{::Utils.puppet_info[:config]['certdir']}/`hostname`.pem --key #{::Utils.puppet_info[:config]['ssldir']}/private_keys/`hostname`.pem -k -H "Accept: s" https://localhost:#{port}/production/certificate_revocation_list/ca 2>&1} =~ /CRL/)
stages.each{ |x|
$stdout.flush
print "Waiting for Puppet Server to Start, on port #{port} " + x + "\r"
sleep(rest)
}
end
}
$stdout.flush
puts
end
rescue Timeout::Error
fail("The Puppet Server did not start within #{timeout} minutes. Please start puppetserver by hand and inspect any issues.")
end
end