Class: Dummer::CLI
- Inherits:
-
Thor
- Object
- Thor
- Dummer::CLI
- Defined in:
- lib/dummer/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/dummer/cli.rb', line 12 def initialize(args = [], opts = [], config = {}) super(args, opts, config) end |
Instance Method Details
#graceful_restart ⇒ Object
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_stop ⇒ Object
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 |
#restart ⇒ Object
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 |
#start ⇒ Object
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 [:config] && File.exists?([:config]) instance_eval(File.read([:config]), [:config]) else Dummer::Dsl.new end dsl.setting.rate = [:rate] if [:rate] dsl.setting.output = [:output] if [:output] dsl.setting.host = [:host] if [:host] dsl.setting.port = [:port] if [:port] dsl.setting. = [:message] if [: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 |
#stop ⇒ Object
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 |