Module: MasterManipulator::Log
- Included in:
- Beaker::TestCase
- Defined in:
- lib/master_manipulator/log.rb
Instance Method Summary collapse
-
#rotate_puppet_server_log(master_host) ⇒ Object
Rollover the puppetserver log file the same way logback would.
Instance Method Details
#rotate_puppet_server_log(master_host) ⇒ Object
Rollover the puppetserver log file the same way logback would
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 |
# File 'lib/master_manipulator/log.rb', line 12 def rotate_puppet_server_log(master_host) log_dir = on(master_host, "puppet config print logdir").stdout.chomp #this is ugly, rev 2 should parse the logback.xml, doesn't seem to be another way log_file = log_dir + "server/puppetserver.log" date_str = on(master_host, "date +%Y-%m-%d").stdout.chomp backup_log_file = log_file.sub(/\log$/,date_str) if ( on(master_host, "test -f #{log_file}",:accept_all_exit_codes => true).exit_code != 0 ) then raise("Puppetserver log file missing: #{log_file}") end i = 0 max = 100 while (i < max) do if ( on(master_host, "test -f #{backup_log_file}.#{i}.log",:accept_all_exit_codes => true).exit_code == 1 ) then backup_log_file = "#{backup_log_file}.#{i}.log" break end i += 1 end if ( i == max ) then raise("Looks like #{max} puppetserver log rotations in one minute, more likely a code issue") end if ( on(master_host, "cp #{log_file} #{backup_log_file}; cat /dev/null > #{log_file}",:accept_all_exit_codes => true).exit_code != 0 ) then raise("The copy truncate operation failed: cp #{log_file} #{backup_log_file}; cat /dev/null > #{log_file}"); end end |