class PhusionPassenger::Config::ReopenLogsCommand
Private Class Methods
create_option_parser(options)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb, line 46 def self.create_option_parser(options) OptionParser.new do |opts| nl = "\n" + ' ' * 37 opts.banner = "Usage: passenger-config reopen-logs [OPTIONS]\n" opts.separator "" opts.separator " Instruct #{PROGRAM_NAME} agent processes to reopen their log files. This" opts.separator " should be invoked after you've rotated log files. This command returns after" opts.separator " the log files have been reopened." opts.separator "" opts.separator "Options:" opts.on("--ignore-logs-not-available", "Exit successfully if #{PROGRAM_NAME}#{nl}" + "was not configured with a log file") do options[:ignore_logs_not_available] = true end opts.on("--instance NAME", String, "The #{PROGRAM_NAME} instance to select") do |value| options[:instance] = value end opts.on("-h", "--help", "Show this help") do options[:help] = true end end end
Public Instance Methods
run()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb, line 39 def run parse_options select_passenger_instance perform_reopen_logs end
Private Instance Methods
handle_error(name, response)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb, line 117 def handle_error(name, response) json = PhusionPassenger::Utils::JSON.parse(response.body) if !should_ignore_error?(json) STDERR.puts "*** An error occured while communicating with the #{PROGRAM_NAME} #{name} (code #{response.code}):" STDERR.puts json['message'] abort end end
perform_reinherit_logs_on(name, socket_name)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb, line 97 def perform_reinherit_logs_on(name, socket_name) puts "Reopening logs for #{PROGRAM_NAME} #{name} (through reinheritance)" request = Net::HTTP::Post.new("/reinherit_logs.json") try_performing_full_admin_basic_auth(request, @instance) request.content_type = "application/json" response = @instance.http_request("agents.s/#{socket_name}", request) if response.code.to_i == 401 print_full_admin_command_permission_error abort elsif response["content-type"] == "application/json" if response.code.to_i / 100 != 2 handle_error(name, response) end else STDERR.puts "*** An error occured while communicating with the #{PROGRAM_NAME} #{name} (code #{response.code}):" STDERR.puts response.body abort end end
perform_reopen_logs()
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb, line 70 def perform_reopen_logs perform_reopen_logs_on("watchdog", "watchdog_api") perform_reinherit_logs_on("core", "core_api") perform_reinherit_logs_on("UstRouter", "ust_router_api") puts "All done" end
perform_reopen_logs_on(name, socket_name)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb, line 77 def perform_reopen_logs_on(name, socket_name) puts "Reopening logs for #{PROGRAM_NAME} #{name}" request = Net::HTTP::Post.new("/reopen_logs.json") try_performing_full_admin_basic_auth(request, @instance) request.content_type = "application/json" response = @instance.http_request("agents.s/#{socket_name}", request) if response.code.to_i == 401 print_full_admin_command_permission_error abort elsif response["content-type"] == "application/json" if response.code.to_i / 100 != 2 handle_error(name, response) end else STDERR.puts "*** An error occured while communicating with the #{PROGRAM_NAME} #{name} (code #{response.code}):" STDERR.puts response.body abort end end
should_ignore_error?(json)
click to toggle source
# File src/ruby_supportlib/phusion_passenger/config/reopen_logs_command.rb, line 126 def should_ignore_error?(json) return @options[:ignore_logs_not_available] && json["code"] == "NO_LOG_FILE" end