notgun 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/CHANGELOG.md +19 -0
- data/Gemfile +3 -0
- data/LICENSE +18 -0
- data/README.md +110 -0
- data/RELEASING +8 -0
- data/Rakefile +17 -0
- data/bin/notgun +164 -0
- data/lib/notgun.rb +44 -0
- data/lib/notgun/favicon.rb +16 -0
- data/lib/notgun/loader.rb +141 -0
- data/lib/notgun/static.rb +20 -0
- data/man/index.txt +6 -0
- data/man/notgun.1 +231 -0
- data/man/notgun.1.ronn +220 -0
- data/notgun.gemspec +23 -0
- data/test/big.ru +15 -0
- data/test/boom.ru +4 -0
- data/test/slow.ru +16 -0
- data/test/test-sinatra.ru +14 -0
- data/test/test.ru +7 -0
- data/test/test_notgun_loader.rb +50 -0
- data/test/test_notgun_static.rb +26 -0
- data/test/verbose.ru +7 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 38cc9ebbf61380ac8482b45e79eaeefd0f8130f3
|
4
|
+
data.tar.gz: 5df2d2a1a642e9c7f3265fc6f6cd65a1692a77f0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 827f98ff6bdb115d48616b351a71f2048016cdb39800049a03d379ffe96504643a24b840391cf5d7fbefd0cf284cdbfa208faf4ee8914a81f69e9ba16e8fc4f5
|
7
|
+
data.tar.gz: f6f52ec3a621c606bfcf538a24a02f5c52b77feb82f10b3d29743d91899a324c094983f1f5c278c3b6a74f8a01642e1a75fae5d740a9ce774ea70c72a64c1371
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
0.9.2 - 2016-08-03
|
2
|
+
==================
|
3
|
+
|
4
|
+
* Forked and renamed to notgun (timriley)
|
5
|
+
|
6
|
+
* Added compatibility with Rack versions 2.0+ (macournoyer via [shotgun#61](https://github.com/rtomayko/shotgun/pull/61))
|
7
|
+
|
8
|
+
0.9.1 - 2015-03-01
|
9
|
+
==================
|
10
|
+
|
11
|
+
* Fixed a long-standing issue that caused Shotgun not to show any access logs
|
12
|
+
in the terminal (#57).
|
13
|
+
|
14
|
+
* Made `--url` option actually work (Adam Mckaig, #49).
|
15
|
+
|
16
|
+
Previous versions
|
17
|
+
=================
|
18
|
+
|
19
|
+
(See commit list.)
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Tomayko <tomayko.com/about>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to
|
5
|
+
deal in the Software without restriction, including without limitation the
|
6
|
+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
7
|
+
sell copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
16
|
+
THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# Notgun
|
2
|
+
|
3
|
+
Notgun is a fork of [Shotgun](https://github.com/rtomayko/shotgun) with Rack 2.0+ compatibility.
|
4
|
+
|
5
|
+
### Usage
|
6
|
+
|
7
|
+
Installation:
|
8
|
+
|
9
|
+
```shell
|
10
|
+
gem install notgun
|
11
|
+
```
|
12
|
+
|
13
|
+
Starting a server with a rackup file:
|
14
|
+
|
15
|
+
```shell
|
16
|
+
notgun config.ru
|
17
|
+
```
|
18
|
+
Using Thin and starting on port 6000 instead of 9393 (default):
|
19
|
+
|
20
|
+
```shell
|
21
|
+
notgun --server=thin --port=6000 config.ru
|
22
|
+
```
|
23
|
+
Running Sinatra apps:
|
24
|
+
|
25
|
+
|
26
|
+
```shell
|
27
|
+
notgun hello.rb
|
28
|
+
```
|
29
|
+
|
30
|
+
See 'notgun --help' for more advanced usage.
|
31
|
+
|
32
|
+
_Original Shotgun README follows:_
|
33
|
+
|
34
|
+
---
|
35
|
+
|
36
|
+
# Shotgun
|
37
|
+
|
38
|
+
This is an automatic reloading version of the rackup command that's shipped with
|
39
|
+
Rack. It can be used as an alternative to the complex reloading logic provided
|
40
|
+
by web frameworks or in environments that don't support application reloading.
|
41
|
+
|
42
|
+
The shotgun command starts one of Rack's supported servers (e.g., mongrel, thin,
|
43
|
+
webrick) and listens for requests but does not load any part of the actual
|
44
|
+
application. Each time a request is received, it forks, loads the application in
|
45
|
+
the child process, processes the request, and exits the child process. The
|
46
|
+
result is clean, application-wide reloading of all source files and templates on
|
47
|
+
each request.
|
48
|
+
|
49
|
+
Usage
|
50
|
+
-----
|
51
|
+
|
52
|
+
Installation:
|
53
|
+
|
54
|
+
```shell
|
55
|
+
gem install shotgun
|
56
|
+
```
|
57
|
+
|
58
|
+
Starting a server with a rackup file:
|
59
|
+
|
60
|
+
```shell
|
61
|
+
shotgun config.ru
|
62
|
+
```
|
63
|
+
Using Thin and starting on port 6000 instead of 9393 (default):
|
64
|
+
|
65
|
+
```shell
|
66
|
+
shotgun --server=thin --port=6000 config.ru
|
67
|
+
```
|
68
|
+
Running Sinatra apps:
|
69
|
+
|
70
|
+
|
71
|
+
```shell
|
72
|
+
shotgun hello.rb
|
73
|
+
```
|
74
|
+
|
75
|
+
See 'shotgun --help' for more advanced usage.
|
76
|
+
|
77
|
+
Compatibility
|
78
|
+
---
|
79
|
+
|
80
|
+
Because of the underlying technique used, Shotgun is only compatible with
|
81
|
+
systems that support `fork(2)` (probably just MRI on POSIX systems).
|
82
|
+
|
83
|
+
Caveats
|
84
|
+
---
|
85
|
+
|
86
|
+
* For performance reasons, Shotgun automatically includes middleware to serve
|
87
|
+
static files (similar to `Rack::Static`). If you rely on Rack serving static
|
88
|
+
assets, then do include `Rack::Static` yourself.
|
89
|
+
|
90
|
+
* If you use Sinatra, you may need to [set the session secret manually][sinatra-caveat].
|
91
|
+
|
92
|
+
* Similar to a Rackup file (`config.ru`), you can't use `require_relative` in
|
93
|
+
your preload files (`shotgun.rb`).
|
94
|
+
|
95
|
+
Links
|
96
|
+
-----
|
97
|
+
|
98
|
+
[Shotgun](http://github.com/rtomayko/shotgun)
|
99
|
+
|
100
|
+
[Rack](http://rack.rubyforge.org/)
|
101
|
+
|
102
|
+
[Sinatra](http://www.sinatrarb.com/)
|
103
|
+
|
104
|
+
The reloading system in Ian Bicking's webware framework served as inspiration
|
105
|
+
for the approach taken in Shotgun. Ian lays down the pros and cons of this
|
106
|
+
approach in the following article:
|
107
|
+
|
108
|
+
http://ianbicking.org/docs/Webware_reload.html
|
109
|
+
|
110
|
+
[sinatra-caveat]: https://groups.google.com/forum/#!topic/sinatrarb/pUFSoyQXyQs
|
data/RELEASING
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
|
3
|
+
require 'rake/clean'
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
task :default => [:test]
|
7
|
+
|
8
|
+
Rake::TestTask.new(:test) do |t|
|
9
|
+
t.test_files = FileList['test/test_notgun_*.rb']
|
10
|
+
t.ruby_opts = ['-rubygems'] if defined? Gem
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "build manual"
|
14
|
+
task :man do
|
15
|
+
ENV['RONN_ORGANIZATION'] = "Notgun #{SPEC.version}"
|
16
|
+
sh "ronn -5r -stoc man/*.ronn"
|
17
|
+
end
|
data/bin/notgun
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
env = ENV['RACK_ENV'] || 'development'
|
6
|
+
host = ENV['HOST'] || '127.0.0.1'
|
7
|
+
port = ENV['PORT'] || 9393
|
8
|
+
mount_path = "/"
|
9
|
+
browse = false
|
10
|
+
server = nil
|
11
|
+
public_dir = 'public' if File.directory?('public')
|
12
|
+
options = {:Port => port, :Host => host, :AccessLog => []}
|
13
|
+
|
14
|
+
opts = OptionParser.new("", 24, ' ') { |opts|
|
15
|
+
opts.banner = "Usage: notgun [ruby options] [rack options] [rackup config]"
|
16
|
+
|
17
|
+
opts.separator ""
|
18
|
+
opts.separator "Ruby options:"
|
19
|
+
|
20
|
+
lineno = 1
|
21
|
+
opts.on("-e", "--eval LINE", "evaluate a LINE of code") { |line|
|
22
|
+
eval line, TOPLEVEL_BINDING, "-e", lineno
|
23
|
+
lineno += 1
|
24
|
+
}
|
25
|
+
|
26
|
+
opts.on("-d", "--debug", "set debugging flags (set $DEBUG to true)") {
|
27
|
+
$DEBUG = true
|
28
|
+
}
|
29
|
+
opts.on("-w", "--warn", "turn warnings on for your script") {
|
30
|
+
$-w = true
|
31
|
+
}
|
32
|
+
|
33
|
+
opts.on("-I", "--include PATH",
|
34
|
+
"specify $LOAD_PATH (may be used more than once)") { |path|
|
35
|
+
$LOAD_PATH.unshift(*path.split(":"))
|
36
|
+
}
|
37
|
+
|
38
|
+
opts.on("-r", "--require LIBRARY",
|
39
|
+
"require the library, before executing your script") { |library|
|
40
|
+
require library
|
41
|
+
}
|
42
|
+
|
43
|
+
opts.separator ""
|
44
|
+
opts.separator "Rack options:"
|
45
|
+
opts.on("-s", "--server SERVER", "server (webrick, mongrel, thin, etc.)") { |s|
|
46
|
+
server = s
|
47
|
+
}
|
48
|
+
|
49
|
+
opts.on("-o", "--host HOST", "listen on HOST (default: 127.0.0.1)") { |host|
|
50
|
+
options[:Host] = host
|
51
|
+
}
|
52
|
+
|
53
|
+
opts.on("-p", "--port PORT", "use PORT (default: 9393)") { |port|
|
54
|
+
options[:Port] = port
|
55
|
+
}
|
56
|
+
|
57
|
+
opts.on("-E", "--env ENVIRONMENT", "use ENVIRONMENT for defaults (default: development)") { |e|
|
58
|
+
env = e
|
59
|
+
}
|
60
|
+
|
61
|
+
opts.separator ""
|
62
|
+
opts.separator "Notgun options:"
|
63
|
+
|
64
|
+
opts.on("-O", "--browse", "open browser immediately after starting") {
|
65
|
+
browse = true
|
66
|
+
}
|
67
|
+
|
68
|
+
opts.on("-u", "--url URL", "specify url path (default: #{mount_path})") { |url|
|
69
|
+
mount_path = url
|
70
|
+
}
|
71
|
+
|
72
|
+
opts.on("-P", "--public PATH", "serve static files under PATH") { |path|
|
73
|
+
public_dir = path
|
74
|
+
}
|
75
|
+
|
76
|
+
opts.on_tail("-h", "--help", "show this message") do
|
77
|
+
puts opts
|
78
|
+
exit
|
79
|
+
end
|
80
|
+
|
81
|
+
opts.on_tail("--version", "show version") do
|
82
|
+
require 'rack'
|
83
|
+
puts "Rack #{Rack.version}"
|
84
|
+
exit
|
85
|
+
end
|
86
|
+
|
87
|
+
opts.parse! ARGV
|
88
|
+
}
|
89
|
+
|
90
|
+
config = ARGV[0] || "config.ru"
|
91
|
+
abort "configuration #{config} not found" unless File.exist? config
|
92
|
+
|
93
|
+
# extract additional arguments from first #\ line in config file.
|
94
|
+
if File.read(config)[/^#\\(.*)/]
|
95
|
+
opts.parse! $1.split(/\s+/)
|
96
|
+
end
|
97
|
+
|
98
|
+
# use the BROWSER environment variable or fall back to a more or less standard
|
99
|
+
# set of commands
|
100
|
+
ENV['BROWSER'] ||=
|
101
|
+
%w[open xdg-open x-www-browser firefox opera mozilla netscape].find do |comm|
|
102
|
+
next if comm == 'open' && `uname` !~ /Darwin/
|
103
|
+
ENV['PATH'].split(':').any? { |dir| File.executable?("#{dir}/#{comm}") }
|
104
|
+
end
|
105
|
+
ENV['RACK_ENV'] = env
|
106
|
+
|
107
|
+
require 'rack'
|
108
|
+
|
109
|
+
require 'notgun'
|
110
|
+
|
111
|
+
require 'thin' if server.to_s.downcase == 'thin'
|
112
|
+
server = Rack::Handler.get(server) || Rack::Handler.default
|
113
|
+
|
114
|
+
app =
|
115
|
+
Rack::Builder.new do
|
116
|
+
map(mount_path) do
|
117
|
+
|
118
|
+
# these middleware run in the master process.
|
119
|
+
use Notgun::Static, public_dir if public_dir
|
120
|
+
use Notgun::SkipFavicon
|
121
|
+
|
122
|
+
# loader forks the child and runs the embedded config followed by the
|
123
|
+
# application config.
|
124
|
+
run Notgun::Loader.new(config) {
|
125
|
+
case env
|
126
|
+
when 'development'
|
127
|
+
use Rack::CommonLogger, STDERR unless server.name =~ /CGI/
|
128
|
+
use Rack::ShowExceptions
|
129
|
+
use Rack::Lint
|
130
|
+
when 'deployment', 'production'
|
131
|
+
use Rack::CommonLogger, STDERR unless server.name =~ /CGI/
|
132
|
+
end
|
133
|
+
}
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
Notgun.enable_copy_on_write
|
138
|
+
|
139
|
+
# trap exit signals
|
140
|
+
downward = false
|
141
|
+
['INT', 'TERM', 'QUIT'].each do |signal|
|
142
|
+
trap(signal) do
|
143
|
+
exit! if downward
|
144
|
+
downward = true
|
145
|
+
server.shutdown if server.respond_to?(:shutdown)
|
146
|
+
Process.wait rescue nil
|
147
|
+
exit!
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
# load notgun.rb in current working directory if it exists
|
152
|
+
Notgun.preload
|
153
|
+
|
154
|
+
base_url = "http://#{options[:Host]}:#{options[:Port]}#{mount_path}"
|
155
|
+
puts "== Notgun/#{server.to_s.sub(/Rack::Handler::/, '')} on #{base_url}"
|
156
|
+
server.run app, options do |inst|
|
157
|
+
if browse
|
158
|
+
if ENV['BROWSER']
|
159
|
+
system "#{ENV['BROWSER']} '#{base_url}'"
|
160
|
+
else
|
161
|
+
abort "BROWSER environment variable not set and no browser detected"
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
data/lib/notgun.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rack'
|
2
|
+
|
3
|
+
module Notgun
|
4
|
+
autoload :Loader, 'notgun/loader'
|
5
|
+
autoload :SkipFavicon, 'notgun/favicon'
|
6
|
+
autoload :Static, 'notgun/static'
|
7
|
+
|
8
|
+
def self.new(rackup_file, &block)
|
9
|
+
Loader.new(rackup_file, &block)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.enable_copy_on_write
|
13
|
+
GC.copy_on_write_friendly = true if GC.respond_to?(:copy_on_write_friendly=)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.preload(files=%w[./config/notgun.rb ./notgun.rb])
|
17
|
+
files.each do |preload_file|
|
18
|
+
if File.exist?(preload_file)
|
19
|
+
module_eval File.read(preload_file), preload_file
|
20
|
+
return preload_file
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.before_fork(&block)
|
26
|
+
@before_fork ||= []
|
27
|
+
@before_fork << block if block
|
28
|
+
@before_fork
|
29
|
+
end
|
30
|
+
|
31
|
+
def self.after_fork(&block)
|
32
|
+
@after_fork ||= []
|
33
|
+
@after_fork << block if block
|
34
|
+
@after_fork
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.before_fork!
|
38
|
+
before_fork.each { |block| block.call }
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.after_fork!
|
42
|
+
after_fork.each { |block| block.call }
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Notgun
|
2
|
+
# Responds to requests for /favicon.ico with a content free 404 and caching
|
3
|
+
# headers.
|
4
|
+
class SkipFavicon < Struct.new(:app)
|
5
|
+
def call(env)
|
6
|
+
if env['PATH_INFO'] == '/favicon.ico'
|
7
|
+
[404, {
|
8
|
+
'Content-Type' => 'image/png',
|
9
|
+
'Cache-Control' => 'public, max-age=100000000000'
|
10
|
+
}, []]
|
11
|
+
else
|
12
|
+
app.call(env)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,141 @@
|
|
1
|
+
require 'rack/utils'
|
2
|
+
require 'thread'
|
3
|
+
|
4
|
+
module Notgun
|
5
|
+
# Rack app that forks, loads the rackup config in the child process,
|
6
|
+
# processes a single request, and exits. The response is communicated over
|
7
|
+
# a unidirectional pipe.
|
8
|
+
class Loader
|
9
|
+
include Rack::Utils
|
10
|
+
attr_reader :rackup_file
|
11
|
+
|
12
|
+
def initialize(rackup_file, &block)
|
13
|
+
@rackup_file = rackup_file
|
14
|
+
@config = block || Proc.new { }
|
15
|
+
end
|
16
|
+
|
17
|
+
def call(env)
|
18
|
+
dup.call!(env)
|
19
|
+
end
|
20
|
+
|
21
|
+
def call!(env)
|
22
|
+
@env = env
|
23
|
+
@reader, @writer = IO.pipe
|
24
|
+
|
25
|
+
Notgun.before_fork!
|
26
|
+
|
27
|
+
if @child = fork
|
28
|
+
proceed_as_parent
|
29
|
+
else
|
30
|
+
Notgun.after_fork!
|
31
|
+
proceed_as_child
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Stuff that happens in the parent process
|
37
|
+
|
38
|
+
def proceed_as_parent
|
39
|
+
@writer.close
|
40
|
+
rand
|
41
|
+
result, status, headers = Marshal.load(@reader)
|
42
|
+
body = Body.new(@child, @reader)
|
43
|
+
case result
|
44
|
+
when :ok
|
45
|
+
[status, headers, body]
|
46
|
+
when :error
|
47
|
+
error, backtrace = status, headers
|
48
|
+
body.close
|
49
|
+
[
|
50
|
+
500,
|
51
|
+
{'Content-Type'=>'text/html;charset=utf-8'},
|
52
|
+
[format_error(error, backtrace)]
|
53
|
+
]
|
54
|
+
else
|
55
|
+
fail "unexpected response: #{result.inspect}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
class Body < Struct.new(:pid, :fd)
|
60
|
+
def each
|
61
|
+
while chunk = fd.read(1024)
|
62
|
+
yield chunk
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def close
|
67
|
+
fd.close
|
68
|
+
ensure
|
69
|
+
Process.wait(pid)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def format_error(error, backtrace)
|
74
|
+
"<h1>Boot Error</h1>" +
|
75
|
+
"<p>Something went wrong while loading <tt>#{escape_html(rackup_file)}</tt></p>" +
|
76
|
+
"<h3>#{escape_html(error)}</h3>" +
|
77
|
+
"<pre>#{escape_html(backtrace.join("\n"))}</pre>"
|
78
|
+
end
|
79
|
+
|
80
|
+
##
|
81
|
+
# Stuff that happens in the child process
|
82
|
+
|
83
|
+
def proceed_as_child
|
84
|
+
boom = false
|
85
|
+
@reader.close
|
86
|
+
status, headers, body = assemble_app.call(@env)
|
87
|
+
Marshal.dump([:ok, status, headers.to_hash], @writer)
|
88
|
+
spec_body(body).each { |chunk| @writer.write(chunk) }
|
89
|
+
body.close if body.respond_to?(:close)
|
90
|
+
rescue Object => boom
|
91
|
+
Marshal.dump([
|
92
|
+
:error,
|
93
|
+
"#{boom.class.name}: #{boom.to_s}",
|
94
|
+
boom.backtrace
|
95
|
+
], @writer)
|
96
|
+
ensure
|
97
|
+
@writer.close
|
98
|
+
exit! boom ? 1 : 0
|
99
|
+
end
|
100
|
+
|
101
|
+
def assemble_app
|
102
|
+
config = @config
|
103
|
+
inner_app = self.inner_app
|
104
|
+
Rack::Builder.new {
|
105
|
+
instance_eval(&config)
|
106
|
+
run inner_app
|
107
|
+
}.to_app
|
108
|
+
end
|
109
|
+
|
110
|
+
def inner_app
|
111
|
+
if rackup_file =~ /\.ru$/
|
112
|
+
config = File.read(rackup_file)
|
113
|
+
eval "Rack::Builder.new {( #{config}\n )}.to_app", nil, rackup_file
|
114
|
+
else
|
115
|
+
require File.expand_path(rackup_file)
|
116
|
+
if defined? Sinatra::Application
|
117
|
+
Sinatra::Application.set :reload, false
|
118
|
+
Sinatra::Application.set :logging, false
|
119
|
+
Sinatra::Application.set :raise_errors, true
|
120
|
+
Sinatra::Application
|
121
|
+
else
|
122
|
+
Object.const_get(camel_case(File.basename(rackup_file, '.rb')))
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def camel_case(string)
|
128
|
+
string.split("_").map { |part| part.capitalize }.join
|
129
|
+
end
|
130
|
+
|
131
|
+
def spec_body(body)
|
132
|
+
if body.respond_to? :to_str
|
133
|
+
[body]
|
134
|
+
elsif body.respond_to?(:each)
|
135
|
+
body
|
136
|
+
else
|
137
|
+
fail "body must respond to #each"
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'rack/file'
|
2
|
+
|
3
|
+
module Notgun
|
4
|
+
# Serves static files out of the specified directory.
|
5
|
+
class Static
|
6
|
+
def initialize(app, public_dir='./public')
|
7
|
+
@file = Rack::File.new(public_dir)
|
8
|
+
@app = app
|
9
|
+
end
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
status, headers, body = @file.call(env)
|
13
|
+
if status > 400
|
14
|
+
@app.call(env)
|
15
|
+
else
|
16
|
+
[status, headers, body]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/man/index.txt
ADDED
data/man/notgun.1
ADDED
@@ -0,0 +1,231 @@
|
|
1
|
+
.\" generated with Ronn/v0.7.3
|
2
|
+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
|
+
.
|
4
|
+
.TH "SHOTGUN" "1" "March 2015" "Notgun 0.9.1" ""
|
5
|
+
.
|
6
|
+
.SH "NAME"
|
7
|
+
\fBnotgun\fR \- reloading rack development server
|
8
|
+
.
|
9
|
+
.SH "SYNOPSIS"
|
10
|
+
\fBnotgun\fR [\fIoptions\fR] [\fIrackup\-file\fR]
|
11
|
+
.
|
12
|
+
.SH "DESCRIPTION"
|
13
|
+
\fBNotgun\fR is a simple process\-per\-request Rack \fIhttp://rack\.rubyforge\.org/doc/README\.html\fR server designed for use in development environments\. Each time a request is received, \fBnotgun\fR forks, loads the \fIrackup\-file\fR, processes a single request and exits\. The result is application\-wide reloading of all configuration, source files, and templates without the need for complex application\-level reloading logic\.
|
14
|
+
.
|
15
|
+
.P
|
16
|
+
When no \fIrackup\-file\fR is given, \fBnotgun\fR uses the \fBconfig\.ru\fR file in the current working directory\.
|
17
|
+
.
|
18
|
+
.SH "OPTIONS"
|
19
|
+
Notgun runs at \fBhttp://127\.0\.0\.1:9393\fR by default\. The following options control server behavior:
|
20
|
+
.
|
21
|
+
.TP
|
22
|
+
\fB\-E\fR, \fB\-\-env\fR=\fIenvironment\fR
|
23
|
+
Sets the \fBRACK_ENV\fR environment variable to \fIenvironment\fR and selects the default set of utility middleware\. When \fIenvironment\fR is \'development\', notgun inserts the \fBRack::Lint\fR and \fBRack::CommonLogger\fR middleware components; when \fIenvironment\fR is \'production\' or \'deployed\', \fBRack::CommonLogger\fR is inserted; otherwise, no utility middleware are inserted\.
|
24
|
+
.
|
25
|
+
.TP
|
26
|
+
\fB\-P\fR, \fB\-\-public\fR=\fIpath\fR
|
27
|
+
Serve requests for static files that exist under \fIpath\fR from the notgun master process without forking a worker process\. This option is automatically enabled when a \fB\./public\fR directory is detected, but can be configured explicitly for non\-conventional static file directory locations\.
|
28
|
+
.
|
29
|
+
.IP
|
30
|
+
Setting this option appropriately can severely improve overall page load times for applications with many static assets\.
|
31
|
+
.
|
32
|
+
.TP
|
33
|
+
\fB\-s\fR, \fB\-\-server\fR=\fImongrel\fR|\fIwebrick\fR|\fIthin\fR|\fIother\fR
|
34
|
+
The Rack server handler implementation used to serve requests\. Supported values include: \fBmongrel\fR, \fBwebrick\fR, and \fBthin\fR\. By default, notgun first tries to use \fBmongrel\fR and falls back to \fBwebrick\fR if mongrel is not available\.
|
35
|
+
.
|
36
|
+
.TP
|
37
|
+
\fB\-o\fR, \fB\-\-host\fR=\fIaddr\fR
|
38
|
+
The hostname or address of the interface the HTTP server should bind to\. Overrides the \fBHOST\fR environment variable\. Default: \fB127\.0\.0\.1\fR\.
|
39
|
+
.
|
40
|
+
.TP
|
41
|
+
\fB\-p\fR, \fB\-\-port\fR=\fIport\fR
|
42
|
+
The port the HTTP server should bind to\. Overrides the \fBPORT\fR environment variable\. Default: \fB9393\fR\.
|
43
|
+
.
|
44
|
+
.TP
|
45
|
+
\fB\-O\fR, \fB\-\-browse\fR
|
46
|
+
Open browser at http://\fIhost\fR:\fIport\fR/ immediately after the server is started\.
|
47
|
+
.
|
48
|
+
.P
|
49
|
+
Ruby environment related options:
|
50
|
+
.
|
51
|
+
.TP
|
52
|
+
\fB\-r\fR, \fB\-\-require\fR \fIlibrary\fR
|
53
|
+
Require \fIlibrary\fR before loading the application and starting the server\. This can be used to load a portion of the application code in the master process so it doesn\'t need to be loaded in the child\. See \fIPRELOADING\fR][] for more information on this approach\.
|
54
|
+
.
|
55
|
+
.TP
|
56
|
+
\fB\-e\fR, \fB\-\-eval\fR \fIcommand\fR
|
57
|
+
Evaluate arbitrary \fIcommand\fR within the notgun master Ruby interpreter\. \fIcommand\fR is evaluated as program arguments are parsed\. Multiple \fB\-e\fR arguments are allowed\.
|
58
|
+
.
|
59
|
+
.TP
|
60
|
+
\fB\-d\fR, \fB\-\-debug\fR
|
61
|
+
Turns on debug mode\. \fB$DEBUG\fR will be set \fBtrue\fR\.
|
62
|
+
.
|
63
|
+
.TP
|
64
|
+
\fB\-w\fR, \fB\-\-warn\fR
|
65
|
+
Enable verbose mode without printing version message at the beginning\. It sets the \fB$VERBOSE\fR variable to true\.
|
66
|
+
.
|
67
|
+
.TP
|
68
|
+
\fB\-I\fR, \fB\-\-include\fR \fIpath\fR
|
69
|
+
Add \fIpath\fR to the Ruby load path (\fB$LOAD_PATH\fR)\. May be used more than once\.
|
70
|
+
.
|
71
|
+
.P
|
72
|
+
Miscellaneous:
|
73
|
+
.
|
74
|
+
.TP
|
75
|
+
\fB\-h\fR, \fB\-\-help\fR
|
76
|
+
Show usage message and exit\.
|
77
|
+
.
|
78
|
+
.TP
|
79
|
+
\fB\-\-version\fR
|
80
|
+
Show the Rack version and exit\.
|
81
|
+
.
|
82
|
+
.SH "ENVIRONMENT"
|
83
|
+
The following environment variables affect the configuration of \fBnotgun\fR:
|
84
|
+
.
|
85
|
+
.TP
|
86
|
+
\fBHOST\fR
|
87
|
+
The hostname or address of the interface the HTTP server should bind to\. See the \fB\-h\fR option\.
|
88
|
+
.
|
89
|
+
.TP
|
90
|
+
\fBPORT\fR
|
91
|
+
The port the HTTP server should bind to\. See the \fB\-p\fR option\.
|
92
|
+
.
|
93
|
+
.SH "PRELOADING"
|
94
|
+
It\'s possible to load support libraries and portions of the application in the notgun master process to reduce the amount of work that needs to be done for each request in worker processes\. There\'s two ways of accomplishing this: either by specifying one or more \fB\-\-require\fR (\fB\-r\fR) arguments or through the use of a \fBnotgun\.rb\fR file\.
|
95
|
+
.
|
96
|
+
.P
|
97
|
+
During start up, notgun looks for a \fBnotgun\.rb\fR or \fBconfig/notgun\.rb\fR file\. If either file is found, it\'s loaded into the notgun master process\. Code at the top\-level of the \fBnotgun\.rb\fR is run once on startup, so just require whatever you want to preload\. It\'s also possible to register callbacks to run before each request in either the master or child worker process:
|
98
|
+
.
|
99
|
+
.TP
|
100
|
+
\fBafter_fork {\fR \fIstuff\fR \fB}\fR
|
101
|
+
Run \fIstuff\fR in the notgun child worker process immediately after forking\. Any files or socket connections opened in the master process should be closed / re\-established by an \fBafter_fork\fR block\.
|
102
|
+
.
|
103
|
+
.TP
|
104
|
+
\fBbefore_fork {\fR \fIstuff\fR \fB}\fR
|
105
|
+
Run \fIstuff\fR in the notgun master process on each request before forking the child worker process\. This is typically less useful than \fBafter_fork\fR, but provided for completeness\.
|
106
|
+
.
|
107
|
+
.P
|
108
|
+
Example \fBconfig/notgun\.rb\fR file from the main github\.com rails project:
|
109
|
+
.
|
110
|
+
.IP "" 4
|
111
|
+
.
|
112
|
+
.nf
|
113
|
+
|
114
|
+
# make sure the load path includes RAILS_ROOT
|
115
|
+
ENV[\'RAILS_ROOT\'] ||= File\.expand_path(\'\.\./\.\.\', __FILE__)
|
116
|
+
$:\.unshift ENV[\'RAILS_ROOT\']
|
117
|
+
|
118
|
+
# bring in the base rails environment and some libraries
|
119
|
+
require \'config/environment\'
|
120
|
+
require \'google\-charts\'
|
121
|
+
require \'aws\-s3\'
|
122
|
+
|
123
|
+
# disable Rails\'s built in class reloading
|
124
|
+
Rails\.configuration\.cache_classes = true
|
125
|
+
|
126
|
+
# reset database and redis connections in workers
|
127
|
+
after_fork do
|
128
|
+
ActiveRecord::Base\.establish_connection
|
129
|
+
CHIMNEY\.client = $redis
|
130
|
+
end
|
131
|
+
.
|
132
|
+
.fi
|
133
|
+
.
|
134
|
+
.IP "" 0
|
135
|
+
.
|
136
|
+
.SH "INSTALLING"
|
137
|
+
Notgun is distributed as a gem package at rubygems\.org:
|
138
|
+
.
|
139
|
+
.P
|
140
|
+
\fIhttp://rubygems\.org/gems/notgun\fR
|
141
|
+
.
|
142
|
+
.br
|
143
|
+
\fBgem install notgun\fR
|
144
|
+
.
|
145
|
+
.P
|
146
|
+
The \fBrack\fR package is required\. The \fBmongrel\fR package is recommended\.
|
147
|
+
.
|
148
|
+
.SH "CONTRIBUTING"
|
149
|
+
Fork and report issues at github\.com:
|
150
|
+
.
|
151
|
+
.P
|
152
|
+
\fIhttp://github\.com/rtomayko/notgun/\fR
|
153
|
+
.
|
154
|
+
.br
|
155
|
+
\fBgit clone git://github\.com/rtomayko/notgun\.git\fR
|
156
|
+
.
|
157
|
+
.SH "VERSION HISTORY"
|
158
|
+
.
|
159
|
+
.SS "Version 0\.9\.1 (2015 March 1)"
|
160
|
+
.
|
161
|
+
.IP "\(bu" 4
|
162
|
+
Fix a long\-standing issue that caused Notgun not to show any access logs in the terminal (#57)\.
|
163
|
+
.
|
164
|
+
.IP "\(bu" 4
|
165
|
+
Make \fB\-\-url\fR option actually work\.
|
166
|
+
.
|
167
|
+
.IP "" 0
|
168
|
+
.
|
169
|
+
.SS "Version 0\.9 (2011 February 24)"
|
170
|
+
.
|
171
|
+
.IP "\(bu" 4
|
172
|
+
\fIhttp://github\.com/rtomayko/notgun/compare/0\.8\.\.\.0\.9\fR
|
173
|
+
.
|
174
|
+
.IP "\(bu" 4
|
175
|
+
Various Ruby 1\.9\.2 fixes\.
|
176
|
+
.
|
177
|
+
.IP "\(bu" 4
|
178
|
+
Handle application class names consisting of multiple words\.
|
179
|
+
.
|
180
|
+
.IP "" 0
|
181
|
+
.
|
182
|
+
.SS "Version 0\.8 (2010 June 24)"
|
183
|
+
.
|
184
|
+
.IP "\(bu" 4
|
185
|
+
\fIhttp://github\.com/rtomayko/notgun/compare/0\.7\.\.\.0\.8\fR
|
186
|
+
.
|
187
|
+
.IP "\(bu" 4
|
188
|
+
Preloading support\. The \fBnotgun\.rb\fR or \fBconfig/notgun\.rb\fR file is loaded at startup and may require libraries and register callbacks for fork events\. See the section on \fIPRELOADING\fR\.
|
189
|
+
.
|
190
|
+
.IP "\(bu" 4
|
191
|
+
Fix starting with the Thin handler (\fBnotgun \-s thin\fR)
|
192
|
+
.
|
193
|
+
.IP "\(bu" 4
|
194
|
+
Actually include the notgun(1) roff manual\.
|
195
|
+
.
|
196
|
+
.IP "" 0
|
197
|
+
.
|
198
|
+
.SS "Version 0\.7 (2010 June 22)"
|
199
|
+
.
|
200
|
+
.IP "\(bu" 4
|
201
|
+
\fIhttp://github\.com/rtomayko/notgun/compare/0\.6\.\.\.0\.7\fR
|
202
|
+
.
|
203
|
+
.IP "\(bu" 4
|
204
|
+
Static files now served from the notgun master process, making notgun tolerable for apps with many/unbundled static assets\.
|
205
|
+
.
|
206
|
+
.IP "\(bu" 4
|
207
|
+
Added \fB\-\-public\fR (\fB\-P\fR) for specifying a non\-standard root / public directory\.
|
208
|
+
.
|
209
|
+
.IP "\(bu" 4
|
210
|
+
Response bodies are now streamed over the master < worker pipe instead of being marshalled\. Improves performance with large response bodies, and reduces notgun master process RES usage\.
|
211
|
+
.
|
212
|
+
.IP "\(bu" 4
|
213
|
+
GET /favicon\.ico requests are served an empty response by the notgun master process\. Prevents the need to fork a worker process\.
|
214
|
+
.
|
215
|
+
.IP "\(bu" 4
|
216
|
+
\fBINT\fR, \fBTERM\fR, \fBQUIT\fR now properly trigger server shutdown\. The second \fBINT\fR, \fBTERM\fR, \fBQUIT\fR causes the master process to exit hard\.
|
217
|
+
.
|
218
|
+
.IP "\(bu" 4
|
219
|
+
Non \fB\.ru\fR config files (e\.g\., sinatra app files) may now define command line options in the same way as \fB\.ru\fR files: by including a \fB#\e \-p 5555 \.\.\.\fR line\.
|
220
|
+
.
|
221
|
+
.IP "" 0
|
222
|
+
.
|
223
|
+
.SS "Versions < 0\.7 (2009\-2010)"
|
224
|
+
.
|
225
|
+
.IP "\(bu" 4
|
226
|
+
\fIhttp://github\.com/rtomayko/notgun/commits/0\.6\fR
|
227
|
+
.
|
228
|
+
.IP "" 0
|
229
|
+
.
|
230
|
+
.SH "SEE ALSO"
|
231
|
+
ruby(1)
|
data/man/notgun.1.ronn
ADDED
@@ -0,0 +1,220 @@
|
|
1
|
+
notgun(1) -- reloading rack development server
|
2
|
+
===============================================
|
3
|
+
|
4
|
+
## SYNOPSIS
|
5
|
+
|
6
|
+
`notgun` [<options>] [<rackup-file>]
|
7
|
+
|
8
|
+
## DESCRIPTION
|
9
|
+
|
10
|
+
**Notgun** is a simple process-per-request [Rack][] server designed for use in
|
11
|
+
development environments. Each time a request is received, `notgun` forks,
|
12
|
+
loads the <rackup-file>, processes a single request and exits. The result is
|
13
|
+
application-wide reloading of all configuration, source files, and templates
|
14
|
+
without the need for complex application-level reloading logic.
|
15
|
+
|
16
|
+
When no <rackup-file> is given, `notgun` uses the `config.ru` file in the
|
17
|
+
current working directory.
|
18
|
+
|
19
|
+
## OPTIONS
|
20
|
+
|
21
|
+
Notgun runs at `http://127.0.0.1:9393` by default. The following options
|
22
|
+
control server behavior:
|
23
|
+
|
24
|
+
* `-E`, `--env`=<environment>:
|
25
|
+
Sets the `RACK_ENV` environment variable to <environment> and selects
|
26
|
+
the default set of utility middleware. When <environment> is 'development',
|
27
|
+
notgun inserts the `Rack::Lint` and `Rack::CommonLogger` middleware
|
28
|
+
components; when <environment> is 'production' or 'deployed',
|
29
|
+
`Rack::CommonLogger` is inserted; otherwise, no utility middleware are
|
30
|
+
inserted.
|
31
|
+
|
32
|
+
* `-P`, `--public`=<path>:
|
33
|
+
Serve requests for static files that exist under <path> from the notgun
|
34
|
+
master process without forking a worker process. This option is
|
35
|
+
automatically enabled when a `./public` directory is detected, but can be
|
36
|
+
configured explicitly for non-conventional static file directory locations.
|
37
|
+
|
38
|
+
Setting this option appropriately can severely improve overall page load
|
39
|
+
times for applications with many static assets.
|
40
|
+
|
41
|
+
* `-s`, `--server`=<mongrel>|<webrick>|<thin>|<other>:
|
42
|
+
The Rack server handler implementation used to serve requests. Supported
|
43
|
+
values include: `mongrel`, `webrick`, and `thin`. By default, notgun first
|
44
|
+
tries to use `mongrel` and falls back to `webrick` if mongrel is not
|
45
|
+
available.
|
46
|
+
|
47
|
+
* `-o`, `--host`=<addr>:
|
48
|
+
The hostname or address of the interface the HTTP server should bind to.
|
49
|
+
Overrides the `HOST` environment variable. Default: `127.0.0.1`.
|
50
|
+
|
51
|
+
* `-p`, `--port`=<port>:
|
52
|
+
The port the HTTP server should bind to. Overrides the `PORT` environment
|
53
|
+
variable. Default: `9393`.
|
54
|
+
|
55
|
+
* `-O`, `--browse`:
|
56
|
+
Open browser at http://<host>:<port>/ immediately after the server
|
57
|
+
is started.
|
58
|
+
|
59
|
+
Ruby environment related options:
|
60
|
+
|
61
|
+
* `-r`, `--require` <library>:
|
62
|
+
Require <library> before loading the application and starting the server.
|
63
|
+
This can be used to load a portion of the application code in the master
|
64
|
+
process so it doesn't need to be loaded in the child. See [PRELOADING]][]
|
65
|
+
for more information on this approach.
|
66
|
+
|
67
|
+
* `-e`, `--eval` <command>:
|
68
|
+
Evaluate arbitrary <command> within the notgun master Ruby interpreter.
|
69
|
+
<command> is evaluated as program arguments are parsed. Multiple `-e`
|
70
|
+
arguments are allowed.
|
71
|
+
|
72
|
+
* `-d`, `--debug`:
|
73
|
+
Turns on debug mode. `$DEBUG` will be set `true`.
|
74
|
+
|
75
|
+
* `-w`, `--warn`:
|
76
|
+
Enable verbose mode without printing version message at the beginning. It
|
77
|
+
sets the `$VERBOSE` variable to true.
|
78
|
+
|
79
|
+
* `-I`, `--include` <path>:
|
80
|
+
Add <path> to the Ruby load path (`$LOAD_PATH`). May be used more than once.
|
81
|
+
|
82
|
+
Miscellaneous:
|
83
|
+
|
84
|
+
* `-h`, `--help`:
|
85
|
+
Show usage message and exit.
|
86
|
+
|
87
|
+
* `--version`:
|
88
|
+
Show the Rack version and exit.
|
89
|
+
|
90
|
+
## ENVIRONMENT
|
91
|
+
|
92
|
+
The following environment variables affect the configuration of `notgun`:
|
93
|
+
|
94
|
+
* `HOST`:
|
95
|
+
The hostname or address of the interface the HTTP server should bind to. See
|
96
|
+
the `-h` option.
|
97
|
+
|
98
|
+
* `PORT`:
|
99
|
+
The port the HTTP server should bind to. See the `-p` option.
|
100
|
+
|
101
|
+
## PRELOADING
|
102
|
+
|
103
|
+
It's possible to load support libraries and portions of the application in the
|
104
|
+
notgun master process to reduce the amount of work that needs to be done for
|
105
|
+
each request in worker processes. There's two ways of accomplishing this: either
|
106
|
+
by specifying one or more `--require` (`-r`) arguments or through the use of a
|
107
|
+
`notgun.rb` file.
|
108
|
+
|
109
|
+
During start up, notgun looks for a `notgun.rb` or `config/notgun.rb` file.
|
110
|
+
If either file is found, it's loaded into the notgun master process. Code at
|
111
|
+
the top-level of the `notgun.rb` is run once on startup, so just require
|
112
|
+
whatever you want to preload. It's also possible to register callbacks to run
|
113
|
+
before each request in either the master or child worker process:
|
114
|
+
|
115
|
+
* `after_fork {` <stuff> `}`:
|
116
|
+
Run <stuff> in the notgun child worker process immediately after forking.
|
117
|
+
Any files or socket connections opened in the master process should be
|
118
|
+
closed / re-established by an `after_fork` block.
|
119
|
+
|
120
|
+
* `before_fork {` <stuff> `}`:
|
121
|
+
Run <stuff> in the notgun master process on each request before forking
|
122
|
+
the child worker process. This is typically less useful than `after_fork`,
|
123
|
+
but provided for completeness.
|
124
|
+
|
125
|
+
Example `config/notgun.rb` file from the main github.com rails project:
|
126
|
+
|
127
|
+
# make sure the load path includes RAILS_ROOT
|
128
|
+
ENV['RAILS_ROOT'] ||= File.expand_path('../..', __FILE__)
|
129
|
+
$:.unshift ENV['RAILS_ROOT']
|
130
|
+
|
131
|
+
# bring in the base rails environment and some libraries
|
132
|
+
require 'config/environment'
|
133
|
+
require 'google-charts'
|
134
|
+
require 'aws-s3'
|
135
|
+
|
136
|
+
# disable Rails's built in class reloading
|
137
|
+
Rails.configuration.cache_classes = true
|
138
|
+
|
139
|
+
# reset database and redis connections in workers
|
140
|
+
after_fork do
|
141
|
+
ActiveRecord::Base.establish_connection
|
142
|
+
CHIMNEY.client = $redis
|
143
|
+
end
|
144
|
+
|
145
|
+
## INSTALLING
|
146
|
+
|
147
|
+
Notgun is distributed as a gem package at rubygems.org:
|
148
|
+
|
149
|
+
<http://rubygems.org/gems/notgun><br>
|
150
|
+
`gem install notgun`
|
151
|
+
|
152
|
+
The `rack` package is required. The `mongrel` package is recommended.
|
153
|
+
|
154
|
+
## CONTRIBUTING
|
155
|
+
|
156
|
+
Fork and report issues at github.com:
|
157
|
+
|
158
|
+
<http://github.com/rtomayko/notgun/><br>
|
159
|
+
`git clone git://github.com/rtomayko/notgun.git`
|
160
|
+
|
161
|
+
## VERSION HISTORY
|
162
|
+
|
163
|
+
### Version 0.9.1 (2015 March 1)
|
164
|
+
|
165
|
+
* Fix a long-standing issue that caused Notgun not to show any access logs
|
166
|
+
in the terminal (#57).
|
167
|
+
|
168
|
+
* Make `--url` option actually work.
|
169
|
+
|
170
|
+
### Version 0.9 (2011 February 24)
|
171
|
+
|
172
|
+
* <http://github.com/rtomayko/notgun/compare/0.8...0.9>
|
173
|
+
|
174
|
+
* Various Ruby 1.9.2 fixes.
|
175
|
+
|
176
|
+
* Handle application class names consisting of multiple words.
|
177
|
+
|
178
|
+
### Version 0.8 (2010 June 24)
|
179
|
+
|
180
|
+
* <http://github.com/rtomayko/notgun/compare/0.7...0.8>
|
181
|
+
|
182
|
+
* Preloading support. The `notgun.rb` or `config/notgun.rb` file is
|
183
|
+
loaded at startup and may require libraries and register callbacks
|
184
|
+
for fork events. See the section on [PRELOADING][].
|
185
|
+
|
186
|
+
* Fix starting with the Thin handler (`notgun -s thin`)
|
187
|
+
|
188
|
+
* Actually include the notgun(1) roff manual.
|
189
|
+
|
190
|
+
### Version 0.7 (2010 June 22)
|
191
|
+
|
192
|
+
* <http://github.com/rtomayko/notgun/compare/0.6...0.7>
|
193
|
+
|
194
|
+
* Static files now served from the notgun master process, making
|
195
|
+
notgun tolerable for apps with many/unbundled static assets.
|
196
|
+
|
197
|
+
* Added `--public` (`-P`) for specifying a non-standard root / public
|
198
|
+
directory.
|
199
|
+
|
200
|
+
* Response bodies are now streamed over the master < worker pipe
|
201
|
+
instead of being marshalled. Improves performance with large response
|
202
|
+
bodies, and reduces notgun master process RES usage.
|
203
|
+
|
204
|
+
* GET /favicon.ico requests are served an empty response by the notgun
|
205
|
+
master process. Prevents the need to fork a worker process.
|
206
|
+
|
207
|
+
* `INT`, `TERM`, `QUIT` now properly trigger server shutdown. The second
|
208
|
+
`INT`, `TERM`, `QUIT` causes the master process to exit hard.
|
209
|
+
|
210
|
+
* Non `.ru` config files (e.g., sinatra app files) may now define command
|
211
|
+
line options in the same way as `.ru` files: by including a
|
212
|
+
`#\ -p 5555 ...` line.
|
213
|
+
|
214
|
+
### Versions < 0.7 (2009-2010)
|
215
|
+
|
216
|
+
* <http://github.com/rtomayko/notgun/commits/0.6>
|
217
|
+
|
218
|
+
## SEE ALSO
|
219
|
+
|
220
|
+
ruby(1)
|
data/notgun.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = 'notgun'
|
3
|
+
s.version = '0.9.2'
|
4
|
+
|
5
|
+
s.description = "Reloading Rack development server (Shotgun fork with Rack 2.0+ support)"
|
6
|
+
s.summary = s.description
|
7
|
+
|
8
|
+
s.license = "MIT"
|
9
|
+
|
10
|
+
s.authors = ["Ryan Tomayko"]
|
11
|
+
s.email = "rtomayko@gmail.com"
|
12
|
+
|
13
|
+
s.files = `git ls-files`.split("\n")
|
14
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
15
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
16
|
+
|
17
|
+
s.add_dependency 'rack', '>= 1.0'
|
18
|
+
|
19
|
+
s.add_development_dependency 'rake'
|
20
|
+
s.add_development_dependency 'test-unit'
|
21
|
+
|
22
|
+
s.homepage = "https://github.com/timriley/notgun"
|
23
|
+
end
|
data/test/big.ru
ADDED
data/test/boom.ru
ADDED
data/test/slow.ru
ADDED
data/test/test.ru
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rack/mock'
|
3
|
+
require 'notgun'
|
4
|
+
|
5
|
+
class NotgunLoaderTest < Test::Unit::TestCase
|
6
|
+
def rackup_file(name)
|
7
|
+
"#{File.dirname(__FILE__)}/#{name}"
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_knows_the_rackup_file
|
11
|
+
file = rackup_file('test.ru')
|
12
|
+
notgun = Notgun::Loader.new(file)
|
13
|
+
assert_equal file, notgun.rackup_file
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_processes_requests
|
17
|
+
file = rackup_file('test.ru')
|
18
|
+
notgun = Notgun::Loader.new(file)
|
19
|
+
request = Rack::MockRequest.new(notgun)
|
20
|
+
res = request.get("/")
|
21
|
+
assert_equal 200, res.status
|
22
|
+
assert_equal "BANG!", res.body
|
23
|
+
assert_equal "text/plain", res.headers['Content-Type']
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_processes_large_requests
|
27
|
+
file = rackup_file('big.ru')
|
28
|
+
notgun = Notgun::Loader.new(file)
|
29
|
+
request = Rack::MockRequest.new(notgun)
|
30
|
+
res = request.get("/")
|
31
|
+
assert_equal 200, res.status
|
32
|
+
assert res.body =~ %r|<pre>(?:.{1023}\n){1024}</pre>|,
|
33
|
+
"body of size #{res.body.size} does not match expected output"
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_logging
|
37
|
+
file = rackup_file('verbose.ru')
|
38
|
+
|
39
|
+
$logger = File.open('test/verbose.log', 'w')
|
40
|
+
$logger.sync = true
|
41
|
+
|
42
|
+
notgun = Notgun::Loader.new(file)
|
43
|
+
request = Rack::MockRequest.new(notgun)
|
44
|
+
request.get('/', 'REMOTE_ADDR' => 'foo.local')
|
45
|
+
|
46
|
+
$logger.close
|
47
|
+
|
48
|
+
assert_match /^foo.local/, File.read('test/verbose.log')
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test/unit'
|
2
|
+
require 'rack/mock'
|
3
|
+
require 'notgun'
|
4
|
+
|
5
|
+
class NotgunStaticTest < Test::Unit::TestCase
|
6
|
+
def setup
|
7
|
+
@app = lambda { |env| [200,{'Content-Type'=>'text/plain'}, ['holla']] }
|
8
|
+
@public = File.dirname(__FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_serving_files
|
12
|
+
static = Notgun::Static.new(@app, @public)
|
13
|
+
request = Rack::MockRequest.new(static)
|
14
|
+
res = request.get("/big.ru")
|
15
|
+
assert_equal 200, res.status
|
16
|
+
assert_equal File.size("#{@public}/big.ru"), res.body.size
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_cascading_when_file_not_found
|
20
|
+
static = Notgun::Static.new(@app, @public)
|
21
|
+
request = Rack::MockRequest.new(static)
|
22
|
+
res = request.get("/does-not-exist")
|
23
|
+
assert_equal 200, res.status
|
24
|
+
assert_equal 'holla', res.body
|
25
|
+
end
|
26
|
+
end
|
data/test/verbose.ru
ADDED
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: notgun
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryan Tomayko
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-08-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rack
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: test-unit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Reloading Rack development server (Shotgun fork with Rack 2.0+ support)
|
56
|
+
email: rtomayko@gmail.com
|
57
|
+
executables:
|
58
|
+
- notgun
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- CHANGELOG.md
|
64
|
+
- Gemfile
|
65
|
+
- LICENSE
|
66
|
+
- README.md
|
67
|
+
- RELEASING
|
68
|
+
- Rakefile
|
69
|
+
- bin/notgun
|
70
|
+
- lib/notgun.rb
|
71
|
+
- lib/notgun/favicon.rb
|
72
|
+
- lib/notgun/loader.rb
|
73
|
+
- lib/notgun/static.rb
|
74
|
+
- man/index.txt
|
75
|
+
- man/notgun.1
|
76
|
+
- man/notgun.1.ronn
|
77
|
+
- notgun.gemspec
|
78
|
+
- test/big.ru
|
79
|
+
- test/boom.ru
|
80
|
+
- test/slow.ru
|
81
|
+
- test/test-sinatra.ru
|
82
|
+
- test/test.ru
|
83
|
+
- test/test_notgun_loader.rb
|
84
|
+
- test/test_notgun_static.rb
|
85
|
+
- test/verbose.ru
|
86
|
+
homepage: https://github.com/timriley/notgun
|
87
|
+
licenses:
|
88
|
+
- MIT
|
89
|
+
metadata: {}
|
90
|
+
post_install_message:
|
91
|
+
rdoc_options: []
|
92
|
+
require_paths:
|
93
|
+
- lib
|
94
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
95
|
+
requirements:
|
96
|
+
- - ">="
|
97
|
+
- !ruby/object:Gem::Version
|
98
|
+
version: '0'
|
99
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
requirements: []
|
105
|
+
rubyforge_project:
|
106
|
+
rubygems_version: 2.5.1
|
107
|
+
signing_key:
|
108
|
+
specification_version: 4
|
109
|
+
summary: Reloading Rack development server (Shotgun fork with Rack 2.0+ support)
|
110
|
+
test_files:
|
111
|
+
- test/big.ru
|
112
|
+
- test/boom.ru
|
113
|
+
- test/slow.ru
|
114
|
+
- test/test-sinatra.ru
|
115
|
+
- test/test.ru
|
116
|
+
- test/test_notgun_loader.rb
|
117
|
+
- test/test_notgun_static.rb
|
118
|
+
- test/verbose.ru
|