Class: Droonga::Command::DroongaEngine::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/droonga/command/droonga_engine.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/droonga/command/droonga_engine.rb', line 118

def initialize
  config = load_config

  @host = config["host"] || Address::DEFAULT_HOST
  @port = config["port"] || Address::DEFAULT_PORT
  @tag  = config["tag"]  || Address::DEFAULT_TAG

  @log_file        = nil
  @daemon          = false
  @pid_file_path   = nil
  @ready_notify_fd = nil

  if have_config_file?
    self.pid_file_path = config["pid_file"] if config["pid_file"]
    self.log_file  = config["log_file"] || Path.default_log_file
    self.log_level = config["log_level"] if config.include?("log_level")
  end
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



116
117
118
# File 'lib/droonga/command/droonga_engine.rb', line 116

def host
  @host
end

#log_fileObject

Returns the value of attribute log_file.



116
117
118
# File 'lib/droonga/command/droonga_engine.rb', line 116

def log_file
  @log_file
end

#pid_file_pathObject

Returns the value of attribute pid_file_path.



116
117
118
# File 'lib/droonga/command/droonga_engine.rb', line 116

def pid_file_path
  @pid_file_path
end

#portObject (readonly)

Returns the value of attribute port.



116
117
118
# File 'lib/droonga/command/droonga_engine.rb', line 116

def port
  @port
end

#ready_notify_fdObject (readonly)

Returns the value of attribute ready_notify_fd.



117
118
119
# File 'lib/droonga/command/droonga_engine.rb', line 117

def ready_notify_fd
  @ready_notify_fd
end

#tagObject (readonly)

Returns the value of attribute tag.



116
117
118
# File 'lib/droonga/command/droonga_engine.rb', line 116

def tag
  @tag
end

Instance Method Details

#add_command_line_options(parser) ⇒ Object



185
186
187
188
189
190
191
# File 'lib/droonga/command/droonga_engine.rb', line 185

def add_command_line_options(parser)
  add_connection_options(parser)
  add_log_options(parser)
  add_process_options(parser)
  add_path_options(parser)
  add_notification_options(parser)
end

#address_familyObject



153
154
155
156
# File 'lib/droonga/command/droonga_engine.rb', line 153

def address_family
  ip_address = IPAddr.new(IPSocket.getaddress(@host))
  ip_address.family
end

#daemon?Boolean

Returns:

  • (Boolean)


174
175
176
# File 'lib/droonga/command/droonga_engine.rb', line 174

def daemon?
  @daemon
end

#engine_nameObject



149
150
151
# File 'lib/droonga/command/droonga_engine.rb', line 149

def engine_name
  "#{@host}:#{@port}/#{@tag}"
end

#have_config_file?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'lib/droonga/command/droonga_engine.rb', line 137

def have_config_file?
  File.exist?(Path.config)
end

#heartbeat_socketObject



197
198
199
# File 'lib/droonga/command/droonga_engine.rb', line 197

def heartbeat_socket
  @heartbeat_socket ||= bind_heartbeat_socket
end

#listen_socketObject



193
194
195
# File 'lib/droonga/command/droonga_engine.rb', line 193

def listen_socket
  @listen_socket ||= TCPServer.new(@host, @port)
end

#load_configObject



141
142
143
144
145
146
147
# File 'lib/droonga/command/droonga_engine.rb', line 141

def load_config
  if have_config_file?
    YAML.load_file(Path.config)
  else
    {}
  end
end

#log_levelObject



158
159
160
# File 'lib/droonga/command/droonga_engine.rb', line 158

def log_level
  ENV["DROONGA_LOG_LEVEL"] || Logger::Level.default
end

#log_level=(level) ⇒ Object



162
163
164
# File 'lib/droonga/command/droonga_engine.rb', line 162

def log_level=(level)
  ENV["DROONGA_LOG_LEVEL"] = level
end

#to_command_lineObject



178
179
180
181
182
183
# File 'lib/droonga/command/droonga_engine.rb', line 178

def to_command_line
  command_line_options = [
    "--engine-name", engine_name,
  ]
  command_line_options
end