servitude 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 11b7ea1e73f25eb1270966889eb4341dd269657a
4
- data.tar.gz: ab47729667a4604e5fb23bd1976b160d96d7b6e8
3
+ metadata.gz: 9d92cd3bbaeb18254224bf3d04c90ef1076d16d6
4
+ data.tar.gz: d821dac504ebe7db88da0d37566908f5625b3e48
5
5
  SHA512:
6
- metadata.gz: c13a26dda70ac70166e95038910e07692809df93cd82ec8b348b863a5fff729acdc5c8df004ed922f7c7f234b93779b7b58aff0de6e750125e480519bd0b0589
7
- data.tar.gz: f7cb8d3b33788691a07f726db705d15a18adb5699ce545e9803e72af6210131be950f579f4a586dd2faf1bbef7f776684e92368373354dbd8d098ea0132281cc
6
+ metadata.gz: 225a9fe42a13c8114c2574596a7a9540ccbc2e3a191e7b2a2fb53335ecf53f03ca8a62db6a4afddc1fc70ddf5470173f2c024d9bfa8bde11acc0de098b003a82
7
+ data.tar.gz: 734f32e55b8eb623eca14dad76e552b6ae6ef9c1e757c9bfcdedbbec2ea5677e7d5aa3d631e5b1f1eba12600aa998faf6d52fac538b830008a1be22b636d10ec
data/README.md CHANGED
@@ -20,8 +20,6 @@ Or install it yourself as:
20
20
 
21
21
  ## Usage
22
22
 
23
- For executable examples see the [examples folder](https://github.com/midas/servitude/tree/master/examples).
24
-
25
23
  To build a server with Servitude only a couple of steps are required.
26
24
 
27
25
  * Include the Servitude::Base module in the base module of your server project.
@@ -30,7 +28,8 @@ To build a server with Servitude only a couple of steps are required.
30
28
  * If a single threaded server, implement your functionality in the Server#run method.
31
29
  * If a multi-threaded server, implement your functionality in a handler class that includes the Servitude::Actor module and call the handler from the Server#run method.
32
30
 
33
- For more details see the examples folder.
31
+ For executable examples see the [examples folder](https://github.com/midas/servitude/tree/master/examples). To run the examples, clone the project,
32
+ install the bundle and follow the usage instructions in each example.
34
33
 
35
34
  The rest of this document will discuss the functionality each module provides.
36
35
 
@@ -79,11 +78,11 @@ If you do not call ::boot, an error is raised before your server can be started.
79
78
 
80
79
  ### Servitude::Cli
81
80
 
82
- The Cli module provides the functionality of a Command Line Interface for your server.
81
+ The Cli module provides several classes with Command Line Interface functionality for your server. The Cli::Service class provides standard unix service
82
+ sub-commands: start, stop, status and restart.
83
83
 
84
84
  module AwesomeServer
85
- class Cli
86
- include Servitude::Cli
85
+ class Cli < Servitude::Cli::Service
87
86
  end
88
87
  end
89
88
 
@@ -91,7 +90,17 @@ In your CLI file (bin/awesome-server):
91
90
 
92
91
  #!/usr/bin/env ruby
93
92
  require 'awesome_server'
94
- AwesomeServer::Cli.new( ARGV ).run
93
+ AwesomeServer::Cli.start
94
+
95
+ To build a custom CLI, you can inherit from Cli::Base.
96
+
97
+ module AwesomeServer
98
+ class Cli < Servitude::Cli::Base
99
+ end
100
+ end
101
+
102
+ For details on how to add commands to your custom or standard service CLIs see the [Thor documentation](http://whatisthor.com/).
103
+
95
104
 
96
105
  ### Servitude::Configuration
97
106
 
@@ -258,7 +267,7 @@ The Server module provides callbacks to utilize in your server implementation:
258
267
 
259
268
  * __before_initialize__: executes just before the initilaization of the server
260
269
  * __after_initialize__: executes immediately after initilaization of the server
261
- * __before_run: executes just before the run method is called
270
+ * __before_run__: executes just before the run method is called
262
271
  * __before_sleep__: executes just before the main thread sleeps to avoid exiting
263
272
  * __finalize__: executes before server exits
264
273
 
@@ -3,8 +3,6 @@
3
3
  require 'rubygems'
4
4
  require 'servitude'
5
5
  require 'socket'
6
- require 'trollop'
7
- require 'pry'
8
6
 
9
7
  # The echo server accepts with CLI builds on the 2_echo_server example, addiing a command line interface.
10
8
  #
@@ -21,7 +19,7 @@ require 'pry'
21
19
  #
22
20
  # Usage:
23
21
  # Help:
24
- # bundle exec examples/3_echo_server_with_cli_and_daemon -h
22
+ # bundle exec examples/3_echo_server_with_cli_and_daemon help
25
23
  #
26
24
  # Start (interactive):
27
25
  # bundle exec examples/3_echo_server_with_cli_and_daemon start -i
@@ -52,10 +50,7 @@ module EchoServer
52
50
  default_thread_count: nil,
53
51
  version_copyright: "v#{VERSION} \u00A9#{Time.now.year} LFE"
54
52
 
55
- class Cli
56
-
57
- include Servitude::Cli
58
-
53
+ class Cli < Servitude::Cli::Service
59
54
  end
60
55
 
61
56
  class Server
@@ -95,4 +90,4 @@ module EchoServer
95
90
  end
96
91
  end
97
92
 
98
- EchoServer::Cli.new( ARGV ).run
93
+ EchoServer::Cli.start
@@ -3,8 +3,6 @@
3
3
  require 'rubygems'
4
4
  require 'servitude'
5
5
  require 'socket'
6
- require 'trollop'
7
- require 'pry'
8
6
 
9
7
  # The echo server accepts with CLI builds on the 2_echo_server example, addiing a command line interface.
10
8
  #
@@ -21,7 +19,7 @@ require 'pry'
21
19
  #
22
20
  # Usage:
23
21
  # Help:
24
- # bundle exec examples/4_echo_server_with_cli_daemon_and_config -h
22
+ # bundle exec examples/4_echo_server_with_cli_daemon_and_config help
25
23
  #
26
24
  # Start (interactive):
27
25
  # bundle exec examples/4_echo_server_with_cli_daemon_and_config start -i
@@ -52,10 +50,7 @@ module EchoServer
52
50
  default_thread_count: nil,
53
51
  version_copyright: "v#{VERSION} \u00A9#{Time.now.year} LFE"
54
52
 
55
- class Cli
56
-
57
- include Servitude::Cli
58
-
53
+ class Cli < Servitude::Cli::Service
59
54
  end
60
55
 
61
56
  class Server
@@ -95,4 +90,4 @@ module EchoServer
95
90
  end
96
91
  end
97
92
 
98
- EchoServer::Cli.new( ARGV ).run
93
+ EchoServer::Cli.start
@@ -3,8 +3,6 @@
3
3
  require 'rubygems'
4
4
  require 'servitude'
5
5
  require 'socket'
6
- require 'trollop'
7
- require 'pry'
8
6
 
9
7
  # The echo server accepts with CLI builds on the 2_echo_server example, addiing a command line interface.
10
8
  #
@@ -21,7 +19,7 @@ require 'pry'
21
19
  #
22
20
  # Usage:
23
21
  # Help:
24
- # bundle exec examples/5_echo_server_with_cli_daemon_and_env_config -h
22
+ # bundle exec examples/5_echo_server_with_cli_daemon_and_env_config help
25
23
  #
26
24
  # Start (interactive):
27
25
  # bundle exec examples/5_echo_server_with_cli_daemon_and_env_config start -i
@@ -60,10 +58,7 @@ module EchoServer
60
58
  default_thread_count: nil,
61
59
  version_copyright: "v#{VERSION} \u00A9#{Time.now.year} LFE"
62
60
 
63
- class Cli
64
-
65
- include Servitude::Cli
66
-
61
+ class Cli < Servitude::Cli::Service
67
62
  end
68
63
 
69
64
  class Server
@@ -111,4 +106,4 @@ module EchoServer
111
106
  end
112
107
  end
113
108
 
114
- EchoServer::Cli.new( ARGV ).run
109
+ EchoServer::Cli.start
@@ -0,0 +1,6 @@
1
+ module Servitude
2
+ module Cli
3
+ class Base < Thor
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,74 @@
1
+ module Servitude
2
+ module Cli
3
+ class Service < Base
4
+
5
+ def self.environment_option
6
+ method_option :environment, desc: "The environment to execute in", type: :string, aliases: '-e'
7
+ end
8
+
9
+ def self.pid_option
10
+ method_option :pid, desc: "The path for the PID file", type: :string, default: Servitude::NS::DEFAULT_PID_PATH
11
+ end
12
+
13
+ def self.common_start_options
14
+ method_option :config, type: :string, aliases: '-c', desc: "The path for the config file", default: Servitude::NS::DEFAULT_CONFIG_PATH
15
+ environment_option
16
+ method_option :log_level, desc: "The log level", type: :string, aliases: '-o', default: 'info'
17
+ method_option :log, desc: "The path for the log file", type: :string, aliases: '-l', default: Servitude::NS::DEFAULT_LOG_PATH
18
+ method_option :threads, desc: "The number of threads", type: :numeric, aliases: '-t', default: Servitude::NS::DEFAULT_THREAD_COUNT
19
+ end
20
+
21
+ desc "restart", "Stop and start the server"
22
+ common_start_options
23
+ pid_option
24
+ def restart
25
+ stop
26
+ start_daemon
27
+ end
28
+
29
+ desc "start", "Start the server"
30
+ common_start_options
31
+ pid_option
32
+ method_option :interactive, type: :boolean, aliases: '-i', desc: "Start the server in interactive mode", default: false
33
+ def start
34
+ if options[:interactive]
35
+ start_interactive
36
+ else
37
+ start_daemon
38
+ end
39
+ end
40
+
41
+ no_commands do
42
+
43
+ def start_interactive
44
+ server = Servitude::NS::Server.new( options.merge( use_config: Servitude::NS::USE_CONFIG, log: 'STDOUT' ))
45
+ server.start
46
+ end
47
+
48
+ def start_daemon
49
+ server = Servitude::Daemon.new( options.merge( use_config: Servitude::NS::USE_CONFIG ))
50
+ server.start
51
+ end
52
+
53
+ end
54
+
55
+ desc "status", "Check the status of the server daemon"
56
+ pid_option
57
+ def status
58
+ Servitude::Daemon.new( options.merge( use_config: Servitude::NS::USE_CONFIG )).status
59
+ end
60
+
61
+ desc "stop", "Stop the server daemon"
62
+ pid_option
63
+ def stop
64
+ server = Servitude::Daemon.new( options.merge( use_config: Servitude::NS::USE_CONFIG ))
65
+ server.stop
66
+ end
67
+
68
+ def self.handle_no_command_error( name )
69
+ puts "Unrecognized command: #{name}"
70
+ end
71
+
72
+ end
73
+ end
74
+ end
data/lib/servitude/cli.rb CHANGED
@@ -1,135 +1,14 @@
1
1
  require 'rubygems'
2
2
  require 'servitude'
3
- require 'trollop'
3
+ require 'thor'
4
4
  require 'yell'
5
5
 
6
+
6
7
  module Servitude
7
8
  module Cli
8
9
 
9
- def self.included( base )
10
- base.class_eval do
11
- attr_reader :cmd,
12
- :options
13
- end
14
- end
15
-
16
- SUB_COMMANDS = %w(
17
- restart
18
- start
19
- status
20
- stop
21
- )
22
-
23
- def initialize( args )
24
- unless Servitude.boot_called
25
- raise 'You must call boot before starting server'
26
- end
27
-
28
- Trollop::options do
29
- version Servitude::NS::VERSION_COPYRIGHT
30
- banner <<-EOS
31
- #{Servitude::NS::APP_NAME} #{Servitude::NS::VERSION_COPYRIGHT}
32
-
33
- Usage:
34
- #{Servitude::NS::APP_ID} [command] [options]
35
-
36
- commands:
37
- #{SUB_COMMANDS.map { |sub_cmd| " #{sub_cmd}" }.join( "\n" )}
38
-
39
- (For help with a command: #{Servitude::NS::APP_ID} [command] -h)
40
-
41
- options:
42
- EOS
43
- stop_on SUB_COMMANDS
44
- end
45
-
46
- # Get the sub-command and its options
47
- #
48
- @cmd = ARGV.shift || ''
49
- @options = case( cmd )
50
- when ''
51
- Trollop::die 'No command provided'
52
- when "restart"
53
- Trollop::options do
54
- opt :config, "The path for the config file", :type => String, :short => '-c', :default => Servitude::NS::DEFAULT_CONFIG_PATH
55
- opt :environment, "The log level", :type => String, :short => '-e'
56
- opt :log_level, "The log level", :type => String, :default => 'info', :short => '-o'
57
- opt :log, "The path for the log file", :type => String, :short => '-l', :default => Servitude::NS::DEFAULT_LOG_PATH
58
- opt :pid, "The path for the PID file", :type => String, :default => Servitude::NS::DEFAULT_PID_PATH
59
- opt :threads, "The number of threads", :type => Integer, :default => Servitude::NS::DEFAULT_THREAD_COUNT, :short => '-t'
60
- end
61
- when "start"
62
- Trollop::options do
63
- opt :config, "The path for the config file", :type => String, :short => '-c', :default => Servitude::NS::DEFAULT_CONFIG_PATH
64
- opt :environment, "The log level", :type => String, :short => '-e'
65
- opt :interactive, "Execute the server in interactive mode", :short => '-i'
66
- opt :log_level, "The log level", :type => String, :default => 'info', :short => '-o'
67
- opt :log, "The path for the log file", :type => String, :short => '-l', :default => Servitude::NS::DEFAULT_LOG_PATH
68
- opt :pid, "The path for the PID file", :type => String, :default => Servitude::NS::DEFAULT_PID_PATH
69
- opt :threads, "The number of threads", :type => Integer, :default => Servitude::NS::DEFAULT_THREAD_COUNT, :short => '-t'
70
- end
71
- when "status"
72
- Trollop::options do
73
- opt :pid, "The path for the PID file", :type => String, :default => Servitude::NS::DEFAULT_PID_PATH
74
- end
75
- when "stop"
76
- Trollop::options do
77
- opt :pid, "The path for the PID file", :type => String, :default => Servitude::NS::DEFAULT_PID_PATH
78
- end
79
- else
80
- Trollop::die "unknown command #{cmd.inspect}"
81
- end
82
-
83
- if cmd == 'start'
84
- unless options[:interactive]
85
- Trollop::die( :config, "is required when running as daemon" ) unless options[:config]
86
- Trollop::die( :log, "is required when running as daemon" ) unless options[:log]
87
- Trollop::die( :pid, "is required when running as daemon" ) unless options[:pid]
88
- end
89
- end
90
-
91
- if %w(restart status stop).include?( cmd )
92
- Trollop::die( :pid, "is required" ) unless options[:pid]
93
- end
94
- end
95
-
96
- def run
97
- send( cmd )
98
- end
99
-
100
- protected
101
-
102
- def start
103
- if options[:interactive]
104
- start_interactive
105
- else
106
- start_daemon
107
- end
108
- end
109
-
110
- def start_interactive
111
- server = Servitude::NS::Server.new( options.merge( use_config: Servitude::NS::USE_CONFIG, log: 'STDOUT' ))
112
- server.start
113
- end
114
-
115
- def start_daemon
116
- server = Servitude::Daemon.new( options.merge( use_config: Servitude::NS::USE_CONFIG ))
117
- server.start
118
- end
119
-
120
- def stop
121
- server = Servitude::Daemon.new( options.merge( use_config: Servitude::NS::USE_CONFIG ))
122
- server.stop
123
- end
124
-
125
- def restart
126
- stop
127
- start_daemon
128
- end
129
-
130
- def status
131
- Servitude::Daemon.new( options.merge( use_config: Servitude::NS::USE_CONFIG )).status
132
- end
10
+ autoload :Base, 'servitude/cli/base'
11
+ autoload :Service, 'servitude/cli/service'
133
12
 
134
13
  end
135
14
  end
@@ -1,5 +1,3 @@
1
- require 'celluloid/autostart'
2
-
3
1
  module Servitude
4
2
  module ConfigHelper
5
3
 
@@ -1,3 +1,3 @@
1
1
  module Servitude
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
data/servitude.gemspec CHANGED
@@ -28,6 +28,6 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "hooks", "~> 0"
29
29
  spec.add_dependency "oj", "~> 2"
30
30
  spec.add_dependency "rainbow", "~> 2"
31
- spec.add_dependency "trollop", "~> 2"
31
+ spec.add_dependency "thor"
32
32
  spec.add_dependency "yell", "~> 1"
33
33
  end
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.2.0
4
+ version: 0.3.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-09-12 00:00:00.000000000 Z
11
+ date: 2014-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -137,19 +137,19 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '2'
139
139
  - !ruby/object:Gem::Dependency
140
- name: trollop
140
+ name: thor
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - "~>"
143
+ - - ">="
144
144
  - !ruby/object:Gem::Version
145
- version: '2'
145
+ version: '0'
146
146
  type: :runtime
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - "~>"
150
+ - - ">="
151
151
  - !ruby/object:Gem::Version
152
- version: '2'
152
+ version: '0'
153
153
  - !ruby/object:Gem::Dependency
154
154
  name: yell
155
155
  requirement: !ruby/object:Gem::Requirement
@@ -191,6 +191,8 @@ files:
191
191
  - lib/servitude/actor.rb
192
192
  - lib/servitude/base.rb
193
193
  - lib/servitude/cli.rb
194
+ - lib/servitude/cli/base.rb
195
+ - lib/servitude/cli/service.rb
194
196
  - lib/servitude/config_helper.rb
195
197
  - lib/servitude/configuration.rb
196
198
  - lib/servitude/daemon.rb