shotgun.1 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. .\" generated with Ronn/v0.7.3
  2. .\" http://github.com/rtomayko/ronn/tree/0.7.3
  3. .
  4. .TH "SHOTGUN" "1" "February 2011" "Shotgun 0.9" ""
  5. .
  6. .SH "NAME"
  7. \fBshotgun\fR \- reloading rack development server
  8. .
  9. .SH "SYNOPSIS"
  10. \fBshotgun\fR [\fIoptions\fR] [\fIrackup\-file\fR]
  11. .
  12. .SH "DESCRIPTION"
  13. \fBShotgun\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, \fBshotgun\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, \fBshotgun\fR uses the \fBconfig\.ru\fR file in the current working directory\.
  17. .
  18. .SH "OPTIONS"
  19. Shotgun 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\', shotgun 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 shotgun 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, shotgun 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\. 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\. 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 shotgun 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 "PRELOADING"
  83. It\'s possible to load support libraries and portions of the application in the shotgun 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 \fBshotgun\.rb\fR file\.
  84. .
  85. .P
  86. During start up, shotgun looks for a \fBshotgun\.rb\fR or \fBconfig/shotgun\.rb\fR file\. If either file is found, it\'s loaded into the shotgun master process\. Code at the top\-level of the \fBshotgun\.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:
  87. .
  88. .TP
  89. \fBafter_fork {\fR \fIstuff\fR \fB}\fR
  90. Run \fIstuff\fR in the shotgun 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\.
  91. .
  92. .TP
  93. \fBbefore_fork {\fR \fIstuff\fR \fB}\fR
  94. Run \fIstuff\fR in the shotgun master process on each request before forking the child worker process\. This is typically less useful than \fBafter_fork\fR, but provided for completeness\.
  95. .
  96. .P
  97. Example \fBconfig/shotgun\.rb\fR file from the main github\.com rails project:
  98. .
  99. .IP "" 4
  100. .
  101. .nf
  102. # make sure the load path includes RAILS_ROOT
  103. ENV[\'RAILS_ROOT\'] ||= File\.expand_path(\'\.\./\.\.\', __FILE__)
  104. $:\.unshift ENV[\'RAILS_ROOT\']
  105. # bring in the base rails environment and some libraries
  106. require \'config/environment\'
  107. require \'google\-charts\'
  108. require \'aws\-s3\'
  109. # disable Rails\'s built in class reloading
  110. Rails\.configuration\.cache_classes = true
  111. # reset database and redis connections in workers
  112. after_fork do
  113. ActiveRecord::Base\.establish_connection
  114. CHIMNEY\.client = $redis
  115. end
  116. .
  117. .fi
  118. .
  119. .IP "" 0
  120. .
  121. .SH "INSTALLING"
  122. Shotgun is distributed as a gem package at rubygems\.org:
  123. .
  124. .P
  125. \fIhttp://rubygems\.org/gems/shotgun\fR
  126. .
  127. .br
  128. \fBgem install shotgun\fR
  129. .
  130. .P
  131. The \fBrack\fR package is required\. The \fBmongrel\fR package is recommended\.
  132. .
  133. .SH "CONTRIBUTING"
  134. Fork and report issues at github\.com:
  135. .
  136. .P
  137. \fIhttp://github\.com/rtomayko/shotgun/\fR
  138. .
  139. .br
  140. \fBgit clone git://github\.com/rtomayko/shotgun\.git\fR
  141. .
  142. .SH "VERSION HISTORY"
  143. .
  144. .SS "Version 0\.9 (2011 February 24)"
  145. .
  146. .IP "\(bu" 4
  147. \fIhttp://github\.com/rtomayko/shotgun/compare/0\.8\.\.\.0\.9\fR
  148. .
  149. .IP "\(bu" 4
  150. Various Ruby 1\.9\.2 fixes\.
  151. .
  152. .IP "\(bu" 4
  153. Handle application class names consisting of multiple words\.
  154. .
  155. .IP "" 0
  156. .
  157. .SS "Version 0\.8 (2010 June 24)"
  158. .
  159. .IP "\(bu" 4
  160. \fIhttp://github\.com/rtomayko/shotgun/compare/0\.7\.\.\.0\.8\fR
  161. .
  162. .IP "\(bu" 4
  163. Preloading support\. The \fBshotgun\.rb\fR or \fBconfig/shotgun\.rb\fR file is loaded at startup and may require libraries and register callbacks for fork events\. See the section on \fIPRELOADING\fR\.
  164. .
  165. .IP "\(bu" 4
  166. Fix starting with the Thin handler (\fBshotgun \-s thin\fR)
  167. .
  168. .IP "\(bu" 4
  169. Actually include the shotgun(1) roff manual\.
  170. .
  171. .IP "" 0
  172. .
  173. .SS "Version 0\.7 (2010 June 22)"
  174. .
  175. .IP "\(bu" 4
  176. \fIhttp://github\.com/rtomayko/shotgun/compare/0\.6\.\.\.0\.7\fR
  177. .
  178. .IP "\(bu" 4
  179. Static files now served from the shotgun master process, making shotgun tolerable for apps with many/unbundled static assets\.
  180. .
  181. .IP "\(bu" 4
  182. Added \fB\-\-public\fR (\fB\-P\fR) for specifying a non\-standard root / public directory\.
  183. .
  184. .IP "\(bu" 4
  185. Response bodies are now streamed over the master < worker pipe instead of being marshalled\. Improves performance with large response bodies, and reduces shotgun master process RES usage\.
  186. .
  187. .IP "\(bu" 4
  188. GET /favicon\.ico requests are served an empty response by the shotgun master process\. Prevents the need to fork a worker process\.
  189. .
  190. .IP "\(bu" 4
  191. \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\.
  192. .
  193. .IP "\(bu" 4
  194. 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\.
  195. .
  196. .IP "" 0
  197. .
  198. .SS "Versions < 0\.7 (2009\-2010)"
  199. .
  200. .IP "\(bu" 4
  201. \fIhttp://github\.com/rtomayko/shotgun/commits/0\.6\fR
  202. .
  203. .IP "" 0
  204. .
  205. .SH "SEE ALSO"
  206. ruby(1)