mirror of
https://github.com/fluent/fluentd-ui.git
synced 2026-05-05 10:56:11 +02:00
Add marker for Common methods
This commit is contained in:
parent
e82e81e234
commit
b6b34ff482
@ -42,20 +42,10 @@ class Fluentd
|
||||
extra_options[:config_file] || self.class.default_options[:config_file]
|
||||
end
|
||||
|
||||
def config_backup_dir
|
||||
dir = File.join(FluentdUI.data_dir, "#{Rails.env}_confg_backups")
|
||||
FileUtils.mkdir_p(dir)
|
||||
dir
|
||||
end
|
||||
|
||||
def running_config_backup_dir
|
||||
dir = File.join(FluentdUI.data_dir, "#{Rails.env}_running_confg_backup")
|
||||
FileUtils.mkdir_p(dir)
|
||||
dir
|
||||
end
|
||||
|
||||
def running_config_backup_file
|
||||
File.join(running_config_backup_dir, "running.conf")
|
||||
def pid
|
||||
return unless File.exists?(pid_file)
|
||||
return if File.zero?(pid_file)
|
||||
File.read(pid_file).to_i rescue nil
|
||||
end
|
||||
|
||||
def running?
|
||||
@ -74,6 +64,12 @@ class Fluentd
|
||||
false
|
||||
end
|
||||
|
||||
# -- log
|
||||
def log
|
||||
return "" unless File.exists?(log_file)
|
||||
File.read(log_file) # TODO: large log file
|
||||
end
|
||||
|
||||
def errors_since(since = 1.day.ago)
|
||||
errors = []
|
||||
logged_errors do |error|
|
||||
@ -96,11 +92,6 @@ class Fluentd
|
||||
recent_errors(1).first.try(:[], :subject) || ""
|
||||
end
|
||||
|
||||
def log
|
||||
return "" unless File.exists?(log_file)
|
||||
File.read(log_file) # TODO: large log file
|
||||
end
|
||||
|
||||
def log_tail(limit = nil)
|
||||
return [] unless File.exists?(log_file)
|
||||
|
||||
@ -116,12 +107,7 @@ class Fluentd
|
||||
buf
|
||||
end
|
||||
|
||||
def pid
|
||||
return unless File.exists?(pid_file)
|
||||
return if File.zero?(pid_file)
|
||||
File.read(pid_file).to_i rescue nil
|
||||
end
|
||||
|
||||
# -- config
|
||||
def config
|
||||
File.read(config_file)
|
||||
end
|
||||
@ -147,6 +133,13 @@ class Fluentd
|
||||
end
|
||||
end
|
||||
|
||||
# -- backup methods
|
||||
def config_backup_dir
|
||||
dir = File.join(FluentdUI.data_dir, "#{Rails.env}_confg_backups")
|
||||
FileUtils.mkdir_p(dir)
|
||||
dir
|
||||
end
|
||||
|
||||
def backup_files
|
||||
Dir.glob(File.join("#{config_backup_dir}", "*.conf"))
|
||||
end
|
||||
@ -159,8 +152,26 @@ class Fluentd
|
||||
backup_files_in_old_order.reverse
|
||||
end
|
||||
|
||||
def running_config_backup_dir
|
||||
dir = File.join(FluentdUI.data_dir, "#{Rails.env}_running_confg_backup")
|
||||
FileUtils.mkdir_p(dir)
|
||||
dir
|
||||
end
|
||||
|
||||
def running_config_backup_file
|
||||
File.join(running_config_backup_dir, "running.conf")
|
||||
end
|
||||
|
||||
# -------------- private --------------
|
||||
private
|
||||
|
||||
def exec_dryrun(command, file_path = nil)
|
||||
Bundler.with_clean_env do
|
||||
system("#{command} -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL)
|
||||
raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero?
|
||||
end
|
||||
end
|
||||
|
||||
def backup_running_config
|
||||
#back up config file only when start success
|
||||
return unless yield
|
||||
@ -172,13 +183,6 @@ class Fluentd
|
||||
true
|
||||
end
|
||||
|
||||
def exec_dryrun(command, file_path = nil)
|
||||
Bundler.with_clean_env do
|
||||
system("#{command} -q --dry-run #{options_to_argv(config_file: file_path)}", out: File::NULL, err: File::NULL)
|
||||
raise ::Fluentd::Agent::ConfigError, last_error_message unless $?.exitstatus.zero?
|
||||
end
|
||||
end
|
||||
|
||||
def backup_config
|
||||
return unless File.exists? config_file
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user