Class: SrvManager::Service
- Inherits:
-
Object
- Object
- SrvManager::Service
- Defined in:
- lib/srv_manager/service.rb
Instance Attribute Summary collapse
-
#auto ⇒ Object
readonly
Returns the value of attribute auto.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#processes ⇒ Object
readonly
Returns the value of attribute processes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(name, command, options = {}) ⇒ Service
constructor
A new instance of Service.
- #restart ⇒ Object
- #start ⇒ Object
- #started? ⇒ Boolean
- #stop ⇒ Object
- #to_hash ⇒ Object
Constructor Details
#initialize(name, command, options = {}) ⇒ Service
Returns a new instance of Service.
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/srv_manager/service.rb', line 9 def initialize(name, command, ={}) @name = name @command = Command.new command, @processes = ([:processes] || 1).times.map do Process.new @command end @auto = [:auto] || false end |
Instance Attribute Details
#auto ⇒ Object (readonly)
Returns the value of attribute auto.
7 8 9 |
# File 'lib/srv_manager/service.rb', line 7 def auto @auto end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/srv_manager/service.rb', line 5 def command @command end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/srv_manager/service.rb', line 4 def name @name end |
#processes ⇒ Object (readonly)
Returns the value of attribute processes.
6 7 8 |
# File 'lib/srv_manager/service.rb', line 6 def processes @processes end |
Class Method Details
.parse(json) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/srv_manager/service.rb', line 43 def self.parse(json) new json['name'], json['command']['text'], dir: json['command']['dir'], env: json['command']['env'], rvm: json['command']['rvm'], processes: json['processes'], auto: json['auto'] end |
Instance Method Details
#restart ⇒ Object
31 32 33 |
# File 'lib/srv_manager/service.rb', line 31 def restart processes.each(&:restart) end |
#start ⇒ Object
21 22 23 24 |
# File 'lib/srv_manager/service.rb', line 21 def start processes.each(&:start) LOGGER.info "Started service #{name}" end |
#started? ⇒ Boolean
35 36 37 |
# File 'lib/srv_manager/service.rb', line 35 def started? processes.map(&:started?).reduce(:|) end |
#stop ⇒ Object
26 27 28 29 |
# File 'lib/srv_manager/service.rb', line 26 def stop processes.each(&:stop) LOGGER.info "Stoped service #{name}" end |
#to_hash ⇒ Object
39 40 41 |
# File 'lib/srv_manager/service.rb', line 39 def to_hash {name: name, command: command.to_hash, processes: processes.count, auto: auto} end |