Method: Tengine::Core::Config::Atd#build

Defined in:
lib/tengine/core/config/atd.rb

#buildObject



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/tengine/core/config/atd.rb', line 76

def build
  banner "Usage: tengine_atd [-k action] [-f path_to_config] [-D process_daemon]\n       [-o mq_conn_host] [-p mq_conn_port] [-u mq_conn_user]\n       [-s mq_conn_pass] [-e mq_exchange_name] [-q mq_queue_name]\n       [-G heartbeat_atd_interval]\n"

  field(:action, "start|stop", :type => :string, :default => "start")
  load_config(:config, "path/to/config_file", :type => :string)

  add(:process, Tengine::Core::Config::Atd::Process)
  field(:db, "settings to connect to db", :type => :hash,
    :default => Tengine::Core::Config::DB::DEFAULT_SETTINGS)

  group(:heartbeat) do
    add(:atd      , Tengine::Core::Config::Core::Heartbeat)
  end

  group(:event_queue, :hidden => true) do
    add(:connection, AmqpConnection)
    add(:exchange  , Tengine::Support::Config::Amqp::Exchange, :defaults => {:name => 'tengine_event_exchange'})
    add(:queue     , Tengine::Support::Config::Amqp::Queue   , :defaults => {:name => 'tengine_event_queue'})
  end

  add(:log_common, Tengine::Support::Config::Logger,
    :defaults => {
      :rotation      => 3          ,
      :rotation_size => 1024 * 1024,
      :level         => 'info'     ,
    })
  add(:application_log, Tengine::Core::Config::Atd::LoggerConfig,
    :parameters => {:logger_name => "application"},
    :dependencies => { :process_config => :process, :log_common => :log_common,}){
    self.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} #{level} #{@process_identifier} #{msg}\n"}
  }
  add(:process_stdout_log, Tengine::Core::Config::Atd::LoggerConfig,
    :parameters => {:logger_name => "#{File.basename($PROGRAM_NAME)}_#{::Process.pid}_stdout"},
    :dependencies => { :process_config => :process, :log_common => :log_common,}){
    self.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} STDOUT #{@process_identifier} #{msg}\n"}
  }
  add(:process_stderr_log, Tengine::Core::Config::Atd::LoggerConfig,
    :parameters => {:logger_name => "#{File.basename($PROGRAM_NAME)}_#{::Process.pid}_stderr"},
    :dependencies => { :process_config => :process, :log_common => :log_common,},
    :defaults => {
      :output => proc{ process_config.daemon ? "./log/#{logger_name}.log" : "STDERR" }}){
    self.formatter = lambda{|level, t, prog, msg| "#{t.iso8601} STDERR #{@process_identifier} #{msg}\n"}
  }

  separator("\nGeneral:")
  field(:verbose, "Show detail to this command", :type => :boolean)
  __action__(:version, "show version"){ STDOUT.puts Tengine::Core.version.to_s; exit }
  __action__(:dump_skelton, "dump skelton of config"){ STDOUT.puts YAML.dump(root.to_hash); exit }
  __action__(:help   , "show this help message"){ STDOUT.puts option_parser.help; exit }

  mapping({
      [:action] => :k,
      [:config] => :f,
      [:process, :daemon] => :D,

      [:event_queue, :connection, :host] => :o,
      [:event_queue, :connection, :port] => :p,
      [:event_queue, :connection, :user] => :u,
      [:event_queue, :connection, :pass] => :s,
      [:event_queue, :exchange  , :name] => :e,
      [:event_queue, :queue     , :name] => :q,

      [:heartbeat, :atd, :interval] => :G,

      [:verbose] => :V,
      [:version] => :v,
      [:help] => :h
    })
end