lib/einhorn/command/interface.rb in einhorn-0.4.2 vs lib/einhorn/command/interface.rb in einhorn-0.4.3

- old
+ new

@@ -290,13 +290,10 @@ # In the normal case, this will do a write # synchronously. Otherwise, the bytes will be stuck into the # buffer and lost upon reload. send_message(conn, 'Reloading, as commanded') Einhorn::Command.reload - - # Reload should not return - raise "Not reachable" end command 'inc', 'Increment the number of Einhorn child processes' do Einhorn::Command.increment end @@ -357,9 +354,35 @@ response = Einhorn::Command.signal_all(signal, Einhorn::WorkerPool.workers) Einhorn::State.respawn = false "Einhorn is going down! #{response}" + end + + command 'config', 'Merge in a new set of config options. (Note: this will likely be subsumed by config file reloading at some point.)' do |conn, request| + args = request['args'] + if message = validate_args(args) + next message + end + + unless args.length > 0 + next 'Must pass in a YAML-encoded hash' + end + + begin + # We do the joining so people don't need to worry about quoting + parsed = YAML.load(args.join(' ')) + rescue ArgumentError => e + next 'Could not parse argument. Must be a YAML-encoded hash' + end + + unless parsed.kind_of?(Hash) + next "Parsed argument is a #{parsed.class}, not a hash" + end + + Einhorn::State.state.merge!(parsed) + + "Successfully merged in config: #{parsed.inspect}" end def self.validate_args(args) return 'No args provided' unless args return 'Args must be an array' unless args.kind_of?(Array)