Class: MultiDaemons::Controller
- Inherits:
-
Object
- Object
- MultiDaemons::Controller
- Defined in:
- lib/multi_daemons/controller.rb
Overview
To control daemons
Instance Attribute Summary collapse
-
#daemons ⇒ Object
Returns the value of attribute daemons.
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(daemons, options = {}) ⇒ Controller
constructor
A new instance of Controller.
- #start ⇒ Object
- #status ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(daemons, options = {}) ⇒ Controller
Returns a new instance of Controller.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/multi_daemons/controller.rb', line 6 def initialize(daemons, = {}) @daemons = daemons @options = unless ARGV[1].to_s.empty? @daemons = filter_daemons(daemons) msg = "Daemon [#{ARGV[1]}] not exist."\ " Available ones are #{daemons.map(&:name)}" Log.log msg if @daemons.empty? end end |
Instance Attribute Details
#daemons ⇒ Object
Returns the value of attribute daemons.
4 5 6 |
# File 'lib/multi_daemons/controller.rb', line 4 def daemons @daemons end |
#options ⇒ Object
Returns the value of attribute options.
4 5 6 |
# File 'lib/multi_daemons/controller.rb', line 4 def @options end |
Instance Method Details
#start ⇒ Object
17 18 19 |
# File 'lib/multi_daemons/controller.rb', line 17 def start daemons.each(&:start) end |
#status ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/multi_daemons/controller.rb', line 34 def status daemon_attrs = {} daemons.each do |daemon| daemon.pids.each { |pid| daemon_attrs["#{daemon.name}-#{pid}"] = pid } end daemon_attrs.each do |pid_name, pid| puts "#{pid_name}: #{print_status(Pid.running?(pid))}" end end |
#stop ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/multi_daemons/controller.rb', line 21 def stop pids = [] pid_files = [] daemons.each do |daemon| daemon.multiple = true daemon.stop pids << daemon.pids pid_files << daemon.pid_file end Pid.force_kill(pids.flatten, force_kill_timeout) PidStore.cleanup(pid_files) end |