shotgun.1.ronn 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. shotgun(1) -- reloading rack development server
  2. ===============================================
  3. ## SYNOPSIS
  4. `shotgun` [<options>] [<rackup-file>]
  5. ## DESCRIPTION
  6. **Shotgun** is a simple process-per-request [Rack][] server designed for use in
  7. development environments. Each time a request is received, `shotgun` forks,
  8. loads the <rackup-file>, processes a single request and exits. The result is
  9. application-wide reloading of all configuration, source files, and templates
  10. without the need for complex application-level reloading logic.
  11. When no <rackup-file> is given, `shotgun` uses the `config.ru` file in the
  12. current working directory.
  13. ## OPTIONS
  14. Shotgun runs at `http://127.0.0.1:9393` by default. The following options
  15. control server behavior:
  16. * `-E`, `--env`=<environment>:
  17. Sets the `RACK_ENV` environment variable to <environment> and selects
  18. the default set of utility middleware. When <environment> is 'development',
  19. shotgun inserts the `Rack::Lint` and `Rack::CommonLogger` middleware
  20. components; when <environment> is 'production' or 'deployed',
  21. `Rack::CommonLogger` is inserted; otherwise, no utility middleware are
  22. inserted.
  23. * `-P`, `--public`=<path>:
  24. Serve requests for static files that exist under <path> from the shotgun
  25. master process without forking a worker process. This option is
  26. automatically enabled when a `./public` directory is detected, but can be
  27. configured explicitly for non-conventional static file directory locations.
  28. Setting this option appropriately can severely improve overall page load
  29. times for applications with many static assets.
  30. * `-s`, `--server`=<mongrel>|<webrick>|<thin>|<other>:
  31. The Rack server handler implementation used to serve requests. Supported
  32. values include: `mongrel`, `webrick`, and `thin`. By default, shotgun first
  33. tries to use `mongrel` and falls back to `webrick` if mongrel is not
  34. available.
  35. * `-o`, `--host`=<addr>:
  36. The hostname or address of the interface the HTTP server should bind to.
  37. Default: `127.0.0.1`.
  38. * `-p`, `--port`=<port>:
  39. The port the HTTP server should bind to. Default: `9393`.
  40. * `-O`, `--browse`:
  41. Open browser at http://<host>:<port>/ immediately after the server
  42. is started.
  43. Ruby environment related options:
  44. * `-r`, `--require` <library>:
  45. Require <library> before loading the application and starting the server.
  46. This can be used to load a portion of the application code in the master
  47. process so it doesn't need to be loaded in the child. See [PRELOADING]][]
  48. for more information on this approach.
  49. * `-e`, `--eval` <command>:
  50. Evaluate arbitrary <command> within the shotgun master Ruby interpreter.
  51. <command> is evaluated as program arguments are parsed. Multiple `-e`
  52. arguments are allowed.
  53. * `-d`, `--debug`:
  54. Turns on debug mode. `$DEBUG` will be set `true`.
  55. * `-w`, `--warn`:
  56. Enable verbose mode without printing version message at the beginning. It
  57. sets the `$VERBOSE` variable to true.
  58. * `-I`, `--include` <path>:
  59. Add <path> to the Ruby load path (`$LOAD_PATH`). May be used more than once.
  60. Miscellaneous:
  61. * `-h`, `--help`:
  62. Show usage message and exit.
  63. * `--version`:
  64. Show the Rack version and exit.
  65. ## PRELOADING
  66. It's possible to load support libraries and portions of the application in the
  67. shotgun master process to reduce the amount of work that needs to be done for
  68. each request in worker processes. There's two ways of accomplishing this: either
  69. by specifying one or more `--require` (`-r`) arguments or through the use of a
  70. `shotgun.rb` file.
  71. During start up, shotgun looks for a `shotgun.rb` or `config/shotgun.rb` file.
  72. If either file is found, it's loaded into the shotgun master process. Code at
  73. the top-level of the `shotgun.rb` is run once on startup, so just require
  74. whatever you want to preload. It's also possible to register callbacks to run
  75. before each request in either the master or child worker process:
  76. * `after_fork {` <stuff> `}`:
  77. Run <stuff> in the shotgun child worker process immediately after forking.
  78. Any files or socket connections opened in the master process should be
  79. closed / re-established by an `after_fork` block.
  80. * `before_fork {` <stuff> `}`:
  81. Run <stuff> in the shotgun master process on each request before forking
  82. the child worker process. This is typically less useful than `after_fork`,
  83. but provided for completeness.
  84. Example `config/shotgun.rb` file from the main github.com rails project:
  85. # make sure the load path includes RAILS_ROOT
  86. ENV['RAILS_ROOT'] ||= File.expand_path('../..', __FILE__)
  87. $:.unshift ENV['RAILS_ROOT']
  88. # bring in the base rails environment and some libraries
  89. require 'config/environment'
  90. require 'google-charts'
  91. require 'aws-s3'
  92. # disable Rails's built in class reloading
  93. Rails.configuration.cache_classes = true
  94. # reset database and redis connections in workers
  95. after_fork do
  96. ActiveRecord::Base.establish_connection
  97. CHIMNEY.client = $redis
  98. end
  99. ## INSTALLING
  100. Shotgun is distributed as a gem package at rubygems.org:
  101. <http://rubygems.org/gems/shotgun><br>
  102. `gem install shotgun`
  103. The `rack` package is required. The `mongrel` package is recommended.
  104. ## CONTRIBUTING
  105. Fork and report issues at github.com:
  106. <http://github.com/rtomayko/shotgun/><br>
  107. `git clone git://github.com/rtomayko/shotgun.git`
  108. ## VERSION HISTORY
  109. ### Version 0.9 (2011 February 24)
  110. * <http://github.com/rtomayko/shotgun/compare/0.8...0.9>
  111. * Various Ruby 1.9.2 fixes.
  112. * Handle application class names consisting of multiple words.
  113. ### Version 0.8 (2010 June 24)
  114. * <http://github.com/rtomayko/shotgun/compare/0.7...0.8>
  115. * Preloading support. The `shotgun.rb` or `config/shotgun.rb` file is
  116. loaded at startup and may require libraries and register callbacks
  117. for fork events. See the section on [PRELOADING][].
  118. * Fix starting with the Thin handler (`shotgun -s thin`)
  119. * Actually include the shotgun(1) roff manual.
  120. ### Version 0.7 (2010 June 22)
  121. * <http://github.com/rtomayko/shotgun/compare/0.6...0.7>
  122. * Static files now served from the shotgun master process, making
  123. shotgun tolerable for apps with many/unbundled static assets.
  124. * Added `--public` (`-P`) for specifying a non-standard root / public
  125. directory.
  126. * Response bodies are now streamed over the master &lt; worker pipe
  127. instead of being marshalled. Improves performance with large response
  128. bodies, and reduces shotgun master process RES usage.
  129. * GET /favicon.ico requests are served an empty response by the shotgun
  130. master process. Prevents the need to fork a worker process.
  131. * `INT`, `TERM`, `QUIT` now properly trigger server shutdown. The second
  132. `INT`, `TERM`, `QUIT` causes the master process to exit hard.
  133. * Non `.ru` config files (e.g., sinatra app files) may now define command
  134. line options in the same way as `.ru` files: by including a
  135. `#\ -p 5555 ...` line.
  136. ### Versions &lt; 0.7 (2009-2010)
  137. * <http://github.com/rtomayko/shotgun/commits/0.6>
  138. ## SEE ALSO
  139. ruby(1)