Class: D13n::Service
- Inherits:
-
Object
show all
- Includes:
- Start
- Defined in:
- lib/d13n/service.rb,
lib/d13n/service/start.rb
Defined Under Namespace
Modules: Start
Classes: ServiceError, ServiceStartError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Start
#config_server_raise_on_failure?, #log_environment, #log_service_name, #log_startup, #log_version_and_pid, #query_server_for_configuration, #start_api_service, #start_metric_manager
Constructor Details
Returns a new instance of Service.
31
32
33
34
|
# File 'lib/d13n/service.rb', line 31
def initialize()
@started=false
@service_prefix = D13n.service.app_class.name.underscore.upcase
end
|
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
30
31
32
|
# File 'lib/d13n/service.rb', line 30
def env
@env
end
|
#service_conf ⇒ Object
Returns the value of attribute service_conf.
30
31
32
|
# File 'lib/d13n/service.rb', line 30
def service_conf
@service_conf
end
|
#service_prefix ⇒ Object
Returns the value of attribute service_prefix.
30
31
32
|
# File 'lib/d13n/service.rb', line 30
def service_prefix
@service_prefix
end
|
#started ⇒ Object
Returns the value of attribute started.
30
31
32
|
# File 'lib/d13n/service.rb', line 30
def started
@started
end
|
Class Method Details
.app_class ⇒ Object
19
20
21
|
# File 'lib/d13n/service.rb', line 19
def app_class
@app_kls ||= Object.const_get(name.split("::").first)
end
|
.inherited(descendant) ⇒ Object
23
24
25
26
27
|
# File 'lib/d13n/service.rb', line 23
def inherited(descendant)
raise ServiceError, "You cannot have more than one D13n::Service" if D13n.service && descendant == D13n::Service
descendant.app_class.extend Application::ClassMethods
D13n.service = descendant
end
|
.instance ⇒ Object
10
11
12
|
# File 'lib/d13n/service.rb', line 10
def instance
@instance ||= new
end
|
.run!(opts) ⇒ Object
14
15
16
17
|
# File 'lib/d13n/service.rb', line 14
def run!(opts)
D13n.service.instance.init(opts)
D13n.service.instance.start
end
|
Instance Method Details
#config_service(opts) ⇒ Object
68
69
70
71
|
# File 'lib/d13n/service.rb', line 68
def config_service(opts)
config_file_path = D13n.config[:config_path]
D13n.config.replace_or_add_config(D13n::Configuration::YamlSource.new(config_file_path, env))
end
|
#determine_env(opts = {}) ⇒ Object
64
65
66
|
# File 'lib/d13n/service.rb', line 64
def determine_env(opts={})
@env = opts.fetch(:env, default_env).to_s
end
|
#determine_logger(opts) ⇒ Object
43
44
45
46
47
|
# File 'lib/d13n/service.rb', line 43
def determine_logger(opts)
if D13n.logger.is_startup_logger?
D13n.logger = D13n::Logger.new(root,opts.delete(:logger))
end
end
|
#determine_service_conf(opts = {}) ⇒ Object
58
59
60
61
62
|
# File 'lib/d13n/service.rb', line 58
def determine_service_conf(opts={})
@service_conf ||= {}
@service_conf[:port] = opts.fetch(:port, 3000)
@service_conf[:bind] = opts.fetch(:host, 'localhost')
end
|
#init(opts) ⇒ Object
36
37
38
39
40
41
|
# File 'lib/d13n/service.rb', line 36
def init(opts)
determine_service_conf(opts)
determine_env(opts)
config_service(opts)
determine_logger(opts)
end
|
#root ⇒ Object
77
78
79
|
# File 'lib/d13n/service.rb', line 77
def root
@root = ENV['SERVICE_ROOT'] || '.'
end
|
#settings ⇒ Object
81
82
83
|
# File 'lib/d13n/service.rb', line 81
def settings
D13n.config.to_collecter_hash
end
|
#start ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/d13n/service.rb', line 49
def start
return if started?
log_startup
query_server_for_configuration
start_metric_manager
log_version_and_pid
start_api_service
end
|
#started? ⇒ Boolean
73
74
75
|
# File 'lib/d13n/service.rb', line 73
def started?
@started
end
|