Class: SrvManager::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/srv_manager/service.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options={})
  @name = name
  
  @command = Command.new command, options
  
  @processes = (options[:processes] || 1).times.map do 
    Process.new @command
  end

  @auto = options[:auto] || false
end

Instance Attribute Details

#autoObject (readonly)

Returns the value of attribute auto.



7
8
9
# File 'lib/srv_manager/service.rb', line 7

def auto
  @auto
end

#commandObject (readonly)

Returns the value of attribute command.



5
6
7
# File 'lib/srv_manager/service.rb', line 5

def command
  @command
end

#nameObject (readonly)

Returns the value of attribute name.



4
5
6
# File 'lib/srv_manager/service.rb', line 4

def name
  @name
end

#processesObject (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

#restartObject



31
32
33
# File 'lib/srv_manager/service.rb', line 31

def restart
  processes.each(&:restart)
end

#startObject



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

Returns:

  • (Boolean)


35
36
37
# File 'lib/srv_manager/service.rb', line 35

def started?
  processes.map(&:started?).reduce(:|)
end

#stopObject



26
27
28
29
# File 'lib/srv_manager/service.rb', line 26

def stop
  processes.each(&:stop)
  LOGGER.info "Stoped service #{name}"
end

#to_hashObject



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