Class: Falcon::Services

Inherits:
Object
  • Object
show all
Defined in:
lib/falcon/services.rb

Overview

Represents one or more services associated with a host.

The services model allows falcon to manage one more more service associated with a given host. Some examples of services include:

The list of services is typically generated from the user supplied ‘falcon.rb` configuration file, which is loaded into an immutable Configuration instance, which is mapped into a list of services.

Instance Method Summary collapse

Constructor Details

#initialize(configuration) ⇒ Services

Initialize the services from the given configuration.



39
40
41
42
43
44
45
46
47
# File 'lib/falcon/services.rb', line 39

def initialize(configuration)
	@named = {}
	
	configuration.each(:service) do |environment|
		service = Service::Generic.wrap(environment)
		
		add(service)
	end
end

Instance Method Details

#add(service) ⇒ Object

Add a named service.



57
58
59
# File 'lib/falcon/services.rb', line 57

def add(service)
	@named[service.name] = service
end

#each(&block) ⇒ Object

Enumerate all named services.



50
51
52
# File 'lib/falcon/services.rb', line 50

def each(&block)
	@named.each_value(&block)
end

#setup(container) ⇒ Object

Setup all named services into the given container.



72
73
74
75
76
77
78
79
# File 'lib/falcon/services.rb', line 72

def setup(container)
	@named.each do |name, service|
		Async.logger.debug(self) {"Setup #{name} into #{container}..."}
		service.setup(container)
	end
	
	return container
end

#startObject

Start all named services.



62
63
64
65
66
67
# File 'lib/falcon/services.rb', line 62

def start
	@named.each do |name, service|
		Async.logger.debug(self) {"Starting #{name}..."}
		service.start
	end
end

#stopObject

Stop all named services.



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/falcon/services.rb', line 82

def stop
	failed = false
	
	@named.each do |name, service|
		Async.logger.debug(self) {"Stopping #{name}..."}
		
		begin
			service.stop
		rescue
			failed = true
			Async.logger.error(self, $!)
		end
	end
	
	return failed
end