servitude 0.8.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -4
- data/examples/1_simple_server +0 -3
- data/examples/2_echo_server +0 -3
- data/examples/3_echo_server_with_cli_and_daemon +0 -3
- data/examples/4_echo_server_with_cli_daemon_and_file_config +0 -3
- data/examples/5_echo_server_with_cli_daemon_and_env_config +0 -3
- data/lib/servitude/base.rb +0 -9
- data/lib/servitude/cli/service.rb +4 -4
- data/lib/servitude/configuration.rb +43 -18
- data/lib/servitude/server.rb +1 -1
- data/lib/servitude/server_logging.rb +0 -1
- data/lib/servitude/server_threaded.rb +29 -13
- data/lib/servitude/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bc5c02aa6f0759b2c023219955399164bc1fb7f
|
4
|
+
data.tar.gz: ed9b38cdedb0f0a593619abd71ae5e23ceb0a351
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9aed8c3cfb27f402763f0cbb60291d4c8d3f46c4b8afe4ad76860812210071f60e8a74a25101925c5d8f2e8922e159b666703c2b695bc4237924f20d3caf7916
|
7
|
+
data.tar.gz: 0722743586090901fbe060ee76f26efe40540e89fd7795b10ea2459eb319eac8bbcc872a5deebbd611a6905ac5914501039e4ffd7784078d15cfe56ad69f90b8
|
data/README.md
CHANGED
@@ -70,10 +70,7 @@ If you do not call ::boot, an error is raised before your server can be started.
|
|
70
70
|
app_name: 'Aswesome Server',
|
71
71
|
attribution: "v#{VERSION} \u00A9#{Time.now.year} Awesome, Inc."
|
72
72
|
author: 'Awesome, Inc.',
|
73
|
-
default_config_path: "/etc/awesome/awesome-server.conf"
|
74
|
-
default_log_path: "/var/log/awesome/awesome-server.log",
|
75
|
-
default_pid_path: "/var/run/awesome/awesome-server.pid",
|
76
|
-
default_thread_count: 1
|
73
|
+
default_config_path: "/etc/awesome/awesome-server.conf"
|
77
74
|
end
|
78
75
|
|
79
76
|
### Servitude::Cli
|
data/examples/1_simple_server
CHANGED
data/examples/2_echo_server
CHANGED
@@ -46,9 +46,6 @@ module EchoServer
|
|
46
46
|
author: 'LFE',
|
47
47
|
use_config: false,
|
48
48
|
default_config_path: "#{PROJECT_ROOT}}/config/#{APP_FOLDER}.conf",
|
49
|
-
default_log_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.log",
|
50
|
-
default_pid_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.pid",
|
51
|
-
default_thread_count: nil
|
52
49
|
|
53
50
|
class Cli < Servitude::Cli::Service
|
54
51
|
end
|
@@ -46,9 +46,6 @@ module EchoServer
|
|
46
46
|
author: 'LFE',
|
47
47
|
use_config: true,
|
48
48
|
default_config_path: "#{PROJECT_ROOT}/config/4.conf",
|
49
|
-
default_log_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.log",
|
50
|
-
default_pid_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.pid",
|
51
|
-
default_thread_count: nil
|
52
49
|
|
53
50
|
class Cli < Servitude::Cli::Service
|
54
51
|
end
|
@@ -54,9 +54,6 @@ module EchoServer
|
|
54
54
|
author: 'LFE',
|
55
55
|
use_config: true,
|
56
56
|
default_config_path: "#{PROJECT_ROOT}/config/5.conf",
|
57
|
-
default_log_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.log",
|
58
|
-
default_pid_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.pid",
|
59
|
-
default_thread_count: nil
|
60
57
|
|
61
58
|
class Cli < Servitude::Cli::Service
|
62
59
|
end
|
data/lib/servitude/base.rb
CHANGED
@@ -24,9 +24,6 @@ module Servitude
|
|
24
24
|
attribution: ( "v#{host_namespace::VERSION} Copyright © #{Time.now.year} #{author || company}" rescue nil ),
|
25
25
|
use_config: false,
|
26
26
|
default_config_path: nil,
|
27
|
-
default_log_path: nil,
|
28
|
-
default_pid_path: nil,
|
29
|
-
default_thread_count: nil,
|
30
27
|
server_class: ( host_namespace::Server rescue "#{host_namespace.name}::Server" ),
|
31
28
|
version_copyright: nil ) # TODO: Remove when version_copyright keyword deprecation expires
|
32
29
|
unless host_namespace
|
@@ -70,9 +67,6 @@ module Servitude
|
|
70
67
|
const_set :COMPANY, author # TODO: Remove when company keyword deprecation expires
|
71
68
|
const_set :ATTRIBUTION, attribution
|
72
69
|
const_set :DEFAULT_CONFIG_PATH, default_config_path
|
73
|
-
const_set :DEFAULT_LOG_PATH, default_log_path
|
74
|
-
const_set :DEFAULT_PID_PATH, default_pid_path
|
75
|
-
const_set :DEFAULT_THREAD_COUNT, default_thread_count
|
76
70
|
const_set :USE_CONFIG, use_config
|
77
71
|
const_set :VERSION_COPYRIGHT, attribution # TODO: Remove when version_copyright keyword deprecation expires
|
78
72
|
|
@@ -82,9 +76,6 @@ module Servitude
|
|
82
76
|
Servitude.const_set :COMPANY, author # TODO: Remove when company keyword deprecation expires
|
83
77
|
Servitude.const_set :ATTRIBUTION, attribution
|
84
78
|
Servitude.const_set :DEFAULT_CONFIG_PATH, default_config_path
|
85
|
-
Servitude.const_set :DEFAULT_LOG_PATH, default_log_path
|
86
|
-
Servitude.const_set :DEFAULT_PID_PATH, default_pid_path
|
87
|
-
Servitude.const_set :DEFAULT_THREAD_COUNT, default_thread_count
|
88
79
|
Servitude.const_set :SERVER_CLASS, server_class
|
89
80
|
Servitude.const_set :USE_CONFIG, use_config
|
90
81
|
Servitude.const_set :VERSION_COPYRIGHT, attribution # TODO: Remove when version_copyright keyword deprecation expires
|
@@ -7,15 +7,15 @@ module Servitude
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def self.pid_option
|
10
|
-
method_option :pid, desc: "The path for the PID file", type: :string
|
10
|
+
method_option :pid, desc: "The path for the PID file", type: :string
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.common_start_options
|
14
14
|
method_option :config, type: :string, aliases: '-c', desc: "The path for the config file", default: Servitude::DEFAULT_CONFIG_PATH
|
15
15
|
environment_option
|
16
|
-
method_option :log_level, desc: "The log level", type: :string, aliases: '-o'
|
17
|
-
method_option :log, desc: "The path for the log file", type: :string, aliases: '-l'
|
18
|
-
method_option :threads, desc: "The number of threads", type: :numeric, aliases: '-t'
|
16
|
+
method_option :log_level, desc: "The log level", type: :string, aliases: '-o'
|
17
|
+
method_option :log, desc: "The path for the log file", type: :string, aliases: '-l'
|
18
|
+
method_option :threads, desc: "The number of threads", type: :numeric, aliases: '-t'
|
19
19
|
end
|
20
20
|
|
21
21
|
desc "restart", "Stop and start the server"
|
@@ -1,33 +1,58 @@
|
|
1
|
-
require 'delegate'
|
2
1
|
require 'hashie'
|
3
|
-
require 'oj'
|
2
|
+
#require 'oj'
|
3
|
+
require 'pathname'
|
4
|
+
require 'yaml'
|
4
5
|
|
5
6
|
module Servitude
|
6
|
-
class Configuration <
|
7
|
+
class Configuration < Hashie::Mash
|
7
8
|
|
8
|
-
def
|
9
|
-
|
9
|
+
def self.load( options={} )
|
10
|
+
merged_options = defaults.merge( file_options )
|
11
|
+
merged_options = merged_options.merge( options )
|
12
|
+
new( merged_options )
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.config_filepath
|
16
|
+
Servitude::DEFAULT_CONFIG_PATH
|
17
|
+
end
|
10
18
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
19
|
+
def config_filepath
|
20
|
+
Pathname.new( self.class.config_filepath )
|
21
|
+
end
|
22
|
+
|
23
|
+
def slice( *keys )
|
24
|
+
klass.new( select { |k,v| keys.map( &:to_s ).include?( k ) } )
|
25
|
+
end
|
17
26
|
|
18
|
-
|
27
|
+
def for_env
|
28
|
+
return Hashie::Mash.new({}) unless env
|
29
|
+
self[env]
|
19
30
|
end
|
20
31
|
|
21
32
|
protected
|
22
33
|
|
23
|
-
|
34
|
+
# Override to povide default config values
|
35
|
+
#
|
36
|
+
def self.defaults
|
37
|
+
{
|
38
|
+
threads: 1
|
39
|
+
}
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.file_options
|
43
|
+
return {} unless config_filepath
|
24
44
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
45
|
+
File.exists?( config_filepath ) ?
|
46
|
+
load_file_options :
|
47
|
+
{}
|
48
|
+
end
|
49
|
+
|
50
|
+
def self.load_file_options
|
51
|
+
YAML::load( File.read( config_filepath ))
|
52
|
+
end
|
29
53
|
|
30
|
-
|
54
|
+
def klass
|
55
|
+
self.class
|
31
56
|
end
|
32
57
|
|
33
58
|
end
|
data/lib/servitude/server.rb
CHANGED
@@ -9,27 +9,51 @@ module Servitude
|
|
9
9
|
|
10
10
|
protected
|
11
11
|
|
12
|
+
def handler_class
|
13
|
+
raise NotImplementedError
|
14
|
+
end
|
15
|
+
|
16
|
+
def run
|
17
|
+
raise NotImplementedError
|
18
|
+
end
|
19
|
+
|
12
20
|
def with_supervision( &block )
|
13
21
|
begin
|
14
22
|
block.call
|
15
23
|
rescue Servitude::SupervisionError
|
16
24
|
# supervisor is restarting actor
|
17
|
-
|
25
|
+
warn_for_supevision_error
|
26
|
+
sleep( config.supervision_retry_timeout || 0 )
|
18
27
|
retry
|
19
28
|
rescue Celluloid::DeadActorError
|
20
29
|
# supervisor has yet to begin restarting actor
|
21
|
-
|
30
|
+
warn_for_dead_actor_error
|
31
|
+
sleep( config.supervision_retry_timeout || 0 )
|
22
32
|
retry
|
33
|
+
rescue => e
|
34
|
+
handle_error( payload, delivery_info, e )
|
23
35
|
end
|
24
36
|
end
|
25
37
|
|
38
|
+
def warn_for_supevision_error
|
39
|
+
warn "RETRYING due to waiting on supervisor to restart actor ..."
|
40
|
+
end
|
41
|
+
|
42
|
+
def warn_for_dead_actor_error
|
43
|
+
warn "RETRYING due to Celluloid::DeadActorError ..."
|
44
|
+
end
|
45
|
+
|
46
|
+
def handle_error( payload, delivery_info, e )
|
47
|
+
error( "#{e.class.name} | #{e.message} | #{e.backtrace.inspect}" )
|
48
|
+
end
|
49
|
+
|
26
50
|
# Correctly calls a single supervised actor when the threads configuraiton is set
|
27
51
|
# to 1, or a pool of actors if threads configuration is > 1. Also protects against
|
28
52
|
# a supervised actor from being nil if the supervisor is reinitializing when access
|
29
53
|
# is attempted.
|
30
54
|
#
|
31
55
|
def call_handler_respecting_thread_count( options )
|
32
|
-
if
|
56
|
+
if config.threads > 1
|
33
57
|
pool.async.call( options )
|
34
58
|
else
|
35
59
|
raise Servitude::SupervisionError unless handler
|
@@ -37,16 +61,8 @@ module Servitude
|
|
37
61
|
end
|
38
62
|
end
|
39
63
|
|
40
|
-
def handler_class
|
41
|
-
raise NotImplementedError
|
42
|
-
end
|
43
|
-
|
44
|
-
def run
|
45
|
-
raise NotImplementedError
|
46
|
-
end
|
47
|
-
|
48
64
|
def pool
|
49
|
-
@pool ||= handler_class.pool( size:
|
65
|
+
@pool ||= handler_class.pool( size: config.threads )
|
50
66
|
end
|
51
67
|
|
52
68
|
def handler
|
@@ -54,7 +70,7 @@ module Servitude
|
|
54
70
|
end
|
55
71
|
|
56
72
|
def initialize_thread
|
57
|
-
return unless
|
73
|
+
return unless config.threads == 1
|
58
74
|
handler_class.supervise_as :handler
|
59
75
|
end
|
60
76
|
|
data/lib/servitude/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: servitude
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Harrelson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-12-
|
11
|
+
date: 2014-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|