Class: DummyLogGenerator::CLI
- Inherits:
-
Thor
- Object
- Thor
- DummyLogGenerator::CLI
- Defined in:
- lib/dummy_log_generator/cli.rb
Instance Method Summary collapse
- #graceful_restart ⇒ Object
- #graceful_stop ⇒ Object
-
#initialize(args = [], opts = [], config = {}) ⇒ CLI
constructor
A new instance of CLI.
- #restart ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(args = [], opts = [], config = {}) ⇒ CLI
Returns a new instance of CLI.
12 13 14 |
# File 'lib/dummy_log_generator/cli.rb', line 12 def initialize(args = [], opts = [], config = {}) super(args, opts, config) end |
Instance Method Details
#graceful_restart ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# 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 ⇒ Object
58 59 60 61 62 63 64 65 66 67 |
# 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 ⇒ Object
70 71 72 73 74 75 76 77 78 79 |
# 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 ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/dummy_log_generator/cli.rb', line 25 def start @options = @options.dup # avoid frozen dsl = if [:config] && File.exists?([:config]) instance_eval(File.read([:config]), [:config]) else DummyLogGenerator::Dsl.new end @options[:setting] = dsl.setting dsl.setting.rate = [:rate] if [:rate] dsl.setting.output = [:output] if [:output] dsl.setting. = [:message] if [: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 ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# 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 |