Module: Haproxy2Rpm

Defined in:
lib/haproxy2rpm/syslog.rb,
lib/haproxy2rpm.rb,
lib/haproxy2rpm/rpm.rb,
lib/haproxy2rpm/version.rb,
lib/haproxy2rpm/file_parser.rb,
lib/haproxy2rpm/line_parser.rb

Overview

Defined Under Namespace

Classes: FileParser, LineParser, Rpm, SyslogHandler

Constant Summary collapse

VERSION =
"0.2.0"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



15
16
17
# File 'lib/haproxy2rpm.rb', line 15

def logger
  @logger
end

.rpmObject

Returns the value of attribute rpm.



15
16
17
# File 'lib/haproxy2rpm.rb', line 15

def rpm
  @rpm
end

Class Method Details

.default_run(log_file, options) ⇒ Object



48
49
50
51
52
53
54
# File 'lib/haproxy2rpm.rb', line 48

def self.default_run(log_file,options)
  EventMachine.run do
    EventMachine::file_tail(log_file) do |filetail, line|
      @rpm.process_and_send(line)
    end
  end
end

.run(log_file, options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/haproxy2rpm.rb', line 22

def self.run(log_file, options)
  @rpm = Rpm.new(options)
  if(options[:daemonize])
    logger.info 'daemonizing'
    run_daemonized(log_file, options)
  else
    write_pid(options[:pid], Process.pid)
    if(options[:syslog])
      run_syslog_server(options)
    else
      default_run(log_file, options)
    end
  end
end

.run_daemonized(log_file, options) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/haproxy2rpm.rb', line 56

def self.run_daemonized(log_file, options)
    Signal.trap('HUP') {}
    
    pid = fork do
      begin
        if(options[:syslog])
          run_syslog_server(options)
        else
          default_run(log_file, options)
        end
      rescue => e
        logger.error e.message
        logger.error e.backtrace.join("\n")
        abort "There was a fatal system error while starting haproxy2rpm"
      end
    end
    
    write_pid(options[:pid], pid)
    
    ::Process.detach pid
    
    exit
end

.run_syslog_server(options) ⇒ Object



42
43
44
45
46
# File 'lib/haproxy2rpm.rb', line 42

def self.run_syslog_server(options)
  EventMachine::run do
    EventMachine::open_datagram_socket(options[:address], options[:port], SyslogHandler)
  end
end

.stopObject



37
38
39
40
# File 'lib/haproxy2rpm.rb', line 37

def self.stop
  logger.info 'stopping new relic agent'
  NewRelic::Agent.shutdown
end

.write_pid(pid_file, pid) ⇒ Object



80
81
82
83
84
# File 'lib/haproxy2rpm.rb', line 80

def self.write_pid(pid_file, pid)
  if pid_file
    File.open(pid_file, 'w') { |f| f.write pid }
  end 
end