Class: Falcon::Services
- Inherits:
-
Object
- Object
- Falcon::Services
- 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:
-
Rack applications wrapped by Falcon::Service::Application.
-
Host supervisor implemented in Falcon::Service::Supervisor.
-
Proxy services wrapped by Falcon::Service::Proxy.
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
-
#add(service) ⇒ Object
Add a named service.
-
#each(&block) ⇒ Object
Enumerate all named services.
-
#initialize(configuration) ⇒ Services
constructor
Initialize the services from the given configuration.
-
#setup(container) ⇒ Object
Setup all named services into the given container.
-
#start ⇒ Object
Start all named services.
-
#stop ⇒ Object
Stop all named services.
Constructor Details
#initialize(configuration) ⇒ Services
Initialize the services from the given configuration.
22 23 24 25 26 27 28 29 30 |
# File 'lib/falcon/services.rb', line 22 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.
40 41 42 |
# File 'lib/falcon/services.rb', line 40 def add(service) @named[service.name] = service end |
#each(&block) ⇒ Object
Enumerate all named services.
33 34 35 |
# File 'lib/falcon/services.rb', line 33 def each(&block) @named.each_value(&block) end |
#setup(container) ⇒ Object
Setup all named services into the given container.
55 56 57 58 59 60 61 62 |
# File 'lib/falcon/services.rb', line 55 def setup(container) @named.each do |name, service| Console.logger.debug(self) {"Setup #{name} into #{container}..."} service.setup(container) end return container end |
#start ⇒ Object
Start all named services.
45 46 47 48 49 50 |
# File 'lib/falcon/services.rb', line 45 def start @named.each do |name, service| Console.logger.debug(self) {"Starting #{name}..."} service.start end end |
#stop ⇒ Object
Stop all named services.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/falcon/services.rb', line 65 def stop failed = false @named.each do |name, service| Console.logger.debug(self) {"Stopping #{name}..."} begin service.stop rescue => error failed = true Console.logger.error(self, error) end end return failed end |