mongrel2 0.53.0 → 0.54.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,26 @@
1
+ # -*- ruby -*-
2
+ # frozen_string_literal: true
3
+
4
+ require 'mongrel2/config'
5
+
6
+ require 'mongrel2/cli' unless defined?( Mongrel2::CLI )
7
+
8
+
9
+ # Mongrel2 settings command
10
+ module Mongrel2::CLI::SettingsCommand
11
+ extend Mongrel2::CLI::Subcommand
12
+
13
+
14
+ desc "Show the 'advanced' server settings."
15
+ command :settings do |settingscmd|
16
+
17
+ settingscmd.action do |globals, options, args|
18
+ prompt.say( hl.headline "Advanced Server Settings" )
19
+ Mongrel2::Config.settings.each do |key,val|
20
+ prompt.say( "%s %s" % [ hl.key("#{key}:"), val] )
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end # module Mongrel2::CLI::SettingsCommand
@@ -0,0 +1,72 @@
1
+ # -*- ruby -*-
2
+ # frozen_string_literal: true
3
+
4
+ require 'shellwords'
5
+ require 'mongrel2/config'
6
+
7
+ require 'mongrel2/cli' unless defined?( Mongrel2::CLI )
8
+
9
+
10
+ # Mongrel2 start command
11
+ module Mongrel2::CLI::StartCommand
12
+ extend Mongrel2::CLI::Subcommand
13
+
14
+
15
+ desc "Starts a server."
16
+ long_desc <<~END_USAGE
17
+ [SERVER]
18
+ If not specified, SERVER is assumed to be the only server entry in the
19
+ current config. If there are more than one, you must specify a SERVER.
20
+
21
+ The SERVER can be a uuid, hostname, or server name, and are searched for
22
+ in that order.
23
+ END_USAGE
24
+ arg :SERVER, :optional
25
+ command :start do |startcmd|
26
+
27
+ startcmd.switch [:sudo, :s], desc: "Start the server with `sudo`"
28
+
29
+ startcmd.arg_name :PORT
30
+ startcmd.flag [:port, :p], desc: "Reset the configured PORT to bind to",
31
+ type: Integer
32
+
33
+ startcmd.action do |globals, options, args|
34
+ server = find_server( args.shift )
35
+ mongrel2 = find_mongrel2()
36
+
37
+ if options.port
38
+ prompt.say "Resetting %s server's port to %d" % [ server.name, options.port ]
39
+ server.port = options.port
40
+ server.save
41
+ end
42
+
43
+ cmd = [ mongrel2.to_s, Mongrel2::Config.dbname.to_s, server.uuid ]
44
+ cmd.unshift( 'sudo' ) if options.sudo
45
+
46
+ url = "http%s://%s:%d" % [
47
+ server.use_ssl? ? 's' : '',
48
+ server.bind_addr,
49
+ server.port,
50
+ ]
51
+
52
+ # Change into the server's chroot directory so paths line up whether or not
53
+ # it's started as root
54
+
55
+ prompt.say( hl.header '*' * 70 )
56
+ prompt.say( hl.headline "Starting mongrel2 at: %s" % [ hl.key(url) ] )
57
+ prompt.say( hl.header '*' * 70 )
58
+
59
+ if server.chroot && server.chroot != '' && server.chroot != '.'
60
+ Dir.chdir( server.chroot )
61
+ prompt.say " changed PWD to: #{Dir.pwd}"
62
+ end
63
+
64
+ Mongrel2::Config.log_action( "Starting server: #{server}", options.why )
65
+ self.log.debug " command is: #{Shellwords.shelljoin(cmd)}"
66
+ exec( *cmd )
67
+ end
68
+
69
+ end
70
+
71
+
72
+ end # module Mongrel2::CLI::StartCommand
@@ -0,0 +1,33 @@
1
+ # -*- ruby -*-
2
+ # frozen_string_literal: true
3
+
4
+ require 'mongrel2/config'
5
+
6
+ require 'mongrel2/cli' unless defined?( Mongrel2::CLI )
7
+
8
+
9
+ # Mongrel2 stop command
10
+ module Mongrel2::CLI::StopCommand
11
+ extend Mongrel2::CLI::Subcommand
12
+
13
+
14
+ desc "Stop the specified server gracefully"
15
+ arg :SERVER
16
+ command :stop do |stopcmd|
17
+
18
+ stopcmd.action do |globals, options, args|
19
+ server = find_server( args.shift )
20
+ control = server.control_socket
21
+
22
+ prompt.say( hl.header "Stopping '%s' gracefully." % [ server.name ] )
23
+ control.stop
24
+ control.close
25
+ prompt.say( "done." )
26
+
27
+ Mongrel2::Config.log_action( "Stopped server #{server}", globals.why )
28
+ end
29
+
30
+ end
31
+
32
+
33
+ end # module Mongrel2::CLI::StopCommand
@@ -65,6 +65,7 @@ module Mongrel2
65
65
  plugin :subclasses
66
66
  plugin :json_serializer
67
67
  plugin :serialization
68
+ plugin :update_or_create
68
69
 
69
70
 
70
71
  # Configuration defaults
@@ -23,6 +23,17 @@ class Mongrel2::Config::Directory < Mongrel2::Config( :directory )
23
23
  end
24
24
 
25
25
 
26
+ ### Return a description of the directory.
27
+ def to_s
28
+ return "Directory %s(%s) {%s} [cache %ds]" % [
29
+ self.base,
30
+ self.index_file,
31
+ self.default_ctype,
32
+ self.cache_ttl
33
+ ]
34
+ end
35
+
36
+
26
37
  #########
27
38
  protected
28
39
  #########
@@ -22,17 +22,11 @@ module Mongrel2::Config::DSL
22
22
  ### Create an instance of the specified +targetclass+ using the specified +opts+
23
23
  ### as initial values. The first pair of +opts+ will be used in the filter to
24
24
  ### find any previous instance and delete it.
25
- def initialize( targetclass, opts={} )
25
+ def initialize( targetclass, opts={}, &block )
26
26
  self.log.debug "Wrapping a %p" % [ targetclass ]
27
27
  @targetclass = targetclass
28
28
 
29
- # Use the first pair as the primary key
30
- unless opts.empty?
31
- first_pair = Hash[ *opts.first ]
32
- @targetclass.filter( first_pair ).destroy
33
- end
34
-
35
- @target = @targetclass.new( opts )
29
+ @target = @targetclass.find_or_new( opts, &block )
36
30
  self.decorate_with_column_declaratives( @target )
37
31
  self.decorate_with_custom_declaratives( @targetclass )
38
32
  end
@@ -98,19 +92,18 @@ module Mongrel2::Config::DSL
98
92
  Mongrel2.log.info "Entering transaction for server %p" % [ uuid ]
99
93
  Mongrel2::Config.db.transaction do
100
94
 
101
- # Set up the options hash with the UUID and reasonable defaults
102
- # for everything else
103
- server_opts = {
104
- uuid: uuid,
105
- access_log: "/logs/access.log",
106
- error_log: "/logs/error.log",
107
- pid_file: "/run/mongrel2.pid",
108
- default_host: "localhost",
109
- port: 8888,
110
- }
111
-
112
95
  Mongrel2.log.debug "Server [%s] (block: %p)" % [ uuid, block ]
113
- adapter = Adapter.new( Mongrel2::Config::Server, server_opts )
96
+ adapter = Adapter.new( Mongrel2::Config::Server, uuid: uuid ) do |server|
97
+ server.access_log ||= "/logs/access.log"
98
+ server.error_log ||= "/logs/error.log"
99
+ server.pid_file ||= "/run/mongrel2.pid"
100
+ server.default_host ||= "localhost"
101
+ server.port ||= 8888
102
+
103
+ server.hosts.each( &:destroy )
104
+ server.filters.each( &:destroy )
105
+ server.xrequests.each( &:destroy )
106
+ end
114
107
  adapter.instance_eval( &block ) if block
115
108
 
116
109
  Mongrel2.log.info " saving server %p..." % [ uuid ]
@@ -59,6 +59,18 @@ class Mongrel2::Config::Handler < Mongrel2::Config( :handler )
59
59
  end
60
60
 
61
61
 
62
+ ### Return a description of the handler.
63
+ def to_s
64
+ return "Handler `%s' %s <-> %s {%s}%s" % [
65
+ self.send_ident,
66
+ self.recv_spec,
67
+ self.send_spec,
68
+ self.protocol,
69
+ self.raw_payload.nonzero? ? ' (raw)' : '',
70
+ ]
71
+ end
72
+
73
+
62
74
  #########
63
75
  protected
64
76
  #########
@@ -51,7 +51,7 @@ class Mongrel2::Config::Host < Mongrel2::Config( :host )
51
51
  self.target.save
52
52
  self.log.debug "Route %s -> %p [%p]" % [ path, target, opts ]
53
53
 
54
- args = { :path => path, :target => target }
54
+ args = { path: path, target: target }
55
55
  args.merge!( opts )
56
56
  route = Mongrel2::Config::Route.new( args )
57
57
 
@@ -12,5 +12,11 @@ class Mongrel2::Config::Proxy < Mongrel2::Config( :proxy )
12
12
  # addr TEXT,
13
13
  # port INTEGER);
14
14
 
15
+
16
+ ### Return a description of the proxy.
17
+ def to_s
18
+ return "Proxy to %s:%d" % [ self.addr, self.port ]
19
+ end
20
+
15
21
  end # class Mongrel2::Config::Proxy
16
22
 
@@ -197,10 +197,11 @@ class Mongrel2::Config::Server < Mongrel2::Config( :server )
197
197
  self.target.save( :validate => false )
198
198
 
199
199
  self.log.debug "Host [%s] (block: %p)" % [ name, block ]
200
- adapter = Mongrel2::Config::DSL::Adapter.new( Mongrel2::Config::Host, name: name )
200
+ adapter = Mongrel2::Config::DSL::Adapter.
201
+ new( Mongrel2::Config::Host, name: name, server_id: self.target.id )
201
202
  adapter.target.matching = name
202
203
  adapter.instance_eval( &block ) if block
203
- self.target.add_host( adapter.target )
204
+ adapter.target.save
204
205
  end
205
206
 
206
207
 
@@ -56,6 +56,8 @@ describe Mongrel2::Config::DSL, :db do
56
56
 
57
57
  end
58
58
 
59
+ result.refresh
60
+
59
61
  expect( result ).to be_a( Mongrel2::Config::Server )
60
62
  expect( result.hosts.size ).to eq( 1 )
61
63
  host = result.hosts.first
@@ -95,6 +97,8 @@ describe Mongrel2::Config::DSL, :db do
95
97
 
96
98
  end
97
99
 
100
+ result.refresh
101
+
98
102
  expect( result ).to be_a( Mongrel2::Config::Server )
99
103
  expect( result.hosts.size ).to eq( 2 )
100
104
  host1, host2 = result.hosts
@@ -232,6 +236,7 @@ describe Mongrel2::Config::DSL, :db do
232
236
  min_size: 1000
233
237
  end
234
238
 
239
+ result.refresh
235
240
  expect( result.filters.size ).to eq( 1 )
236
241
  expect( result.filters.first ).to be_a( Mongrel2::Config::Filter )
237
242
  expect( result.filters.first.settings ).
@@ -261,6 +266,7 @@ describe Mongrel2::Config::DSL, :db do
261
266
  min_size: 1000
262
267
  end
263
268
 
269
+ result.refresh
264
270
  expect( result.xrequests.size ).to eq( 1 )
265
271
  expect( result.xrequests.first ).to be_a( Mongrel2::Config::XRequest )
266
272
  expect( result.xrequests.first.settings ).
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongrel2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.53.0
4
+ version: 0.54.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Granger
@@ -34,7 +34,7 @@ cert_chain:
34
34
  v4qqqa27Bs468d6SoPxjSm8a2mM9HZ4OdWhq4tFsbTeXDVquCfi64OTEaTt2xQdR
35
35
  JnC4lpJfCP6aCXa5h2XAQfPSH636cQap
36
36
  -----END CERTIFICATE-----
37
- date: 2019-06-26 00:00:00.000000000 Z
37
+ date: 2019-09-06 00:00:00.000000000 Z
38
38
  dependencies:
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: cztop
@@ -64,34 +64,62 @@ dependencies:
64
64
  - - "~>"
65
65
  - !ruby/object:Gem::Version
66
66
  version: '0.6'
67
+ - !ruby/object:Gem::Dependency
68
+ name: gli
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '2.19'
74
+ type: :runtime
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '2.19'
67
81
  - !ruby/object:Gem::Dependency
68
82
  name: libxml-ruby
69
83
  requirement: !ruby/object:Gem::Requirement
70
84
  requirements:
71
85
  - - "~>"
72
86
  - !ruby/object:Gem::Version
73
- version: '3.0'
87
+ version: '3.1'
74
88
  type: :runtime
75
89
  prerelease: false
76
90
  version_requirements: !ruby/object:Gem::Requirement
77
91
  requirements:
78
92
  - - "~>"
79
93
  - !ruby/object:Gem::Version
80
- version: '3.0'
94
+ version: '3.1'
81
95
  - !ruby/object:Gem::Dependency
82
96
  name: loggability
83
97
  requirement: !ruby/object:Gem::Requirement
84
98
  requirements:
85
99
  - - "~>"
86
100
  - !ruby/object:Gem::Version
87
- version: '0.12'
101
+ version: '0.14'
88
102
  type: :runtime
89
103
  prerelease: false
90
104
  version_requirements: !ruby/object:Gem::Requirement
91
105
  requirements:
92
106
  - - "~>"
93
107
  - !ruby/object:Gem::Version
94
- version: '0.12'
108
+ version: '0.14'
109
+ - !ruby/object:Gem::Dependency
110
+ name: pastel
111
+ requirement: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - "~>"
114
+ - !ruby/object:Gem::Version
115
+ version: '0.7'
116
+ type: :runtime
117
+ prerelease: false
118
+ version_requirements: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - "~>"
121
+ - !ruby/object:Gem::Version
122
+ version: '0.7'
95
123
  - !ruby/object:Gem::Dependency
96
124
  name: sequel
97
125
  requirement: !ruby/object:Gem::Requirement
@@ -149,33 +177,47 @@ dependencies:
149
177
  - !ruby/object:Gem::Version
150
178
  version: '0.3'
151
179
  - !ruby/object:Gem::Dependency
152
- name: trollop
180
+ name: tty-prompt
153
181
  requirement: !ruby/object:Gem::Requirement
154
182
  requirements:
155
183
  - - "~>"
156
184
  - !ruby/object:Gem::Version
157
- version: '2.0'
185
+ version: '0.19'
158
186
  type: :runtime
159
187
  prerelease: false
160
188
  version_requirements: !ruby/object:Gem::Requirement
161
189
  requirements:
162
190
  - - "~>"
163
191
  - !ruby/object:Gem::Version
164
- version: '2.0'
192
+ version: '0.19'
193
+ - !ruby/object:Gem::Dependency
194
+ name: tty-table
195
+ requirement: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - "~>"
198
+ - !ruby/object:Gem::Version
199
+ version: '0.11'
200
+ type: :runtime
201
+ prerelease: false
202
+ version_requirements: !ruby/object:Gem::Requirement
203
+ requirements:
204
+ - - "~>"
205
+ - !ruby/object:Gem::Version
206
+ version: '0.11'
165
207
  - !ruby/object:Gem::Dependency
166
208
  name: yajl-ruby
167
209
  requirement: !ruby/object:Gem::Requirement
168
210
  requirements:
169
211
  - - "~>"
170
212
  - !ruby/object:Gem::Version
171
- version: '1.0'
213
+ version: '1.4'
172
214
  type: :runtime
173
215
  prerelease: false
174
216
  version_requirements: !ruby/object:Gem::Requirement
175
217
  requirements:
176
218
  - - "~>"
177
219
  - !ruby/object:Gem::Version
178
- version: '1.0'
220
+ version: '1.4'
179
221
  - !ruby/object:Gem::Dependency
180
222
  name: hoe-mercurial
181
223
  requirement: !ruby/object:Gem::Requirement
@@ -238,14 +280,14 @@ dependencies:
238
280
  requirements:
239
281
  - - "~>"
240
282
  - !ruby/object:Gem::Version
241
- version: '3.1'
283
+ version: '3.4'
242
284
  type: :development
243
285
  prerelease: false
244
286
  version_requirements: !ruby/object:Gem::Requirement
245
287
  requirements:
246
288
  - - "~>"
247
289
  - !ruby/object:Gem::Version
248
- version: '3.1'
290
+ version: '3.4'
249
291
  - !ruby/object:Gem::Dependency
250
292
  name: simplecov
251
293
  requirement: !ruby/object:Gem::Requirement
@@ -339,7 +381,24 @@ files:
339
381
  - data/mongrel2/config.rb.in
340
382
  - data/mongrel2/config.sql
341
383
  - data/mongrel2/mimetypes.sql
384
+ - gem.deps.rb
342
385
  - lib/mongrel2.rb
386
+ - lib/mongrel2/cli.rb
387
+ - lib/mongrel2/cli/access.rb
388
+ - lib/mongrel2/cli/bootstrap.rb
389
+ - lib/mongrel2/cli/commit.rb
390
+ - lib/mongrel2/cli/hosts.rb
391
+ - lib/mongrel2/cli/init.rb
392
+ - lib/mongrel2/cli/load.rb
393
+ - lib/mongrel2/cli/log.rb
394
+ - lib/mongrel2/cli/quickstart.rb
395
+ - lib/mongrel2/cli/reload.rb
396
+ - lib/mongrel2/cli/routes.rb
397
+ - lib/mongrel2/cli/running.rb
398
+ - lib/mongrel2/cli/servers.rb
399
+ - lib/mongrel2/cli/settings.rb
400
+ - lib/mongrel2/cli/start.rb
401
+ - lib/mongrel2/cli/stop.rb
343
402
  - lib/mongrel2/config.rb
344
403
  - lib/mongrel2/config/directory.rb
345
404
  - lib/mongrel2/config/dsl.rb
@@ -411,7 +470,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
411
470
  requirements:
412
471
  - - ">="
413
472
  - !ruby/object:Gem::Version
414
- version: 2.4.0
473
+ version: 2.5.0
415
474
  required_rubygems_version: !ruby/object:Gem::Requirement
416
475
  requirements:
417
476
  - - ">="