class Falcon::Services
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 {Service::Application}. -
Host supervisor implemented in {Service::Supervisor}.
-
Proxy services wrapped by {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.
Public Class Methods
Initialize the services from the given configuration.
@parameter configuration [Configuration]
# 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
Public Instance Methods
Add a named service.
@parameter service [Service]
# File lib/falcon/services.rb, line 57 def add(service) @named[service.name] = service end
Enumerate all named services.
# File lib/falcon/services.rb, line 50 def each(&block) @named.each_value(&block) end
Setup all named services into the given container.
@parameter container [Async::Container::Generic]
# File lib/falcon/services.rb, line 72 def setup(container) @named.each do |name, service| Console.logger.debug(self) {"Setup #{name} into #{container}..."} service.setup(container) end return container end
Start all named services.
# File lib/falcon/services.rb, line 62 def start @named.each do |name, service| Console.logger.debug(self) {"Starting #{name}..."} service.start end end
Stop all named services.
# File lib/falcon/services.rb, line 82 def stop failed = false @named.each do |name, service| Console.logger.debug(self) {"Stopping #{name}..."} begin service.stop rescue failed = true Console.logger.error(self, $!) end end return failed end