Class: Dummer::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/dummer/cli.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = [], opts = [], config = {}) ⇒ CLI

Returns a new instance of CLI.



12
13
14
# File 'lib/dummer/cli.rb', line 12

def initialize(args = [], opts = [], config = {})
  super(args, opts, config)
end

Instance Method Details

#graceful_restartObject



88
89
90
91
92
93
94
95
96
97
# File 'lib/dummer/cli.rb', line 88

def graceful_restart
  pid = File.read(@options["pid_path"]).to_i

  begin
    Process.kill("USR1", pid)
    puts "Gracefully restarted #{pid}"
  rescue Errno::ESRCH
    puts "Dummer #{pid} not running"
  end
end

#graceful_stopObject



64
65
66
67
68
69
70
71
72
73
# File 'lib/dummer/cli.rb', line 64

def graceful_stop
  pid = File.read(@options["pid_path"]).to_i

  begin
    Process.kill("TERM", pid)
    puts "Gracefully stopped #{pid}"
  rescue Errno::ESRCH
    puts "Dummer #{pid} not running"
  end
end

#restartObject



76
77
78
79
80
81
82
83
84
85
# File 'lib/dummer/cli.rb', line 76

def restart
  pid = File.read(@options["pid_path"]).to_i

  begin
    Process.kill("HUP", pid)
    puts "Restarted #{pid}"
  rescue Errno::ESRCH
    puts "Dummer #{pid} not running"
  end
end

#startObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/dummer/cli.rb', line 28

def start
  @options = @options.dup # avoid frozen
  dsl =
    if options[:config] && File.exists?(options[:config])
      instance_eval(File.read(options[:config]), options[:config])
    else
      Dummer::Dsl.new
    end
  dsl.setting.rate = options[:rate] if options[:rate]
  dsl.setting.output = options[:output] if options[:output]
  dsl.setting.host = options[:host] if options[:host]
  dsl.setting.port = options[:port] if options[:port]
  dsl.setting.message = options[:message] if options[:message]
  @options[:setting] = dsl.setting
  # options for serverengine
  @options[:workers] ||= dsl.setting.workers
  @options[:log] ||= dsl.setting.log

  opts = @options.symbolize_keys.except(:config)
  se = ServerEngine.create(nil, Dummer::Worker, opts)
  se.run
end

#stopObject



52
53
54
55
56
57
58
59
60
61
# File 'lib/dummer/cli.rb', line 52

def stop
  pid = File.read(@options["pid_path"]).to_i

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