rsense-server 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +14 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +1 -0
  6. data/README.md +51 -0
  7. data/Rakefile +9 -0
  8. data/bin/_rsense.rb +115 -0
  9. data/config/puma.rb +2 -0
  10. data/lib/rsense/server/code.rb +38 -0
  11. data/lib/rsense/server/command/completion_result.rb +11 -0
  12. data/lib/rsense/server/command/special_meth.rb +18 -0
  13. data/lib/rsense/server/command/type_inference_method.rb +24 -0
  14. data/lib/rsense/server/command.rb +239 -0
  15. data/lib/rsense/server/config.rb +70 -0
  16. data/lib/rsense/server/gem_path.rb +18 -0
  17. data/lib/rsense/server/listeners/find_definition_event_listener.rb +91 -0
  18. data/lib/rsense/server/listeners/where_event_listener.rb +39 -0
  19. data/lib/rsense/server/load_path.rb +62 -0
  20. data/lib/rsense/server/options.rb +85 -0
  21. data/lib/rsense/server/parser.rb +17 -0
  22. data/lib/rsense/server/path_info.rb +17 -0
  23. data/lib/rsense/server/project.rb +24 -0
  24. data/lib/rsense/server/version.rb +5 -0
  25. data/lib/rsense/server.rb +18 -0
  26. data/rsense-server.gemspec +35 -0
  27. data/spec/fixtures/config_fixture/.rsense +4 -0
  28. data/spec/fixtures/deeply/nested/thing.rb +0 -0
  29. data/spec/fixtures/find_def_sample.json +10 -0
  30. data/spec/fixtures/sample.json +10 -0
  31. data/spec/fixtures/test_gem/.gitignore +22 -0
  32. data/spec/fixtures/test_gem/Gemfile +4 -0
  33. data/spec/fixtures/test_gem/LICENSE.txt +22 -0
  34. data/spec/fixtures/test_gem/README.md +29 -0
  35. data/spec/fixtures/test_gem/Rakefile +2 -0
  36. data/spec/fixtures/test_gem/lib/sample/version.rb +3 -0
  37. data/spec/fixtures/test_gem/lib/sample.rb +16 -0
  38. data/spec/fixtures/test_gem/sample.gemspec +23 -0
  39. data/spec/fixtures/test_gem/test.json +10 -0
  40. data/spec/rsense/server/code_spec.rb +44 -0
  41. data/spec/rsense/server/command/special_meth_spec.rb +23 -0
  42. data/spec/rsense/server/command_spec.rb +108 -0
  43. data/spec/rsense/server/config_spec.rb +27 -0
  44. data/spec/rsense/server/gem_path_spec.rb +16 -0
  45. data/spec/rsense/server/load_path_spec.rb +63 -0
  46. data/spec/rsense/server/options_spec.rb +33 -0
  47. data/spec/rsense/server/path_info_spec.rb +11 -0
  48. data/spec/rsense/server/project_spec.rb +18 -0
  49. data/spec/rsense/server_spec.rb +7 -0
  50. data/spec/spec_helper.rb +16 -0
  51. data/vendor/gems/puma-2.8.2-java/COPYING +55 -0
  52. data/vendor/gems/puma-2.8.2-java/DEPLOYMENT.md +92 -0
  53. data/vendor/gems/puma-2.8.2-java/Gemfile +17 -0
  54. data/vendor/gems/puma-2.8.2-java/History.txt +532 -0
  55. data/vendor/gems/puma-2.8.2-java/LICENSE +26 -0
  56. data/vendor/gems/puma-2.8.2-java/Manifest.txt +68 -0
  57. data/vendor/gems/puma-2.8.2-java/README.md +251 -0
  58. data/vendor/gems/puma-2.8.2-java/Rakefile +158 -0
  59. data/vendor/gems/puma-2.8.2-java/bin/puma +10 -0
  60. data/vendor/gems/puma-2.8.2-java/bin/puma-wild +17 -0
  61. data/vendor/gems/puma-2.8.2-java/bin/pumactl +12 -0
  62. data/vendor/gems/puma-2.8.2-java/docs/config.md +0 -0
  63. data/vendor/gems/puma-2.8.2-java/docs/nginx.md +80 -0
  64. data/vendor/gems/puma-2.8.2-java/docs/signals.md +42 -0
  65. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/PumaHttp11Service.java +17 -0
  66. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/ext_help.h +15 -0
  67. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/extconf.rb +8 -0
  68. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.c +1225 -0
  69. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.h +64 -0
  70. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.java.rl +161 -0
  71. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.rl +146 -0
  72. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser_common.rl +54 -0
  73. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/io_buffer.c +155 -0
  74. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/mini_ssl.c +195 -0
  75. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/Http11.java +225 -0
  76. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/Http11Parser.java +488 -0
  77. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/MiniSSL.java +289 -0
  78. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/puma_http11.c +491 -0
  79. data/vendor/gems/puma-2.8.2-java/lib/puma/accept_nonblock.rb +23 -0
  80. data/vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb +59 -0
  81. data/vendor/gems/puma-2.8.2-java/lib/puma/binder.rb +298 -0
  82. data/vendor/gems/puma-2.8.2-java/lib/puma/capistrano.rb +86 -0
  83. data/vendor/gems/puma-2.8.2-java/lib/puma/cli.rb +587 -0
  84. data/vendor/gems/puma-2.8.2-java/lib/puma/client.rb +289 -0
  85. data/vendor/gems/puma-2.8.2-java/lib/puma/cluster.rb +389 -0
  86. data/vendor/gems/puma-2.8.2-java/lib/puma/compat.rb +18 -0
  87. data/vendor/gems/puma-2.8.2-java/lib/puma/configuration.rb +377 -0
  88. data/vendor/gems/puma-2.8.2-java/lib/puma/const.rb +165 -0
  89. data/vendor/gems/puma-2.8.2-java/lib/puma/control_cli.rb +251 -0
  90. data/vendor/gems/puma-2.8.2-java/lib/puma/daemon_ext.rb +25 -0
  91. data/vendor/gems/puma-2.8.2-java/lib/puma/delegation.rb +11 -0
  92. data/vendor/gems/puma-2.8.2-java/lib/puma/detect.rb +4 -0
  93. data/vendor/gems/puma-2.8.2-java/lib/puma/events.rb +130 -0
  94. data/vendor/gems/puma-2.8.2-java/lib/puma/io_buffer.rb +7 -0
  95. data/vendor/gems/puma-2.8.2-java/lib/puma/java_io_buffer.rb +45 -0
  96. data/vendor/gems/puma-2.8.2-java/lib/puma/jruby_restart.rb +83 -0
  97. data/vendor/gems/puma-2.8.2-java/lib/puma/minissl.rb +148 -0
  98. data/vendor/gems/puma-2.8.2-java/lib/puma/null_io.rb +34 -0
  99. data/vendor/gems/puma-2.8.2-java/lib/puma/puma_http11.jar +0 -0
  100. data/vendor/gems/puma-2.8.2-java/lib/puma/rack_default.rb +7 -0
  101. data/vendor/gems/puma-2.8.2-java/lib/puma/rack_patch.rb +45 -0
  102. data/vendor/gems/puma-2.8.2-java/lib/puma/reactor.rb +183 -0
  103. data/vendor/gems/puma-2.8.2-java/lib/puma/runner.rb +146 -0
  104. data/vendor/gems/puma-2.8.2-java/lib/puma/server.rb +801 -0
  105. data/vendor/gems/puma-2.8.2-java/lib/puma/single.rb +102 -0
  106. data/vendor/gems/puma-2.8.2-java/lib/puma/tcp_logger.rb +32 -0
  107. data/vendor/gems/puma-2.8.2-java/lib/puma/thread_pool.rb +185 -0
  108. data/vendor/gems/puma-2.8.2-java/lib/puma/util.rb +9 -0
  109. data/vendor/gems/puma-2.8.2-java/lib/puma.rb +14 -0
  110. data/vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb +66 -0
  111. data/vendor/gems/puma-2.8.2-java/puma.gemspec +55 -0
  112. data/vendor/gems/puma-2.8.2-java/test/test_app_status.rb +92 -0
  113. data/vendor/gems/puma-2.8.2-java/test/test_cli.rb +173 -0
  114. data/vendor/gems/puma-2.8.2-java/test/test_config.rb +26 -0
  115. data/vendor/gems/puma-2.8.2-java/test/test_http10.rb +27 -0
  116. data/vendor/gems/puma-2.8.2-java/test/test_http11.rb +144 -0
  117. data/vendor/gems/puma-2.8.2-java/test/test_integration.rb +165 -0
  118. data/vendor/gems/puma-2.8.2-java/test/test_iobuffer.rb +38 -0
  119. data/vendor/gems/puma-2.8.2-java/test/test_minissl.rb +25 -0
  120. data/vendor/gems/puma-2.8.2-java/test/test_null_io.rb +31 -0
  121. data/vendor/gems/puma-2.8.2-java/test/test_persistent.rb +238 -0
  122. data/vendor/gems/puma-2.8.2-java/test/test_puma_server.rb +323 -0
  123. data/vendor/gems/puma-2.8.2-java/test/test_rack_handler.rb +10 -0
  124. data/vendor/gems/puma-2.8.2-java/test/test_rack_server.rb +141 -0
  125. data/vendor/gems/puma-2.8.2-java/test/test_tcp_rack.rb +42 -0
  126. data/vendor/gems/puma-2.8.2-java/test/test_thread_pool.rb +156 -0
  127. data/vendor/gems/puma-2.8.2-java/test/test_unix_socket.rb +39 -0
  128. data/vendor/gems/puma-2.8.2-java/test/test_ws.rb +89 -0
  129. data/vendor/gems/puma-2.8.2-java/tools/jungle/README.md +9 -0
  130. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/README.md +54 -0
  131. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/puma +332 -0
  132. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/run-puma +3 -0
  133. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/README.md +61 -0
  134. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/puma-manager.conf +31 -0
  135. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/puma.conf +63 -0
  136. data/vendor/gems/puma-2.8.2-java/tools/trickletest.rb +45 -0
  137. metadata +389 -0
@@ -0,0 +1,251 @@
1
+ # Puma: A Ruby Web Server Built For Concurrency
2
+
3
+ [![Build Status](https://secure.travis-ci.org/puma/puma.png)](http://travis-ci.org/puma/puma) [![Dependency Status](https://gemnasium.com/puma/puma.png)](https://gemnasium.com/puma/puma) <a href="https://codeclimate.com/github/puma/puma"><img src="https://codeclimate.com/github/puma/puma.png" /></a>
4
+
5
+ ## Description
6
+
7
+ Puma is a simple, fast, threaded, and highly concurrent HTTP 1.1 server for Ruby/Rack applications. Puma is intended for use in both development and production environments. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like Rubinius or JRuby.
8
+
9
+ ## Built For Speed &amp; Concurrency
10
+
11
+ Puma is a simple, fast, and highly concurrent HTTP 1.1 server for Ruby web applications. It can be used with any application that supports Rack, and is considered the replacement for Webrick and Mongrel. It was designed to be the go-to server for [Rubinius](http://rubini.us), but also works well with JRuby and MRI. Puma is intended for use in both development and production environments.
12
+
13
+ Under the hood, Puma processes requests using a C-optimized Ragel extension (inherited from Mongrel) that provides fast, accurate HTTP 1.1 protocol parsing in a portable way. Puma then serves the request in a thread from an internal thread pool (which you can control). This allows Puma to provide real concurrency for your web application!
14
+
15
+ With Rubinius 2.0, Puma will utilize all cores on your CPU with real threads, meaning you won't have to spawn multiple processes to increase throughput. You can expect to see a similar benefit from JRuby.
16
+
17
+ On MRI, there is a Global Interpreter Lock (GIL) that ensures only one thread can be run at a time. But if you're doing a lot of blocking IO (such as HTTP calls to external APIs like Twitter), Puma still improves MRI's throughput by allowing blocking IO to be run concurrently (EventMachine-based servers such as Thin turn off this ability, requiring you to use special libraries). Your mileage may vary. In order to get the best throughput, it is highly recommended that you use a Ruby implementation with real threads like [Rubinius](http://rubini.us) or [JRuby](http://jruby.org).
18
+
19
+ ## Quick Start
20
+
21
+ The easiest way to get started with Puma is to install it via RubyGems. You can do this easily:
22
+
23
+ $ gem install puma
24
+
25
+ Now you should have the `puma` command available in your PATH, so just do the following in the root folder of your Rack application:
26
+
27
+ $ puma app.ru
28
+
29
+ ## Advanced Setup
30
+
31
+ ### Sinatra
32
+
33
+ You can run your Sinatra application with Puma from the command line like this:
34
+
35
+ $ ruby app.rb -s Puma
36
+
37
+ Or you can configure your application to always use Puma:
38
+
39
+ require 'sinatra'
40
+ configure { set :server, :puma }
41
+
42
+ If you use Bundler, make sure you add Puma to your Gemfile (see below).
43
+
44
+ ### Rails
45
+
46
+ First, make sure Puma is in your Gemfile:
47
+
48
+ gem 'puma'
49
+
50
+ Then start your server with the `rails` command:
51
+
52
+ $ rails s Puma
53
+
54
+ ### Rackup
55
+
56
+ You can pass it as an option to `rackup`:
57
+
58
+ $ rackup -s Puma
59
+
60
+ Alternatively, you can modify your `config.ru` to choose Puma by default, by adding the following as the first line:
61
+
62
+ #\ -s puma
63
+
64
+ ## Configuration
65
+
66
+ Puma provides numerous options for controlling the operation of the server. Consult `puma -h` (or `puma --help`) for a full list.
67
+
68
+ ### Thread Pool
69
+
70
+ Puma utilizes a dynamic thread pool which you can modify. You can set the minimum and maximum number of threads that are available in the pool with the `-t` (or `--threads`) flag:
71
+
72
+ $ puma -t 8:32
73
+
74
+ Puma will automatically scale the number of threads based on how much traffic is present. The current default is `0:16`. Feel free to experiment, but be careful not to set the number of maximum threads to a very large number, as you may exhaust resources on the system (or hit resource limits).
75
+
76
+ ### Clustered mode
77
+
78
+ Puma 2 offers clustered mode, allowing you to use forked processes to handle multiple incoming requests concurrently, in addition to threads already provided. You can tune the number of workers with the `-w` (or `--workers`) flag:
79
+
80
+ $ puma -t 8:32 -w 3
81
+
82
+ On a ruby implementation that offers native threads, you should tune this number to match the number of cores available.
83
+ Note that threads are still used in clustered mode, and the `-t` thread flag setting is per worker, so `-w 2 -t 16:16` will be 32 threads.
84
+
85
+ If you're running in Clustered Mode you can optionally choose to preload your application before starting up the workers. This is necessary in order to take advantage of the [Copy on Write](http://en.wikipedia.org/wiki/Copy-on-write) feature introduced in [MRI Ruby 2.0](https://blog.heroku.com/archives/2013/3/6/matz_highlights_ruby_2_0_at_waza). To do this simply specify the `--preload` flag in invocation:
86
+
87
+ # CLI invocation
88
+ $ puma -t 8:32 -w 3 --preload
89
+
90
+ If you're using a configuration file, use the `preload_app!` method, and be sure to specify your config file's location with the `-C` flag:
91
+
92
+ $ puma -C config/puma.rb
93
+
94
+ # config/puma.rb
95
+ threads 8,32
96
+ workers 3
97
+ preload_app!
98
+
99
+ Additionally, you can specify a block in your configuration file that will be run on boot of each worker:
100
+
101
+ # config/puma.rb
102
+ on_worker_boot do
103
+ # configuration here
104
+ end
105
+
106
+ This code can be used to setup the process before booting the application, allowing
107
+ you to do some Puma-specific things that you don't want to embed in your application.
108
+ For instance, you could fire a log notification that a worker booted or send something to statsd.
109
+ This can be called multiple times to add hooks.
110
+
111
+ If you're preloading your application and using ActiveRecord, it's recommend you setup your connection pool here:
112
+
113
+ # config/puma.rb
114
+ on_worker_boot do
115
+ ActiveSupport.on_load(:active_record) do
116
+ ActiveRecord::Base.establish_connection
117
+ end
118
+ end
119
+
120
+ When you use preload_app, your new code goes all in the master process, and is then copied in the workers (meaning it’s only compatible with cluster mode). General rule is to use preload_app when your workers die often and need fast starts. If you don’t have many workers, you should probably don’t use preload_app.
121
+
122
+ Note that preload_app can’t be used with phased restart, since phased restart kills and restarts workers one-by-one, and preload_app is all about copying the code of master into the workers.
123
+
124
+ ### Binding TCP / Sockets
125
+
126
+ In contrast to many other server configs which require multiple flags, Puma simply uses one URI parameter with the `-b` (or `--bind`) flag:
127
+
128
+ $ puma -b tcp://127.0.0.1:9292
129
+
130
+ Want to use UNIX Sockets instead of TCP (which can provide a 5-10% performance boost)? No problem!
131
+
132
+ $ puma -b unix:///var/run/puma.sock
133
+
134
+ If you need to change the permissions of the UNIX socket, just add a umask parameter:
135
+
136
+ $ puma -b 'unix:///var/run/puma.sock?umask=0777'
137
+
138
+ Need a bit of security? Use SSL sockets!
139
+
140
+ $ puma -b 'ssl://127.0.0.1:9292?key=path_to_key&cert=path_to_cert'
141
+
142
+ ### Control/Status Server
143
+
144
+ Puma comes with a builtin status/control app that can be used query and control Puma itself. Here is an example of starting Puma with the control server:
145
+
146
+ $ puma --control tcp://127.0.0.1:9293 --control-token foo
147
+
148
+ This directs Puma to start the control server on localhost port 9293. Additionally, all requests to the control server will need to include `token=foo` as a query parameter. This allows for simple authentication. Check out [status.rb](https://github.com/puma/puma/blob/master/lib/puma/app/status.rb) to see what the app has available.
149
+
150
+ ### Configuration file
151
+
152
+ You can also provide a configuration file which Puma will use with the `-C` (or `--config`) flag:
153
+
154
+ $ puma -C /path/to/config
155
+
156
+ By default, if no configuration file is specifed, Puma will look for a configuration file at config/puma.rb. If an environment is specified, either via the `-e` and `--environment` flags, or through the `RACK_ENV` environment variable, the default file location will be config/puma/environment_name.rb.
157
+
158
+ If you want to prevent Puma from looking for a configuration file in those locations, provide a dash as the argument to the `-C` (or `--config`) flag:
159
+
160
+ $ puma -C "-"
161
+
162
+ Take the following [sample configuration](https://github.com/puma/puma/blob/master/examples/config.rb) as inspiration or check out [configuration.rb](https://github.com/puma/puma/blob/master/lib/puma/configuration.rb) to see all available options.
163
+
164
+ ## Restart
165
+
166
+ Puma includes the ability to restart itself allowing easy upgrades to new versions. When available (MRI, Rubinius, JRuby), Puma performs a "hot restart". This is the same functionality available in *unicorn* and *nginx* which keep the server sockets open between restarts. This makes sure that no pending requests are dropped while the restart is taking place.
167
+
168
+ To perform a restart, there are 2 builtin mechanisms:
169
+
170
+ * Send the `puma` process the `SIGUSR2` signal
171
+ * Use the status server and issue `/restart`
172
+
173
+ No code is shared between the current and restarted process, so it should be safe to issue a restart any place where you would manually stop Puma and start it again.
174
+
175
+ If the new process is unable to load, it will simply exit. You should therefore run Puma under a supervisor when using it in production.
176
+
177
+ ### Normal vs Hot vs Phased Restart
178
+
179
+ A hot restart means that no requests while deploying your new code will be lost, since the server socket is kept open between restarts.
180
+
181
+ But beware, hot restart does not mean that the incoming requests won’t hang for multiple seconds while your new code has not fully deployed. If you need a zero downtime and zero hanging requests deploy, you must use phased restart.
182
+
183
+ When you run pumactl phased-restart, Puma kills workers one-by-one, meaning that at least another worker is still available to serve requests, which lead in zero hanging request (yay!).
184
+
185
+ But again beware, upgrading an application sometimes involves upgrading the database schema. With phased restart, there may be a moment during the deployment where processes belonging to the previous version and processes belonging to the new version both exist at the same time. Any database schema upgrades you perform must therefore be backwards-compatible with the old application version.
186
+
187
+ if you perform a lot of database migrations, you probably should not use phased restart and use a normal/hot restart instead (pumactl restart). That way, no code is shared while deploying (in that case, preload_app might help for quicker deployment, see below).
188
+
189
+
190
+ ### Cleanup Code
191
+
192
+ Puma isn't able to understand all the resources that your app may use, so it provides a hook in the configuration file you pass to `-C` called `on_restart`. The block passed to `on_restart` will be called, unsurprisingly, just before Puma restarts itself.
193
+
194
+ You should place code to close global log files, redis connections, etc in this block so that their file descriptors don't leak into the restarted process. Failure to do so will result in slowly running out of descriptors and eventually obscure crashes as the server is restart many times.
195
+
196
+ ### Platform Constraints
197
+
198
+ Because of various platforms not being implement certain things, the following differences occur when Puma is used on different platforms:
199
+
200
+ * **JRuby**, **Windows**: server sockets are not seamless on restart, they must be closed and reopened. These platforms have no way to pass descriptors into a new process that is exposed to ruby
201
+ * **JRuby**, **Windows**: cluster mode is not supported due to a lack of fork(2)
202
+ * **Windows**: daemon mode is not supported due to a lack of fork(2)
203
+
204
+ ## pumactl
205
+
206
+ `pumactl` is a simple CLI frontend to the control/status app described above. Please refer to `pumactl --help` for available commands.
207
+
208
+ ## Managing multiple Pumas / init.d / upstart scripts
209
+
210
+ If you want an easy way to manage multiple scripts at once check [tools/jungle](https://github.com/puma/puma/tree/master/tools/jungle) for init.d and upstart scripts.
211
+
212
+ ## Capistrano deployment
213
+
214
+ Puma has support for Capistrano3 with an [external gem](https://github.com/seuros/capistrano-puma), you just need require that in Gemfile:
215
+
216
+ ```ruby
217
+ gem 'capistrano3-puma'
218
+ ```
219
+ And then execute:
220
+
221
+ ```bash
222
+ bundle
223
+ ```
224
+
225
+ Then add to Capfile
226
+
227
+ ```ruby
228
+ require 'capistrano/puma'
229
+ ```
230
+
231
+ and then
232
+
233
+ ```bash
234
+ $ bundle exec cap puma:start
235
+ $ bundle exec cap puma:restart
236
+ $ bundle exec cap puma:stop
237
+ $ bundle exec cap puma:phased_restart
238
+ ```
239
+
240
+ ## Contributing
241
+
242
+ To run the test suite:
243
+
244
+ ```bash
245
+ $ bundle install
246
+ $ bundle exec rake
247
+ ```
248
+
249
+ ## License
250
+
251
+ Puma is copyright 2013 Evan Phoenix and contributors. It is licensed under the BSD license. See the include LICENSE file for details.
@@ -0,0 +1,158 @@
1
+ require "hoe"
2
+ require "rake/extensiontask"
3
+ require "rake/javaextensiontask"
4
+
5
+ IS_JRUBY = defined?(RUBY_ENGINE) ? RUBY_ENGINE == "jruby" : false
6
+
7
+ Hoe.plugin :git
8
+ Hoe.plugin :ignore
9
+
10
+ HOE = Hoe.spec "puma" do
11
+ self.readme_file = "README.md"
12
+ self.urls = %w!http://puma.io https://github.com/puma/puma!
13
+
14
+ license "BSD"
15
+ developer 'Evan Phoenix', 'evan@phx.io'
16
+
17
+ spec_extras[:extensions] = ["ext/puma_http11/extconf.rb"]
18
+ spec_extras[:executables] = ['puma', 'pumactl']
19
+ spec_extras[:homepage] = self.urls.first
20
+
21
+ require_ruby_version ">= 1.8.7"
22
+
23
+ dependency "rack", [">= 1.1", "< 2.0"]
24
+
25
+ extra_dev_deps << ["rake-compiler", "~> 0.8.0"]
26
+ end
27
+
28
+ task :prerelease => [:clobber, :check_manifest, :test]
29
+
30
+ # hoe/test and rake-compiler don't seem to play well together, so disable
31
+ # hoe/test's .gemtest touch file thingy for now
32
+ HOE.spec.files -= [".gemtest"]
33
+
34
+ include Hoe::Git
35
+
36
+ desc "Print the current changelog."
37
+ task "changelog" do
38
+ tag = ENV["FROM"] || git_tags.last
39
+ range = [tag, "HEAD"].compact.join ".."
40
+ cmd = "git log #{range} '--format=tformat:%B|||%aN|||%aE|||'"
41
+ now = Time.new.strftime "%Y-%m-%d"
42
+
43
+ changes = `#{cmd}`.split(/\|\|\|/).each_slice(3).map { |msg, author, email|
44
+ msg.split(/\n/).reject { |s| s.empty? }.first
45
+ }.flatten.compact
46
+
47
+ $changes = Hash.new { |h,k| h[k] = [] }
48
+
49
+ codes = {
50
+ "!" => :major,
51
+ "+" => :minor,
52
+ "*" => :minor,
53
+ "-" => :bug,
54
+ "?" => :unknown,
55
+ }
56
+
57
+ codes_re = Regexp.escape codes.keys.join
58
+
59
+ changes.each do |change|
60
+ if change =~ /^\s*([#{codes_re}])\s*(.*)/ then
61
+ code, line = codes[$1], $2
62
+ else
63
+ code, line = codes["?"], change.chomp
64
+ end
65
+
66
+ $changes[code] << line
67
+ end
68
+
69
+ puts "=== #{ENV['VERSION'] || 'NEXT'} / #{now}"
70
+ puts
71
+ changelog_section :major
72
+ changelog_section :minor
73
+ changelog_section :bug
74
+ changelog_section :unknown
75
+ puts
76
+ end
77
+
78
+ # generate extension code using Ragel (C and Java)
79
+ desc "Generate extension code (C and Java) using Ragel"
80
+ task :ragel
81
+
82
+ file 'ext/puma_http11/http11_parser.c' => ['ext/puma_http11/http11_parser.rl'] do |t|
83
+ begin
84
+ sh "ragel #{t.prerequisites.last} -C -G2 -I ext/puma_http11 -o #{t.name}"
85
+ rescue
86
+ fail "Could not build wrapper using Ragel (it failed or not installed?)"
87
+ end
88
+ end
89
+ task :ragel => ['ext/puma_http11/http11_parser.c']
90
+
91
+ file 'ext/puma_http11/org/jruby/puma/Http11Parser.java' => ['ext/puma_http11/http11_parser.java.rl'] do |t|
92
+ begin
93
+ sh "ragel #{t.prerequisites.last} -J -G2 -I ext/puma_http11 -o #{t.name}"
94
+ rescue
95
+ fail "Could not build wrapper using Ragel (it failed or not installed?)"
96
+ end
97
+ end
98
+ task :ragel => ['ext/puma_http11/org/jruby/puma/Http11Parser.java']
99
+
100
+ if !IS_JRUBY
101
+
102
+ # compile extensions using rake-compiler
103
+ # C (MRI, Rubinius)
104
+ Rake::ExtensionTask.new("puma_http11", HOE.spec) do |ext|
105
+ # place extension inside namespace
106
+ ext.lib_dir = "lib/puma"
107
+
108
+ ext.cross_compile = true
109
+ ext.cross_platform = ['i386-mswin32-60', 'i386-mingw32']
110
+ ext.cross_compiling do |spec|
111
+ # add fat-binary stub only when cross compiling
112
+ spec.files << "lib/puma/puma_http11.rb"
113
+ end
114
+
115
+ CLEAN.include "lib/puma/{1.8,1.9}"
116
+ CLEAN.include "lib/puma/puma_http11.rb"
117
+ end
118
+
119
+ else
120
+
121
+ # Java (JRuby)
122
+ Rake::JavaExtensionTask.new("puma_http11", HOE.spec) do |ext|
123
+ ext.lib_dir = "lib/puma"
124
+ end
125
+
126
+ end
127
+
128
+ # the following is a fat-binary stub that will be used when
129
+ # require 'puma/puma_http11' and will use either 1.8 or 1.9 version depending
130
+ # on RUBY_VERSION
131
+ file "lib/puma/puma_http11.rb" do |t|
132
+ File.open(t.name, "w") do |f|
133
+ f.puts "RUBY_VERSION =~ /(\d+.\d+)/"
134
+ f.puts 'require "puma/#{$1}/puma_http11"'
135
+ end
136
+ end
137
+
138
+ # tests require extension be compiled, but depend on the platform
139
+ if IS_JRUBY
140
+ task :test => [:java]
141
+ else
142
+ task :test => [:compile]
143
+ end
144
+
145
+ namespace :test do
146
+ desc "Run the integration tests"
147
+ task :integration do
148
+ sh "cd test/shell; sh run.sh"
149
+ end
150
+
151
+ desc "Run all tests"
152
+ if defined?(JRUBY_VERSION) and ENV['TRAVIS']
153
+ task :all => :test
154
+ else
155
+ task :all => [:test, "test:integration"]
156
+ end
157
+ end
158
+
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2011 Evan Phoenix
4
+ #
5
+
6
+ require 'puma/cli'
7
+
8
+ cli = Puma::CLI.new ARGV
9
+
10
+ cli.run
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Copyright (c) 2014 Evan Phoenix
4
+ #
5
+
6
+ require 'rubygems'
7
+
8
+ deps = ARGV.shift.split(",").each do |s|
9
+ name, ver = s.split(":",2)
10
+ gem name, ver
11
+ end
12
+
13
+ require 'puma/cli'
14
+
15
+ cli = Puma::CLI.new ARGV
16
+
17
+ cli.run
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'puma/control_cli'
4
+
5
+ cli = Puma::ControlCLI.new ARGV
6
+
7
+ begin
8
+ cli.run
9
+ rescue => e
10
+ STDERR.puts e.message
11
+ exit 1
12
+ end
File without changes
@@ -0,0 +1,80 @@
1
+ # Nginx configuration example file
2
+
3
+ This is a very common setup using an upstream. It was adapted from some Capistrano recipe I found on the Internet a while ago.
4
+
5
+ ```
6
+ upstream myapp {
7
+ server unix:///myapp/tmp/puma.sock;
8
+ }
9
+
10
+ server {
11
+ listen 80;
12
+ server_name myapp.com;
13
+
14
+ # ~2 seconds is often enough for most folks to parse HTML/CSS and
15
+ # retrieve needed images/icons/frames, connections are cheap in
16
+ # nginx so increasing this is generally safe...
17
+ keepalive_timeout 5;
18
+
19
+ # path for static files
20
+ root /myapp/public;
21
+ access_log /myapp/log/nginx.access.log;
22
+ error_log /myapp/log/nginx.error.log info;
23
+
24
+ # this rewrites all the requests to the maintenance.html
25
+ # page if it exists in the doc root. This is for capistrano's
26
+ # disable web task
27
+ if (-f $document_root/maintenance.html) {
28
+ rewrite ^(.*)$ /maintenance.html last;
29
+ break;
30
+ }
31
+
32
+ location / {
33
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
34
+ proxy_set_header Host $http_host;
35
+
36
+ # If the file exists as a static file serve it directly without
37
+ # running all the other rewite tests on it
38
+ if (-f $request_filename) {
39
+ break;
40
+ }
41
+
42
+ # check for index.html for directory index
43
+ # if its there on the filesystem then rewite
44
+ # the url to add /index.html to the end of it
45
+ # and then break to send it to the next config rules.
46
+ if (-f $request_filename/index.html) {
47
+ rewrite (.*) $1/index.html break;
48
+ }
49
+
50
+ # this is the meat of the rack page caching config
51
+ # it adds .html to the end of the url and then checks
52
+ # the filesystem for that file. If it exists, then we
53
+ # rewite the url to have explicit .html on the end
54
+ # and then send it on its way to the next config rule.
55
+ # if there is no file on the fs then it sets all the
56
+ # necessary headers and proxies to our upstream pumas
57
+ if (-f $request_filename.html) {
58
+ rewrite (.*) $1.html break;
59
+ }
60
+
61
+ if (!-f $request_filename) {
62
+ proxy_pass http://myapp;
63
+ break;
64
+ }
65
+ }
66
+
67
+ # Now this supposedly should work as it gets the filenames with querystrings that Rails provides.
68
+ # BUT there's a chance it could break the ajax calls.
69
+ location ~* \.(ico|css|gif|jpe?g|png|js)(\?[0-9]+)?$ {
70
+ expires max;
71
+ break;
72
+ }
73
+
74
+ # Error pages
75
+ # error_page 500 502 503 504 /500.html;
76
+ location = /500.html {
77
+ root /myapp/current/public;
78
+ }
79
+ }
80
+ ```
@@ -0,0 +1,42 @@
1
+ The [unix signal](http://en.wikipedia.org/wiki/Unix_signal) is a method of sending messages between [processes](http://en.wikipedia.org/wiki/Process_(computing)). When a signal is sent, the operating system interrupts the target process's normal flow of execution. There are standard signals that are used to stop a process but there are also custom signals that can be used for other purposes. This document is an attempt to list all supported signals that Puma will respond to. In general, signals need only be sent to the master process of a cluster.
2
+
3
+ ## Sending Signals
4
+
5
+ If you are new to signals it can be useful to see how they can be used. When a process is created in a *nix like operating system it will have a [PID - or process identifier](http://en.wikipedia.org/wiki/Process_identifier) that can be used to send signals to the process. For demonstration we will create an infinitely running process by tailing a file:
6
+
7
+ ```sh
8
+ $ echo "foo" >> my.log
9
+ $ irb
10
+ > pid = Process.spawn 'tail -f my.log'
11
+ ```
12
+
13
+ From here we can see that the tail process is running by using the `ps` command:
14
+
15
+ ```sh
16
+ $ ps aux | grep tail
17
+ schneems 87152 0.0 0.0 2432772 492 s032 S+ 12:46PM 0:00.00 tail -f my.log
18
+ ```
19
+
20
+ You can send a signal in Ruby using the [Process module](http://www.ruby-doc.org/core-2.1.1/Process.html#kill-method):
21
+
22
+ ```
23
+ $ irb
24
+ > puts pid
25
+ => 87152
26
+ Process.detach(pid) # http://ruby-doc.org/core-2.1.1/Process.html#method-c-detach
27
+ Process.kill("TERM", pid)
28
+ ```
29
+
30
+ Now you will see via `ps` that there is no more `tail` process. Sometimes when referring to signals the `SIG` prefix will be used for instance `SIGTERM` is equivalent to sending `TERM` via `Process.kill`.
31
+
32
+ ## Puma Signals
33
+
34
+ Puma cluster responds to these signals:
35
+
36
+ - `TTIN` increment the worker count by 1
37
+ - `TTOU` decrement the worker count by 1
38
+ - `TERM` send `TERM` to worker. Worker will attempt to finish then exit.
39
+ - `USR2` restart workers
40
+ - `USR1` restart workers in phases, a rolling restart.
41
+ - `INT` equivalent of sending Ctrl-C to cluster. Will attempt to finish then exit.
42
+ - `CHLD`
@@ -0,0 +1,17 @@
1
+ package puma;
2
+
3
+ import java.io.IOException;
4
+
5
+ import org.jruby.Ruby;
6
+ import org.jruby.runtime.load.BasicLibraryService;
7
+
8
+ import org.jruby.puma.Http11;
9
+ import org.jruby.puma.MiniSSL;
10
+
11
+ public class PumaHttp11Service implements BasicLibraryService {
12
+ public boolean basicLoad(final Ruby runtime) throws IOException {
13
+ Http11.createHttp11(runtime);
14
+ MiniSSL.createMiniSSL(runtime);
15
+ return true;
16
+ }
17
+ }
@@ -0,0 +1,15 @@
1
+ #ifndef ext_help_h
2
+ #define ext_help_h
3
+
4
+ #define RAISE_NOT_NULL(T) if(T == NULL) rb_raise(rb_eArgError, "%s", "NULL found for " # T " when shouldn't be.");
5
+ #define DATA_GET(from,type,name) Data_Get_Struct(from,type,name); RAISE_NOT_NULL(name);
6
+ #define REQUIRE_TYPE(V, T) if(TYPE(V) != T) rb_raise(rb_eTypeError, "%s", "Wrong argument type for " # V " required " # T);
7
+ #define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
8
+
9
+ #ifdef DEBUG
10
+ #define TRACE() fprintf(stderr, "> %s:%d:%s\n", __FILE__, __LINE__, __FUNCTION__)
11
+ #else
12
+ #define TRACE()
13
+ #endif
14
+
15
+ #endif
@@ -0,0 +1,8 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("puma_http11")
4
+
5
+ $defs.push "-Wno-deprecated-declarations"
6
+ $libs += " -lssl -lcrypto "
7
+
8
+ create_makefile("puma/puma_http11")