mongrel2 0.53.0 → 0.54.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
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/ChangeLog +56 -2
- data/History.rdoc +7 -0
- data/Manifest.txt +17 -0
- data/Rakefile +21 -18
- data/bin/m2sh.rb +3 -738
- data/gem.deps.rb +2 -0
- data/lib/mongrel2.rb +1 -1
- data/lib/mongrel2/cli.rb +496 -0
- data/lib/mongrel2/cli/access.rb +29 -0
- data/lib/mongrel2/cli/bootstrap.rb +39 -0
- data/lib/mongrel2/cli/commit.rb +34 -0
- data/lib/mongrel2/cli/hosts.rb +51 -0
- data/lib/mongrel2/cli/init.rb +29 -0
- data/lib/mongrel2/cli/load.rb +41 -0
- data/lib/mongrel2/cli/log.rb +27 -0
- data/lib/mongrel2/cli/quickstart.rb +52 -0
- data/lib/mongrel2/cli/reload.rb +33 -0
- data/lib/mongrel2/cli/routes.rb +51 -0
- data/lib/mongrel2/cli/running.rb +44 -0
- data/lib/mongrel2/cli/servers.rb +34 -0
- data/lib/mongrel2/cli/settings.rb +26 -0
- data/lib/mongrel2/cli/start.rb +72 -0
- data/lib/mongrel2/cli/stop.rb +33 -0
- data/lib/mongrel2/config.rb +1 -0
- data/lib/mongrel2/config/directory.rb +11 -0
- data/lib/mongrel2/config/dsl.rb +13 -20
- data/lib/mongrel2/config/handler.rb +12 -0
- data/lib/mongrel2/config/host.rb +1 -1
- data/lib/mongrel2/config/proxy.rb +6 -0
- data/lib/mongrel2/config/server.rb +3 -2
- data/spec/mongrel2/config/dsl_spec.rb +6 -0
- metadata +73 -14
- metadata.gz.sig +0 -0
@@ -0,0 +1,29 @@
|
|
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 access command
|
10
|
+
module Mongrel2::CLI::AccessCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
desc "Dump the access log. The LOGFILE defaults to logs/access.log"
|
14
|
+
arg :LOGFILE, :optional
|
15
|
+
command :access do |accesscmd|
|
16
|
+
|
17
|
+
accesscmd.action do |globals, options, args|
|
18
|
+
logfile = args.shift || 'logs/access.log'
|
19
|
+
|
20
|
+
IO.foreach( logfile ) do |line|
|
21
|
+
row, _ = TNetstring.parse( line )
|
22
|
+
message %{[%4$d] %2$s:%3$d %1$s "%5$s %6$s %7$s" %8$03d %9$d} % row
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end # module Mongrel2::CLI::AccessCommand
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'pathname'
|
5
|
+
require 'mongrel2/config'
|
6
|
+
|
7
|
+
require 'mongrel2/cli' unless defined?( Mongrel2::CLI )
|
8
|
+
require 'mongrel2/constants'
|
9
|
+
|
10
|
+
|
11
|
+
# Mongrel2 bootstrap command
|
12
|
+
module Mongrel2::CLI::BootstrapCommand
|
13
|
+
extend Mongrel2::CLI::Subcommand
|
14
|
+
|
15
|
+
|
16
|
+
desc "Generate a basic config-generation script."
|
17
|
+
arg :CONFIG_SCRIPT, :optional
|
18
|
+
command :bootstrap do |bootstrapcmd|
|
19
|
+
|
20
|
+
bootstrapcmd.action do |globals, options, args|
|
21
|
+
scriptpath = Pathname( args.shift || Mongrel2::Constants::DEFAULT_CONFIG_SCRIPT )
|
22
|
+
template = Mongrel2::DATA_DIR + 'config.rb.in'
|
23
|
+
|
24
|
+
# Read the config DSL template
|
25
|
+
data = template.read
|
26
|
+
data.gsub!( /%% PWD %%/, Dir.pwd )
|
27
|
+
|
28
|
+
# Write it out
|
29
|
+
prompt.say( hl.header "Writing a config-generation script to %s" % [scriptpath] )
|
30
|
+
scriptpath.open( File::WRONLY|File::EXCL|File::CREAT, 0755, encoding: 'utf-8' ) do |fh|
|
31
|
+
fh.print( data )
|
32
|
+
end
|
33
|
+
prompt.say "Done."
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
end # module Mongrel2::CLI::BootstrapCommand
|
@@ -0,0 +1,34 @@
|
|
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 commit command
|
10
|
+
module Mongrel2::CLI::CommitCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
desc "Add a message to the commit log."
|
14
|
+
arg :WHAT, :optional
|
15
|
+
arg :WHERE, :optional
|
16
|
+
arg :WHY, :optional
|
17
|
+
arg :HOW, :optional
|
18
|
+
command :commit do |commitcmd|
|
19
|
+
|
20
|
+
commitcmd.action do |globals, options, args|
|
21
|
+
what, where, why, how = *args
|
22
|
+
what ||= '- mark -'
|
23
|
+
why ||= globals.why
|
24
|
+
|
25
|
+
log = Mongrel2::Config::Log.log_action( what, where, why, how )
|
26
|
+
|
27
|
+
prompt.say( hl.header "Okay, logged." )
|
28
|
+
prompt.say( log.to_s )
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end # module Mongrel2::CLI::CommitCommand
|
@@ -0,0 +1,51 @@
|
|
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 hosts command
|
10
|
+
module Mongrel2::CLI::HostsCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
desc "Lists the hosts in a server, or in all servers if none is specified."
|
14
|
+
arg :SERVERNAME, :optional
|
15
|
+
command :hosts do |hostscmd|
|
16
|
+
|
17
|
+
hostscmd.action do |globals, options, args|
|
18
|
+
servername = args.shift
|
19
|
+
|
20
|
+
# Start with all servers, then narrow it down if they specified a server name.
|
21
|
+
servers = Mongrel2::Config::Server.dataset
|
22
|
+
servers = servers.filter( name: servername ) if servername
|
23
|
+
|
24
|
+
|
25
|
+
# Output a section for each server
|
26
|
+
servers.each do |server|
|
27
|
+
hosts_table = TTY::Table.new( header: ['Id', 'Name', 'Matching'] )
|
28
|
+
|
29
|
+
prompt.say( hl.header %{HOSTS for server %s:} % [hl.key(server.name)] )
|
30
|
+
server.hosts.each do |host|
|
31
|
+
hosts_table << [
|
32
|
+
host.id,
|
33
|
+
host.name,
|
34
|
+
host.matching == host.name ? '*' : 'host.matching'
|
35
|
+
]
|
36
|
+
end
|
37
|
+
|
38
|
+
if hosts_table.empty?
|
39
|
+
prompt.say "No hosts."
|
40
|
+
else
|
41
|
+
prompt.say( hosts_table.render(:unicode) )
|
42
|
+
end
|
43
|
+
|
44
|
+
prompt.say( "\n" )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end # module Mongrel2::CLI::HostsCommand
|
@@ -0,0 +1,29 @@
|
|
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 init command
|
10
|
+
module Mongrel2::CLI::InitCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
desc "Initialize a new empty config database."
|
14
|
+
command :init do |initcmd|
|
15
|
+
|
16
|
+
initcmd.action do |globals, options, args|
|
17
|
+
if Mongrel2::Config.database_initialized?
|
18
|
+
exit_now! "Okay, aborting." unless
|
19
|
+
prompt.yes?( "Are you sure you want to destroy the current config? " )
|
20
|
+
end
|
21
|
+
|
22
|
+
prompt.say( headline_string "Initializing #{globals.config}" )
|
23
|
+
Mongrel2::Config.init_database!
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
end # module Mongrel2::CLI::InitCommand
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
require 'mongrel2/cli' unless defined?( Mongrel2::CLI )
|
7
|
+
|
8
|
+
|
9
|
+
# Mongrel2 load command
|
10
|
+
module Mongrel2::CLI::LoadCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
desc "Overwrite the config database with the values from the specified CONFIGFILE."
|
14
|
+
long_desc <<~END_DESC
|
15
|
+
Note: the CONFIGFILE should contain a configuration described using the
|
16
|
+
Ruby config DSL, not a Python-ish normal one. m2sh already works perfectly
|
17
|
+
fine for loading those.
|
18
|
+
END_DESC
|
19
|
+
arg :CONFIGFILE
|
20
|
+
command :load do |loadcmd|
|
21
|
+
|
22
|
+
loadcmd.action do |globals, options, args|
|
23
|
+
configfile = args.shift or
|
24
|
+
exit_now! "No configfile specified."
|
25
|
+
|
26
|
+
runspace = Module.new
|
27
|
+
runspace.extend( Mongrel2::Config::DSL )
|
28
|
+
runspace.extend( FileUtils::Verbose )
|
29
|
+
|
30
|
+
prompt.say( headline_string "Loading config from #{configfile}" )
|
31
|
+
source = File.read( configfile )
|
32
|
+
|
33
|
+
runspace.module_eval( source, configfile, 1 )
|
34
|
+
Mongrel2::Config.log_action( "Loaded config from #{configfile}", globals.why )
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end # module Mongrel2::CLI::LoadCommand
|
41
|
+
|
@@ -0,0 +1,27 @@
|
|
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 log command
|
10
|
+
module Mongrel2::CLI::LogCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
desc "Prints the commit log."
|
14
|
+
command :log do |logcmd|
|
15
|
+
|
16
|
+
logcmd.action do |globals, options, args|
|
17
|
+
prompt.say( hl.header "Log Messages" )
|
18
|
+
|
19
|
+
Mongrel2::Config::Log.order_by( :happened_at ).each do |log|
|
20
|
+
prompt.say( log.to_s )
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
end # module Mongrel2::CLI::LogCommand
|
@@ -0,0 +1,52 @@
|
|
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 quickstart command
|
10
|
+
module Mongrel2::CLI::QuickstartCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
|
14
|
+
desc "Set up a basic mongrel2 server and run it."
|
15
|
+
command :quickstart do |quickstartcmd|
|
16
|
+
|
17
|
+
quickstartcmd.action do |globals, options, args|
|
18
|
+
idx_template = Mongrel2::DATA_DIR + 'index.html.in'
|
19
|
+
configfile = 'config.rb'
|
20
|
+
|
21
|
+
header "Quickstart!"
|
22
|
+
self.bootstrap_command( configfile )
|
23
|
+
edit( configfile )
|
24
|
+
self.load_command( configfile )
|
25
|
+
|
26
|
+
# Now load the new config DB and fetch the configured server
|
27
|
+
host = Mongrel2::Config.servers.first.hosts.first
|
28
|
+
hello_route = host.routes_dataset.filter( target_type: 'handler' ).first
|
29
|
+
|
30
|
+
# Read the index page template
|
31
|
+
data = idx_template.read
|
32
|
+
data.gsub!( /%% VERSION %%/, Mongrel2.version_string(true) )
|
33
|
+
data.gsub!( /%% HELLOWORLD_SEND_SPEC %%/, hello_route.target.send_spec )
|
34
|
+
data.gsub!( /%% HELLOWORLD_RECV_SPEC %%/, hello_route.target.recv_spec )
|
35
|
+
data.gsub!( /%% HELLOWORLD_URI %%/, hello_route.path[ /([^\(]*)/ ] )
|
36
|
+
|
37
|
+
# Write it out to the public directory
|
38
|
+
header "Writing an index file to public/index.html"
|
39
|
+
Dir.mkdir( 'public' ) unless File.directory?( 'public' )
|
40
|
+
File.open( 'public/index.html', File::WRONLY|File::EXCL|File::CREAT, 0755,
|
41
|
+
encoding: 'utf-8' ) do |fh|
|
42
|
+
fh.print( data )
|
43
|
+
end
|
44
|
+
message "Done."
|
45
|
+
|
46
|
+
self.start_command()
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end # module Mongrel2::CLI::QuickstartCommand
|
@@ -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 reload command
|
10
|
+
module Mongrel2::CLI::ReloadCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
|
14
|
+
desc "Reload the specified server's configuration"
|
15
|
+
arg :SERVER
|
16
|
+
command :reload do |reloadcmd|
|
17
|
+
|
18
|
+
reloadcmd.action do |globals, options, args|
|
19
|
+
server = find_server( args.shift )
|
20
|
+
control = server.control_socket
|
21
|
+
|
22
|
+
prompt.say( hl.header "Reloading '%s'" % [ server.name ] )
|
23
|
+
control.reload
|
24
|
+
control.close
|
25
|
+
prompt.say( hl.success "done." )
|
26
|
+
|
27
|
+
Mongrel2::Config.log_action( "Restarted server #{server}", globals.why )
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
end # module Mongrel2::CLI::ReloadCommand
|
@@ -0,0 +1,51 @@
|
|
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 routes command
|
10
|
+
module Mongrel2::CLI::RoutesCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
|
14
|
+
desc "Show the routes under a host."
|
15
|
+
arg :SERVERNAME, :optional
|
16
|
+
arg :HOSTNAME, :optional
|
17
|
+
command :routes do |routescmd|
|
18
|
+
|
19
|
+
routescmd.action do |globals, options, args|
|
20
|
+
servername = args.shift
|
21
|
+
hostname = args.shift
|
22
|
+
|
23
|
+
# Start with all hosts, then narrow it down if a server and/or host was given.
|
24
|
+
if servername
|
25
|
+
server = Mongrel2::Config::Server[ servername ] or
|
26
|
+
exit_now! "No such server '#{servername}'"
|
27
|
+
hosts = server.hosts_dataset
|
28
|
+
else
|
29
|
+
hosts = Mongrel2::Config::Host.dataset
|
30
|
+
end
|
31
|
+
hosts = hosts.where( name: hostname ) if hostname
|
32
|
+
|
33
|
+
# Output a section for each host
|
34
|
+
hosts.each do |host|
|
35
|
+
header = "ROUTES for host %s/%s:" % [ hl.key(host.server.name), hl.key(host.name) ]
|
36
|
+
prompt.say( hl.header(header) )
|
37
|
+
|
38
|
+
routes_table = TTY::Table.new( header: ['Id', 'Path', 'Target'] )
|
39
|
+
host.routes.each do |route|
|
40
|
+
routes_table << [ route.id, route.path, route.target ]
|
41
|
+
end
|
42
|
+
|
43
|
+
prompt.say( routes_table.render(:unicode) )
|
44
|
+
prompt.say( "\n" )
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end # module Mongrel2::CLI::RoutesCommand
|
@@ -0,0 +1,44 @@
|
|
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 running command
|
10
|
+
module Mongrel2::CLI::RunningCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
|
14
|
+
desc "Show the status of a server."
|
15
|
+
arg :SERVER
|
16
|
+
command :running do |runningcmd|
|
17
|
+
|
18
|
+
runningcmd.action do |globals, options, args|
|
19
|
+
server = find_server( args.shift )
|
20
|
+
pidfile = server.pid_file_path
|
21
|
+
|
22
|
+
prompt.say( hl.header "Checking the status of the '%s' server." % [ server.name ] )
|
23
|
+
unless pidfile.exist?
|
24
|
+
prompt.say( hl.error "Not running: PID file (%s) doesn't exist." % [ pidfile ] )
|
25
|
+
exit
|
26
|
+
end
|
27
|
+
|
28
|
+
pid = Integer( pidfile.read )
|
29
|
+
begin
|
30
|
+
Process.kill( 0, pid )
|
31
|
+
rescue Errno::ESRCH
|
32
|
+
prompt.say( hl.error " mongrel2 at PID %d is NOT running" % [ pid ] )
|
33
|
+
exit
|
34
|
+
rescue => err
|
35
|
+
prompt.say( hl.error " %p while signalling PID %d: %s" % [ err.class, pid, err.message ] )
|
36
|
+
end
|
37
|
+
|
38
|
+
prompt.say( hl.success " mongrel2 at PID %d is running." % [ pid ] )
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end # module Mongrel2::CLI::RunningCommand
|
@@ -0,0 +1,34 @@
|
|
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 servers command
|
10
|
+
module Mongrel2::CLI::ServersCommand
|
11
|
+
extend Mongrel2::CLI::Subcommand
|
12
|
+
|
13
|
+
desc "Lists the servers in a config database."
|
14
|
+
command :servers do |serverscmd|
|
15
|
+
|
16
|
+
serverscmd.action do |globals, options, args|
|
17
|
+
prompt.say( hl.header 'SERVERS:' )
|
18
|
+
|
19
|
+
table = TTY::Table.new( header: ['Name', 'Default Host', 'Identifier'] )
|
20
|
+
Mongrel2::Config.servers.each do |server|
|
21
|
+
table << [
|
22
|
+
hl.key( server.name ),
|
23
|
+
server.default_host,
|
24
|
+
server.uuid,
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
prompt.say( table.render(:unicode) )
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
end # module Mongrel2::CLI::ServersCommand
|