class DummyLogGenerator::CLI

Public Class Methods

new(args = [], opts = [], config = {}) click to toggle source
Calls superclass method
# File lib/dummy_log_generator/cli.rb, line 12
def initialize(args = [], opts = [], config = {})
  super(args, opts, config)
end

Public Instance Methods

graceful_restart() click to toggle source
# File lib/dummy_log_generator/cli.rb, line 82
def graceful_restart
  pid = File.read(@options["pid_path"]).to_i

  begin
    Process.kill("USR1", pid)
    puts "Gracefully restarted #{pid}"
  rescue Errno::ESRCH
    puts "DummyLogGenerator #{pid} not running"
  end
end
graceful_stop() click to toggle source
# File lib/dummy_log_generator/cli.rb, line 58
def graceful_stop
  pid = File.read(@options["pid_path"]).to_i

  begin
    Process.kill("TERM", pid)
    puts "Gracefully stopped #{pid}"
  rescue Errno::ESRCH
    puts "DummyLogGenerator #{pid} not running"
  end
end
restart() click to toggle source
# File lib/dummy_log_generator/cli.rb, line 70
def restart
  pid = File.read(@options["pid_path"]).to_i

  begin
    Process.kill("HUP", pid)
    puts "Restarted #{pid}"
  rescue Errno::ESRCH
    puts "DummyLogGenerator #{pid} not running"
  end
end
start() click to toggle source
# File lib/dummy_log_generator/cli.rb, line 25
def start
  @options = @options.dup # avoid frozen
  dsl =
    if options[:config] && File.exists?(options[:config])
      instance_eval(File.read(options[:config]), options[:config])
    else
      DummyLogGenerator::Dsl.new
    end
  @options[:setting] = dsl.setting
  dsl.setting.rate = options[:rate] if options[:rate]
  dsl.setting.output = options[:output] if options[:output]
  dsl.setting.message = options[:message] if options[:message]
  # options for serverengine
  @options[:workers] ||= dsl.setting.workers

  opts = @options.symbolize_keys.except(:config)
  se = ServerEngine.create(nil, DummyLogGenerator::Worker, opts)
  se.run
end
stop() click to toggle source
# File lib/dummy_log_generator/cli.rb, line 46
def stop
  pid = File.read(@options["pid_path"]).to_i

  begin
    Process.kill("QUIT", pid)
    puts "Stopped #{pid}"
  rescue Errno::ESRCH
    puts "DummyLogGenerator #{pid} not running"
  end
end