class ManageIQ::ApplianceConsole::LogfileConfiguration

Constants

LOGFILE_DIRECTORY
LOGFILE_NAME
MIQ_LOGS_CONF

Attributes

current_logrotate_count[RW]
disk[RW]
evm_was_running[RW]
new_logrotate_count[RW]
size[RW]

Public Class Methods

new(config = {}) click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 17
def initialize(config = {})
  self.disk                = config[:disk]
  self.new_logrotate_count = nil

  self.size = Utilities.disk_usage(LOGFILE_DIRECTORY)[0][:total_bytes]
  self.current_logrotate_count = /rotate\s+(\d+)/.match(File.read(MIQ_LOGS_CONF))[1]
  self.evm_was_running = LinuxAdmin::Service.new("evmserverd").running?
end

Public Instance Methods

activate() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 26
def activate
  activate_new_disk && activate_new_logrotate_count
end
ask_questions() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 30
def ask_questions
  clear_screen
  choose_disk if use_new_disk
  choose_logrotate_count if set_new_logrotate_count?
  confirm_selection
end

Private Instance Methods

activate_new_disk() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 86
def activate_new_disk
  return true unless disk
  stop_evm if evm_was_running
  initialize_logfile_disk
  start_evm if evm_was_running
  true
end
activate_new_logrotate_count() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 77
def activate_new_logrotate_count
  return true unless new_logrotate_count
  say 'Activating new logrotate count'
  data = File.read(MIQ_LOGS_CONF)
  data.gsub!(/rotate\s+\d+/, "rotate #{new_logrotate_count}")
  File.write(MIQ_LOGS_CONF, data)
  true
end
choose_disk() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 58
def choose_disk
  self.disk = ask_for_disk("logfile disk")
end
choose_logrotate_count() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 66
def choose_logrotate_count
  say "\t1 GB of disk space is recommended for each saved log rotation."
  if disk
    say "\tThe proposed new disk is #{disk.size.to_i / 1.gigabyte} GB"
  else
    say "\tThe current log disk is #{size.to_i / 1.gigabyte} GB"
  end

  self.new_logrotate_count = ask_for_integer("new log rotate count")
end
confirm_selection() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 39
def confirm_selection
  return false unless disk || new_logrotate_count

  clear_screen
  if disk
    say("\t#{disk.path} with #{disk.size.to_i / 1.gigabyte} GB will be configured as the new logfile disk.")
  end

  if new_logrotate_count
    say("\tThe number of saved logratations will be updated to: #{new_logrotate_count}")
  end

  agree("Confirm continue with these updates (Y/N):")
end
initialize_logfile_disk() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 94
def initialize_logfile_disk
  say 'Initializing logfile disk'
  LogicalVolumeManagement.new(:disk => disk, :mount_point => LOGFILE_DIRECTORY, :name => LOGFILE_NAME).setup

  FileUtils.mkdir_p("#{LOGFILE_DIRECTORY}/apache")
  AwesomeSpawn.run!('/usr/sbin/semanage fcontext -a -t httpd_log_t "#{LOGFILE_DIRECTORY.to_path}(/.*)?"')
  AwesomeSpawn.run!("/sbin/restorecon -R -v #{LOGFILE_DIRECTORY.to_path}") if File.executable?("/sbin/restorecon")
  true
end
set_new_logrotate_count?() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 62
def set_new_logrotate_count?
  agree("Change the saved logrotate count from #{current_logrotate_count}? (Y/N):")
end
start_evm() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 104
def start_evm
  say 'Starting EVM'
  LinuxAdmin::Service.new("evmserverd").enable.start
  LinuxAdmin::Service.new("httpd").enable.start
end
stop_evm() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 110
def stop_evm
  say 'Stopping EVM'
  LinuxAdmin::Service.new("evmserverd").stop
  LinuxAdmin::Service.new("httpd").stop
end
use_new_disk() click to toggle source
# File lib/manageiq/appliance_console/logfile_configuration.rb, line 54
def use_new_disk
  agree("Configure a new logfile disk volume? (Y/N):")
end