Class: MultiDaemons::Controller

Inherits:
Object
  • Object
show all
Defined in:
lib/multi_daemons/controller.rb

Overview

To control daemons

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @daemons = daemons
  @options = 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

#daemonsObject

Returns the value of attribute daemons


4
5
6
# File 'lib/multi_daemons/controller.rb', line 4

def daemons
  @daemons
end

#optionsObject

Returns the value of attribute options


4
5
6
# File 'lib/multi_daemons/controller.rb', line 4

def options
  @options
end

Instance Method Details

#startObject


17
18
19
# File 'lib/multi_daemons/controller.rb', line 17

def start
  daemons.each(&:start)
end

#statusObject


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

#stopObject


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