passenger 2.1.3 → 2.2.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of passenger might be problematic. Click here for more details.

Files changed (398) hide show
  1. data/DEVELOPERS.TXT +2 -0
  2. data/INSTALL +3 -1
  3. data/LICENSE +19 -355
  4. data/NEWS +3 -0
  5. data/README +11 -4
  6. data/Rakefile +435 -236
  7. data/bin/passenger-config +20 -14
  8. data/bin/passenger-install-apache2-module +67 -201
  9. data/bin/passenger-install-nginx-module +477 -0
  10. data/bin/passenger-make-enterprisey +17 -12
  11. data/bin/passenger-memory-stats +33 -23
  12. data/bin/passenger-spawn-server +17 -12
  13. data/bin/passenger-status +18 -13
  14. data/bin/passenger-stress-test +17 -12
  15. data/doc/{Users guide.html → Users guide Apache.html } +79 -61
  16. data/doc/{Users guide.txt → Users guide Apache.txt } +43 -939
  17. data/doc/Users guide Nginx.html +2276 -0
  18. data/doc/Users guide Nginx.txt +776 -0
  19. data/doc/cxxapi/ApplicationPoolServer_8h-source.html +9 -4
  20. data/doc/cxxapi/ApplicationPool_8h-source.html +9 -4
  21. data/doc/cxxapi/Application_8h-source.html +26 -21
  22. data/doc/cxxapi/Bucket_8h-source.html +54 -44
  23. data/doc/cxxapi/CachedFileStat_8h-source.html +9 -4
  24. data/doc/cxxapi/Configuration_8h-source.html +357 -339
  25. data/doc/cxxapi/DirectoryMapper_8h-source.html +294 -280
  26. data/doc/cxxapi/DummySpawnManager_8h-source.html +9 -4
  27. data/doc/cxxapi/Exceptions_8h-source.html +9 -4
  28. data/doc/cxxapi/FileChecker_8h-source.html +9 -4
  29. data/doc/cxxapi/Hooks_8h-source.html +50 -40
  30. data/doc/cxxapi/Logging_8h-source.html +9 -4
  31. data/doc/cxxapi/MessageChannel_8h-source.html +20 -15
  32. data/doc/cxxapi/PoolOptions_8h-source.html +10 -5
  33. data/doc/cxxapi/SpawnManager_8h-source.html +9 -4
  34. data/doc/cxxapi/StandardApplicationPool_8h-source.html +10 -5
  35. data/doc/cxxapi/SystemTime_8h-source.html +9 -4
  36. data/doc/cxxapi/Utils_8h-source.html +242 -214
  37. data/doc/cxxapi/annotated.html +4 -28
  38. data/doc/cxxapi/classClient-members.html +4 -4
  39. data/doc/cxxapi/classClient.html +14 -11
  40. data/doc/cxxapi/classHooks-members.html +4 -5
  41. data/doc/cxxapi/classHooks.html +26 -24
  42. data/doc/cxxapi/classPassenger_1_1Application-members.html +4 -4
  43. data/doc/cxxapi/classPassenger_1_1Application.html +40 -37
  44. data/doc/cxxapi/classPassenger_1_1ApplicationPool-members.html +4 -4
  45. data/doc/cxxapi/classPassenger_1_1ApplicationPool.html +95 -92
  46. data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer-members.html +4 -4
  47. data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer.html +26 -23
  48. data/doc/cxxapi/classPassenger_1_1ApplicationPool__inherit__graph.map +1 -1
  49. data/doc/cxxapi/classPassenger_1_1ApplicationPool__inherit__graph.md5 +1 -1
  50. data/doc/cxxapi/classPassenger_1_1ApplicationPool__inherit__graph.png +0 -0
  51. data/doc/cxxapi/classPassenger_1_1Application_1_1Session-members.html +17 -17
  52. data/doc/cxxapi/classPassenger_1_1Application_1_1Session.html +139 -136
  53. data/doc/cxxapi/classPassenger_1_1BufferedUpload-members.html +4 -4
  54. data/doc/cxxapi/classPassenger_1_1BufferedUpload.html +13 -10
  55. data/doc/cxxapi/classPassenger_1_1BusyException-members.html +4 -4
  56. data/doc/cxxapi/classPassenger_1_1BusyException.html +11 -8
  57. data/doc/cxxapi/classPassenger_1_1ConfigurationException-members.html +4 -4
  58. data/doc/cxxapi/classPassenger_1_1ConfigurationException.html +11 -8
  59. data/doc/cxxapi/classPassenger_1_1DirectoryMapper-members.html +4 -5
  60. data/doc/cxxapi/classPassenger_1_1DirectoryMapper.html +45 -43
  61. data/doc/cxxapi/classPassenger_1_1DummySpawnManager-members.html +4 -4
  62. data/doc/cxxapi/classPassenger_1_1DummySpawnManager.html +13 -10
  63. data/doc/cxxapi/classPassenger_1_1FileChecker-members.html +4 -4
  64. data/doc/cxxapi/classPassenger_1_1FileChecker.html +22 -19
  65. data/doc/cxxapi/classPassenger_1_1FileNotFoundException-members.html +4 -4
  66. data/doc/cxxapi/classPassenger_1_1FileNotFoundException.html +12 -9
  67. data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.map +1 -1
  68. data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.md5 +1 -1
  69. data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.png +0 -0
  70. data/doc/cxxapi/classPassenger_1_1FileSystemException-members.html +4 -4
  71. data/doc/cxxapi/classPassenger_1_1FileSystemException.html +14 -11
  72. data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.map +1 -1
  73. data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.md5 +1 -1
  74. data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.png +0 -0
  75. data/doc/cxxapi/classPassenger_1_1IOException-members.html +4 -4
  76. data/doc/cxxapi/classPassenger_1_1IOException.html +12 -9
  77. data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.map +1 -1
  78. data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.md5 +1 -1
  79. data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.png +0 -0
  80. data/doc/cxxapi/classPassenger_1_1MessageChannel-members.html +4 -4
  81. data/doc/cxxapi/classPassenger_1_1MessageChannel.html +228 -225
  82. data/doc/cxxapi/classPassenger_1_1RuntimeException-members.html +4 -4
  83. data/doc/cxxapi/classPassenger_1_1RuntimeException.html +11 -8
  84. data/doc/cxxapi/classPassenger_1_1SpawnException-members.html +4 -4
  85. data/doc/cxxapi/classPassenger_1_1SpawnException.html +14 -11
  86. data/doc/cxxapi/classPassenger_1_1SpawnManager-members.html +4 -4
  87. data/doc/cxxapi/classPassenger_1_1SpawnManager.html +50 -47
  88. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool-members.html +4 -4
  89. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool.html +73 -70
  90. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool__inherit__graph.map +1 -1
  91. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool__inherit__graph.md5 +1 -1
  92. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool__inherit__graph.png +0 -0
  93. data/doc/cxxapi/classPassenger_1_1SystemException-members.html +4 -4
  94. data/doc/cxxapi/classPassenger_1_1SystemException.html +17 -14
  95. data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.map +1 -1
  96. data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.md5 +1 -1
  97. data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.png +0 -0
  98. data/doc/cxxapi/classPassenger_1_1SystemTime-members.html +4 -4
  99. data/doc/cxxapi/classPassenger_1_1SystemTime.html +14 -11
  100. data/doc/cxxapi/classes.html +35 -0
  101. data/doc/cxxapi/definitions_8h-source.html +9 -4
  102. data/doc/cxxapi/doxygen.css +311 -303
  103. data/doc/cxxapi/files.html +9 -18
  104. data/doc/cxxapi/functions.html +5 -224
  105. data/doc/cxxapi/functions_func.html +5 -185
  106. data/doc/cxxapi/functions_type.html +4 -4
  107. data/doc/cxxapi/functions_vars.html +4 -4
  108. data/doc/cxxapi/graph_legend.dot +19 -19
  109. data/doc/cxxapi/graph_legend.html +5 -5
  110. data/doc/cxxapi/graph_legend.png +0 -0
  111. data/doc/cxxapi/group__Configuration.html +11 -13
  112. data/doc/cxxapi/group__Configuration.png +0 -0
  113. data/doc/cxxapi/group__Core.html +10 -12
  114. data/doc/cxxapi/group__Core.png +0 -0
  115. data/doc/cxxapi/group__Exceptions.html +5 -7
  116. data/doc/cxxapi/group__Hooks.html +5 -7
  117. data/doc/cxxapi/group__Hooks.png +0 -0
  118. data/doc/cxxapi/group__Support.html +5 -624
  119. data/doc/cxxapi/hierarchy.html +6 -6
  120. data/doc/cxxapi/inherit__graph__0.map +1 -1
  121. data/doc/cxxapi/inherit__graph__0.md5 +1 -1
  122. data/doc/cxxapi/inherit__graph__0.png +0 -0
  123. data/doc/cxxapi/inherit__graph__1.map +1 -1
  124. data/doc/cxxapi/inherit__graph__1.md5 +1 -1
  125. data/doc/cxxapi/inherit__graph__1.png +0 -0
  126. data/doc/cxxapi/inherit__graph__10.map +1 -1
  127. data/doc/cxxapi/inherit__graph__10.md5 +1 -1
  128. data/doc/cxxapi/inherit__graph__10.png +0 -0
  129. data/doc/cxxapi/inherit__graph__11.map +1 -1
  130. data/doc/cxxapi/inherit__graph__11.md5 +1 -1
  131. data/doc/cxxapi/inherit__graph__11.png +0 -0
  132. data/doc/cxxapi/inherit__graph__12.map +1 -1
  133. data/doc/cxxapi/inherit__graph__12.md5 +1 -1
  134. data/doc/cxxapi/inherit__graph__12.png +0 -0
  135. data/doc/cxxapi/inherit__graph__13.map +1 -2
  136. data/doc/cxxapi/inherit__graph__13.md5 +1 -1
  137. data/doc/cxxapi/inherit__graph__13.png +0 -0
  138. data/doc/cxxapi/inherit__graph__14.map +2 -1
  139. data/doc/cxxapi/inherit__graph__14.md5 +1 -1
  140. data/doc/cxxapi/inherit__graph__14.png +0 -0
  141. data/doc/cxxapi/inherit__graph__15.map +1 -1
  142. data/doc/cxxapi/inherit__graph__15.md5 +1 -1
  143. data/doc/cxxapi/inherit__graph__15.png +0 -0
  144. data/doc/cxxapi/inherit__graph__16.map +1 -1
  145. data/doc/cxxapi/inherit__graph__16.md5 +1 -1
  146. data/doc/cxxapi/inherit__graph__16.png +0 -0
  147. data/doc/cxxapi/inherit__graph__17.map +1 -1
  148. data/doc/cxxapi/inherit__graph__17.md5 +1 -1
  149. data/doc/cxxapi/inherit__graph__17.png +0 -0
  150. data/doc/cxxapi/inherit__graph__18.map +1 -1
  151. data/doc/cxxapi/inherit__graph__18.md5 +1 -1
  152. data/doc/cxxapi/inherit__graph__18.png +0 -0
  153. data/doc/cxxapi/inherit__graph__19.map +1 -1
  154. data/doc/cxxapi/inherit__graph__19.md5 +1 -1
  155. data/doc/cxxapi/inherit__graph__19.png +0 -0
  156. data/doc/cxxapi/inherit__graph__2.map +1 -1
  157. data/doc/cxxapi/inherit__graph__2.md5 +1 -1
  158. data/doc/cxxapi/inherit__graph__2.png +0 -0
  159. data/doc/cxxapi/inherit__graph__20.map +2 -2
  160. data/doc/cxxapi/inherit__graph__20.md5 +1 -1
  161. data/doc/cxxapi/inherit__graph__20.png +0 -0
  162. data/doc/cxxapi/inherit__graph__21.map +1 -1
  163. data/doc/cxxapi/inherit__graph__21.md5 +1 -1
  164. data/doc/cxxapi/inherit__graph__21.png +0 -0
  165. data/doc/cxxapi/inherit__graph__3.map +1 -1
  166. data/doc/cxxapi/inherit__graph__3.md5 +1 -1
  167. data/doc/cxxapi/inherit__graph__3.png +0 -0
  168. data/doc/cxxapi/inherit__graph__4.map +1 -1
  169. data/doc/cxxapi/inherit__graph__4.md5 +1 -1
  170. data/doc/cxxapi/inherit__graph__4.png +0 -0
  171. data/doc/cxxapi/inherit__graph__5.map +1 -2
  172. data/doc/cxxapi/inherit__graph__5.md5 +1 -1
  173. data/doc/cxxapi/inherit__graph__5.png +0 -0
  174. data/doc/cxxapi/inherit__graph__6.map +2 -1
  175. data/doc/cxxapi/inherit__graph__6.md5 +1 -1
  176. data/doc/cxxapi/inherit__graph__6.png +0 -0
  177. data/doc/cxxapi/inherit__graph__7.map +1 -1
  178. data/doc/cxxapi/inherit__graph__7.md5 +1 -1
  179. data/doc/cxxapi/inherit__graph__7.png +0 -0
  180. data/doc/cxxapi/inherit__graph__8.map +1 -1
  181. data/doc/cxxapi/inherit__graph__8.md5 +1 -1
  182. data/doc/cxxapi/inherit__graph__8.png +0 -0
  183. data/doc/cxxapi/inherit__graph__9.map +1 -1
  184. data/doc/cxxapi/inherit__graph__9.md5 +1 -1
  185. data/doc/cxxapi/inherit__graph__9.png +0 -0
  186. data/doc/cxxapi/inherits.html +41 -41
  187. data/doc/cxxapi/main.html +4 -4
  188. data/doc/cxxapi/modules.html +4 -5
  189. data/doc/cxxapi/structPassenger_1_1AnythingToString-members.html +4 -4
  190. data/doc/cxxapi/structPassenger_1_1AnythingToString.html +13 -10
  191. data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4-members.html +5 -5
  192. data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4.html +16 -13
  193. data/doc/cxxapi/structPassenger_1_1PoolOptions-members.html +4 -4
  194. data/doc/cxxapi/structPassenger_1_1PoolOptions.html +63 -60
  195. data/doc/cxxapi/tabs.css +5 -2
  196. data/doc/cxxapi/tree.html +7 -81
  197. data/doc/rdoc/classes/ConditionVariable.html +59 -59
  198. data/doc/rdoc/classes/Exception.html +11 -11
  199. data/doc/rdoc/classes/GC.html +4 -4
  200. data/doc/rdoc/classes/IO.html +14 -14
  201. data/doc/rdoc/classes/PhusionPassenger.html +75 -20
  202. data/doc/rdoc/classes/PhusionPassenger/AbstractInstaller.html +153 -0
  203. data/doc/rdoc/classes/PhusionPassenger/AbstractRequestHandler.html +125 -130
  204. data/doc/rdoc/classes/PhusionPassenger/AbstractServer.html +236 -236
  205. data/doc/rdoc/classes/PhusionPassenger/AbstractServerCollection.html +213 -213
  206. data/doc/rdoc/classes/PhusionPassenger/AdminTools.html +28 -28
  207. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ControlProcess.html +91 -75
  208. data/doc/rdoc/classes/PhusionPassenger/AppInitError.html +10 -10
  209. data/doc/rdoc/classes/PhusionPassenger/Application.html +64 -64
  210. data/doc/rdoc/classes/PhusionPassenger/ConsoleTextTemplate.html +34 -34
  211. data/doc/rdoc/classes/PhusionPassenger/FrameworkInitError.html +13 -13
  212. data/doc/rdoc/classes/PhusionPassenger/HTMLTemplate.html +30 -30
  213. data/doc/rdoc/classes/PhusionPassenger/InitializationError.html +10 -10
  214. data/doc/rdoc/classes/PhusionPassenger/MessageChannel.html +136 -136
  215. data/doc/rdoc/classes/PhusionPassenger/NativeSupport.html +24 -24
  216. data/doc/rdoc/classes/PhusionPassenger/Rack/ApplicationSpawner.html +42 -42
  217. data/doc/rdoc/classes/PhusionPassenger/Rack/RequestHandler.html +55 -53
  218. data/doc/rdoc/classes/PhusionPassenger/Railz.html +1 -1
  219. data/doc/rdoc/classes/PhusionPassenger/Railz/ApplicationSpawner.html +25 -30
  220. data/doc/rdoc/classes/PhusionPassenger/Railz/CGIFixed.html +23 -23
  221. data/doc/rdoc/classes/PhusionPassenger/Railz/FrameworkSpawner.html +116 -117
  222. data/doc/rdoc/classes/PhusionPassenger/Railz/RequestHandler.html +22 -22
  223. data/doc/rdoc/classes/PhusionPassenger/SpawnManager.html +118 -124
  224. data/doc/rdoc/classes/PhusionPassenger/UnknownError.html +10 -10
  225. data/doc/rdoc/classes/PhusionPassenger/Utils.html +354 -354
  226. data/doc/rdoc/classes/PhusionPassenger/VersionNotFound.html +9 -9
  227. data/doc/rdoc/classes/PhusionPassenger/WSGI/ApplicationSpawner.html +37 -37
  228. data/doc/rdoc/classes/PlatformInfo.html +282 -261
  229. data/doc/rdoc/classes/RakeExtensions.html +7 -7
  230. data/doc/rdoc/classes/Signal.html +26 -26
  231. data/doc/rdoc/created.rid +1 -1
  232. data/doc/rdoc/files/DEVELOPERS_TXT.html +6 -1
  233. data/doc/rdoc/files/README.html +15 -6
  234. data/doc/rdoc/files/ext/phusion_passenger/native_support_c.html +1 -1
  235. data/doc/rdoc/files/lib/phusion_passenger/abstract_installer_rb.html +129 -0
  236. data/doc/rdoc/files/lib/phusion_passenger/abstract_request_handler_rb.html +20 -13
  237. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_collection_rb.html +19 -13
  238. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_rb.html +19 -13
  239. data/doc/rdoc/files/lib/phusion_passenger/admin_tools/control_process_rb.html +31 -1
  240. data/doc/rdoc/files/lib/phusion_passenger/admin_tools_rb.html +31 -1
  241. data/doc/rdoc/files/lib/phusion_passenger/application_rb.html +19 -13
  242. data/doc/rdoc/files/lib/phusion_passenger/console_text_template_rb.html +19 -13
  243. data/doc/rdoc/files/lib/phusion_passenger/constants_rb.html +21 -12
  244. data/doc/rdoc/files/lib/phusion_passenger/dependencies_rb.html +19 -13
  245. data/doc/rdoc/files/lib/phusion_passenger/events_rb.html +19 -13
  246. data/doc/rdoc/files/lib/phusion_passenger/exceptions_rb.html +19 -13
  247. data/doc/rdoc/files/lib/phusion_passenger/html_template_rb.html +19 -13
  248. data/doc/rdoc/files/lib/phusion_passenger/message_channel_rb.html +19 -13
  249. data/doc/rdoc/files/lib/phusion_passenger/packaging_rb.html +122 -0
  250. data/doc/rdoc/files/lib/phusion_passenger/platform_info_rb.html +19 -13
  251. data/doc/rdoc/files/lib/phusion_passenger/rack/application_spawner_rb.html +22 -12
  252. data/doc/rdoc/files/lib/phusion_passenger/rack/request_handler_rb.html +21 -12
  253. data/doc/rdoc/files/lib/phusion_passenger/railz/application_spawner_rb.html +19 -13
  254. data/doc/rdoc/files/lib/phusion_passenger/railz/cgi_fixed_rb.html +1 -1
  255. data/doc/rdoc/files/lib/phusion_passenger/railz/framework_spawner_rb.html +19 -13
  256. data/doc/rdoc/files/lib/phusion_passenger/railz/request_handler_rb.html +21 -12
  257. data/doc/rdoc/files/lib/phusion_passenger/simple_benchmarking_rb.html +19 -13
  258. data/doc/rdoc/files/lib/phusion_passenger/spawn_manager_rb.html +19 -13
  259. data/doc/rdoc/files/lib/phusion_passenger/utils_rb.html +27 -21
  260. data/doc/rdoc/files/lib/phusion_passenger/wsgi/application_spawner_rb.html +21 -12
  261. data/doc/rdoc/files/misc/rake/extensions_rb.html +21 -12
  262. data/doc/rdoc/fr_class_index.html +1 -0
  263. data/doc/rdoc/fr_file_index.html +2 -0
  264. data/doc/rdoc/fr_method_index.html +116 -112
  265. data/doc/users_guide_snippets/analysis_and_system_maintenance_tools.txt +144 -0
  266. data/doc/users_guide_snippets/appendix_a_about.txt +13 -0
  267. data/doc/users_guide_snippets/appendix_b_terminology.txt +63 -0
  268. data/doc/users_guide_snippets/appendix_c_spawning_methods.txt +304 -0
  269. data/doc/users_guide_snippets/global_queueing_explained.txt +78 -0
  270. data/doc/users_guide_snippets/rackup_specifications.txt +75 -0
  271. data/doc/users_guide_snippets/rails_spawn_method.txt +48 -0
  272. data/doc/users_guide_snippets/tips.txt +173 -0
  273. data/ext/apache2/Bucket.cpp +17 -12
  274. data/ext/apache2/Bucket.h +17 -12
  275. data/ext/apache2/Configuration.cpp +17 -12
  276. data/ext/apache2/Configuration.h +27 -14
  277. data/ext/apache2/DirectoryMapper.h +21 -12
  278. data/ext/apache2/Hooks.cpp +67 -21
  279. data/ext/apache2/Hooks.h +17 -12
  280. data/ext/apache2/mod_passenger.c +17 -12
  281. data/ext/{apache2 → common}/Application.h +19 -14
  282. data/ext/{apache2 → common}/ApplicationPool.h +17 -12
  283. data/ext/{apache2 → common}/ApplicationPoolServer.h +18 -72
  284. data/ext/{apache2 → common}/ApplicationPoolServerExecutable.cpp +45 -104
  285. data/ext/common/ApplicationPoolStatusReporter.h +212 -0
  286. data/ext/{apache2 → common}/CachedFileStat.cpp +17 -12
  287. data/ext/{apache2 → common}/CachedFileStat.h +17 -12
  288. data/ext/{apache2 → common}/DummySpawnManager.h +17 -12
  289. data/ext/{apache2 → common}/Exceptions.h +17 -12
  290. data/ext/{apache2 → common}/FileChecker.h +17 -12
  291. data/ext/common/Logging.cpp +65 -0
  292. data/ext/{apache2 → common}/Logging.h +17 -12
  293. data/ext/{apache2 → common}/MessageChannel.h +17 -12
  294. data/ext/{apache2 → common}/PoolOptions.h +17 -12
  295. data/ext/{apache2 → common}/SpawnManager.h +17 -12
  296. data/ext/{apache2 → common}/StandardApplicationPool.h +17 -12
  297. data/ext/common/StaticString.h +147 -0
  298. data/ext/common/SystemTime.cpp +33 -0
  299. data/ext/{apache2 → common}/SystemTime.h +17 -12
  300. data/ext/{apache2 → common}/Utils.cpp +69 -12
  301. data/ext/{apache2 → common}/Utils.h +41 -12
  302. data/ext/nginx/Configuration.c +1091 -0
  303. data/ext/nginx/Configuration.h +71 -0
  304. data/ext/nginx/ContentHandler.c +1154 -0
  305. data/ext/nginx/ContentHandler.h +64 -0
  306. data/ext/nginx/HelperServer.cpp +857 -0
  307. data/ext/nginx/HttpStatusExtractor.h +161 -0
  308. data/ext/nginx/ScgiRequestParser.h +317 -0
  309. data/ext/nginx/StaticContentHandler.c +222 -0
  310. data/ext/nginx/StaticContentHandler.h +37 -0
  311. data/ext/nginx/config +41 -0
  312. data/ext/nginx/ngx_http_passenger_module.c +572 -0
  313. data/ext/nginx/ngx_http_passenger_module.h +72 -0
  314. data/ext/oxt/backtrace.cpp +8 -1
  315. data/ext/oxt/system_calls.cpp +40 -0
  316. data/ext/oxt/system_calls.hpp +14 -7
  317. data/ext/phusion_passenger/extconf.rb +17 -12
  318. data/ext/phusion_passenger/native_support.c +19 -12
  319. data/lib/phusion_passenger/abstract_installer.rb +196 -0
  320. data/lib/phusion_passenger/abstract_request_handler.rb +19 -24
  321. data/lib/phusion_passenger/abstract_server.rb +17 -12
  322. data/lib/phusion_passenger/abstract_server_collection.rb +17 -12
  323. data/lib/phusion_passenger/admin_tools.rb +23 -0
  324. data/lib/phusion_passenger/admin_tools/control_process.rb +39 -13
  325. data/lib/phusion_passenger/application.rb +17 -12
  326. data/lib/phusion_passenger/console_text_template.rb +17 -12
  327. data/lib/phusion_passenger/constants.rb +22 -11
  328. data/lib/phusion_passenger/dependencies.rb +47 -12
  329. data/lib/phusion_passenger/events.rb +17 -12
  330. data/lib/phusion_passenger/exceptions.rb +17 -12
  331. data/lib/phusion_passenger/html_template.rb +17 -12
  332. data/lib/phusion_passenger/message_channel.rb +17 -12
  333. data/lib/phusion_passenger/packaging.rb +39 -0
  334. data/lib/phusion_passenger/platform_info.rb +48 -22
  335. data/lib/phusion_passenger/rack/application_spawner.rb +22 -11
  336. data/lib/phusion_passenger/rack/request_handler.rb +21 -12
  337. data/lib/phusion_passenger/railz/application_spawner.rb +23 -23
  338. data/lib/phusion_passenger/railz/framework_spawner.rb +18 -14
  339. data/lib/phusion_passenger/railz/request_handler.rb +18 -11
  340. data/lib/phusion_passenger/simple_benchmarking.rb +17 -12
  341. data/lib/phusion_passenger/spawn_manager.rb +17 -20
  342. data/lib/phusion_passenger/templates/{apache_must_be_compiled_with_compatible_mpm.txt.erb → apache2/apache_must_be_compiled_with_compatible_mpm.txt.erb} +0 -0
  343. data/lib/phusion_passenger/templates/{apache2_config_snippets.txt.erb → apache2/config_snippets.txt.erb} +0 -0
  344. data/lib/phusion_passenger/templates/{deployment_example.txt.erb → apache2/deployment_example.txt.erb} +0 -0
  345. data/lib/phusion_passenger/templates/{no_write_permission_to_passenger_root.txt.erb → apache2/no_write_permission_to_passenger_root.txt.erb} +0 -0
  346. data/lib/phusion_passenger/templates/{possible_solutions_for_compilation_and_installation_problems.txt.erb → apache2/possible_solutions_for_compilation_and_installation_problems.txt.erb} +0 -0
  347. data/lib/phusion_passenger/templates/{run_installer_as_root.txt.erb → apache2/run_installer_as_root.txt.erb} +0 -0
  348. data/lib/phusion_passenger/templates/{welcome.txt.erb → apache2/welcome.txt.erb} +0 -0
  349. data/lib/phusion_passenger/templates/nginx/ask_for_extra_configure_flags.txt.erb +8 -0
  350. data/lib/phusion_passenger/templates/nginx/cannot_write_to_dir.txt.erb +11 -0
  351. data/lib/phusion_passenger/templates/nginx/config_snippets.txt.erb +17 -0
  352. data/lib/phusion_passenger/templates/nginx/config_snippets_inserted.txt.erb +20 -0
  353. data/lib/phusion_passenger/templates/nginx/confirm_extra_configure_flags.txt.erb +5 -0
  354. data/lib/phusion_passenger/templates/nginx/deployment_example.txt.erb +22 -0
  355. data/lib/phusion_passenger/templates/nginx/pcre_could_not_be_downloaded.txt.erb +11 -0
  356. data/lib/phusion_passenger/templates/nginx/pcre_could_not_be_extracted.txt.erb +11 -0
  357. data/lib/phusion_passenger/templates/nginx/possible_solutions_for_compilation_and_installation_problems.txt.erb +11 -0
  358. data/lib/phusion_passenger/templates/nginx/possible_solutions_for_download_and_extraction_problems.txt.erb +20 -0
  359. data/lib/phusion_passenger/templates/nginx/query_download_and_install.txt.erb +21 -0
  360. data/lib/phusion_passenger/templates/nginx/run_installer_as_root.txt.erb +8 -0
  361. data/lib/phusion_passenger/templates/nginx/welcome.txt.erb +15 -0
  362. data/lib/phusion_passenger/utils.rb +20 -15
  363. data/lib/phusion_passenger/wsgi/application_spawner.rb +18 -11
  364. data/lib/phusion_passenger/wsgi/request_handler.py +23 -0
  365. data/misc/copy_boost_headers.rb +23 -0
  366. data/misc/find_owner_pipe_leaks.rb +18 -11
  367. data/misc/rake/cplusplus.rb +18 -11
  368. data/misc/rake/extensions.rb +21 -14
  369. data/misc/render_error_pages.rb +18 -11
  370. data/test/ApplicationPoolServerTest.cpp +1 -3
  371. data/test/ApplicationPoolServer_ApplicationPoolTest.cpp +1 -1
  372. data/test/CxxTestMain.cpp +19 -3
  373. data/test/HttpStatusExtractorTest.cpp +181 -0
  374. data/test/ScgiRequestParserTest.cpp +337 -0
  375. data/test/StaticStringTest.cpp +51 -0
  376. data/test/UtilsTest.cpp +32 -0
  377. data/test/config.yml.example +5 -0
  378. data/test/{integration_tests.rb → integration_tests/apache2_tests.rb} +7 -299
  379. data/test/integration_tests/hello_world_rack_spec.rb +36 -0
  380. data/test/integration_tests/hello_world_wsgi_spec.rb +41 -0
  381. data/test/integration_tests/mycook_spec.rb +192 -0
  382. data/test/integration_tests/nginx_tests.rb +98 -0
  383. data/test/ruby/rack/application_spawner_spec.rb +40 -0
  384. data/test/stub/nginx/koi-utf +109 -0
  385. data/test/stub/nginx/koi-win +103 -0
  386. data/test/stub/nginx/mime.types +70 -0
  387. data/test/stub/nginx/nginx.conf.erb +57 -0
  388. data/test/stub/nginx/win-utf +126 -0
  389. data/test/stub/rails_apps/mycook/app/controllers/uploads_controller.rb +4 -0
  390. data/test/stub/rails_apps/mycook/config/routes.rb +1 -1
  391. data/test/stub/wsgi/passenger_wsgi.pyc +0 -0
  392. data/test/support/Support.h +40 -0
  393. data/test/support/nginx_controller.rb +98 -0
  394. data/test/support/test_helper.rb +79 -0
  395. metadata +1091 -1028
  396. data/benchmark/DummyRequestHandler.cpp +0 -101
  397. data/ext/apache2/Logging.cpp +0 -60
  398. data/ext/apache2/SystemTime.cpp +0 -28
@@ -0,0 +1,2276 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2
+ "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4
+ <head>
5
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6
+ <meta name="generator" content="AsciiDoc 8.4.2" />
7
+ <title>Phusion Passenger users guide, Nginx version</title>
8
+ <style type="text/css">
9
+ /* Debug borders */
10
+ p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11
+ /*
12
+ border: 1px solid red;
13
+ */
14
+ }
15
+
16
+ body {
17
+ margin: 1em 5% 1em 5%;
18
+ }
19
+
20
+ a {
21
+ color: blue;
22
+ text-decoration: underline;
23
+ }
24
+ a:visited {
25
+ color: fuchsia;
26
+ }
27
+
28
+ em {
29
+ font-style: italic;
30
+ color: navy;
31
+ }
32
+
33
+ strong {
34
+ font-weight: bold;
35
+ color: #083194;
36
+ }
37
+
38
+ tt {
39
+ color: navy;
40
+ }
41
+
42
+ h1, h2, h3, h4, h5, h6 {
43
+ color: #527bbd;
44
+ font-family: sans-serif;
45
+ margin-top: 1.2em;
46
+ margin-bottom: 0.5em;
47
+ line-height: 1.3;
48
+ }
49
+
50
+ h1, h2, h3 {
51
+ border-bottom: 2px solid silver;
52
+ }
53
+ h2 {
54
+ padding-top: 0.5em;
55
+ }
56
+ h3 {
57
+ float: left;
58
+ }
59
+ h3 + * {
60
+ clear: left;
61
+ }
62
+
63
+ div.sectionbody {
64
+ font-family: serif;
65
+ margin-left: 0;
66
+ }
67
+
68
+ hr {
69
+ border: 1px solid silver;
70
+ }
71
+
72
+ p {
73
+ margin-top: 0.5em;
74
+ margin-bottom: 0.5em;
75
+ }
76
+
77
+ ul, ol, li > p {
78
+ margin-top: 0;
79
+ }
80
+
81
+ pre {
82
+ padding: 0;
83
+ margin: 0;
84
+ }
85
+
86
+ span#author {
87
+ color: #527bbd;
88
+ font-family: sans-serif;
89
+ font-weight: bold;
90
+ font-size: 1.1em;
91
+ }
92
+ span#email {
93
+ }
94
+ span#revision {
95
+ font-family: sans-serif;
96
+ }
97
+
98
+ div#footer {
99
+ font-family: sans-serif;
100
+ font-size: small;
101
+ border-top: 2px solid silver;
102
+ padding-top: 0.5em;
103
+ margin-top: 4.0em;
104
+ }
105
+ div#footer-text {
106
+ float: left;
107
+ padding-bottom: 0.5em;
108
+ }
109
+ div#footer-badges {
110
+ float: right;
111
+ padding-bottom: 0.5em;
112
+ }
113
+
114
+ div#preamble {
115
+ margin-top: 1.5em;
116
+ margin-bottom: 1.5em;
117
+ }
118
+ div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119
+ div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120
+ div.admonitionblock {
121
+ margin-top: 1.5em;
122
+ margin-bottom: 1.5em;
123
+ }
124
+ div.admonitionblock {
125
+ margin-top: 2.5em;
126
+ margin-bottom: 2.5em;
127
+ }
128
+
129
+ div.content { /* Block element content. */
130
+ padding: 0;
131
+ }
132
+
133
+ /* Block element titles. */
134
+ div.title, caption.title {
135
+ color: #527bbd;
136
+ font-family: sans-serif;
137
+ font-weight: bold;
138
+ text-align: left;
139
+ margin-top: 1.0em;
140
+ margin-bottom: 0.5em;
141
+ }
142
+ div.title + * {
143
+ margin-top: 0;
144
+ }
145
+
146
+ td div.title:first-child {
147
+ margin-top: 0.0em;
148
+ }
149
+ div.content div.title:first-child {
150
+ margin-top: 0.0em;
151
+ }
152
+ div.content + div.title {
153
+ margin-top: 0.0em;
154
+ }
155
+
156
+ div.sidebarblock > div.content {
157
+ background: #ffffee;
158
+ border: 1px solid silver;
159
+ padding: 0.5em;
160
+ }
161
+
162
+ div.listingblock > div.content {
163
+ border: 1px solid silver;
164
+ background: #f4f4f4;
165
+ padding: 0.5em;
166
+ }
167
+
168
+ div.quoteblock {
169
+ padding-left: 2.0em;
170
+ margin-right: 10%;
171
+ }
172
+ div.quoteblock > div.attribution {
173
+ padding-top: 0.5em;
174
+ text-align: right;
175
+ }
176
+
177
+ div.verseblock {
178
+ padding-left: 2.0em;
179
+ margin-right: 10%;
180
+ }
181
+ div.verseblock > div.content {
182
+ white-space: pre;
183
+ }
184
+ div.verseblock > div.attribution {
185
+ padding-top: 0.75em;
186
+ text-align: left;
187
+ }
188
+ /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189
+ div.verseblock + div.attribution {
190
+ text-align: left;
191
+ }
192
+
193
+ div.admonitionblock .icon {
194
+ vertical-align: top;
195
+ font-size: 1.1em;
196
+ font-weight: bold;
197
+ text-decoration: underline;
198
+ color: #527bbd;
199
+ padding-right: 0.5em;
200
+ }
201
+ div.admonitionblock td.content {
202
+ padding-left: 0.5em;
203
+ border-left: 2px solid silver;
204
+ }
205
+
206
+ div.exampleblock > div.content {
207
+ border-left: 2px solid silver;
208
+ padding: 0.5em;
209
+ }
210
+
211
+ div.imageblock div.content { padding-left: 0; }
212
+ div.imageblock img { border: 1px solid silver; }
213
+ span.image img { border-style: none; }
214
+
215
+ dl {
216
+ margin-top: 0.8em;
217
+ margin-bottom: 0.8em;
218
+ }
219
+ dt {
220
+ margin-top: 0.5em;
221
+ margin-bottom: 0;
222
+ font-style: normal;
223
+ color: navy;
224
+ }
225
+ dd > *:first-child {
226
+ margin-top: 0.1em;
227
+ }
228
+
229
+ ul, ol {
230
+ list-style-position: outside;
231
+ }
232
+ ol.arabic {
233
+ list-style-type: decimal;
234
+ }
235
+ ol.loweralpha {
236
+ list-style-type: lower-alpha;
237
+ }
238
+ ol.upperalpha {
239
+ list-style-type: upper-alpha;
240
+ }
241
+ ol.lowerroman {
242
+ list-style-type: lower-roman;
243
+ }
244
+ ol.upperroman {
245
+ list-style-type: upper-roman;
246
+ }
247
+
248
+ div.compact ul, div.compact ol,
249
+ div.compact p, div.compact p,
250
+ div.compact div, div.compact div {
251
+ margin-top: 0.1em;
252
+ margin-bottom: 0.1em;
253
+ }
254
+
255
+ div.tableblock > table {
256
+ border: 3px solid #527bbd;
257
+ }
258
+ thead {
259
+ font-family: sans-serif;
260
+ font-weight: bold;
261
+ }
262
+ tfoot {
263
+ font-weight: bold;
264
+ }
265
+ td > div.verse {
266
+ white-space: pre;
267
+ }
268
+ p.table {
269
+ margin-top: 0;
270
+ }
271
+ /* Because the table frame attribute is overriden by CSS in most browsers. */
272
+ div.tableblock > table[frame="void"] {
273
+ border-style: none;
274
+ }
275
+ div.tableblock > table[frame="hsides"] {
276
+ border-left-style: none;
277
+ border-right-style: none;
278
+ }
279
+ div.tableblock > table[frame="vsides"] {
280
+ border-top-style: none;
281
+ border-bottom-style: none;
282
+ }
283
+
284
+
285
+ div.hdlist {
286
+ margin-top: 0.8em;
287
+ margin-bottom: 0.8em;
288
+ }
289
+ div.hdlist tr {
290
+ padding-bottom: 15px;
291
+ }
292
+ dt.hdlist1.strong, td.hdlist1.strong {
293
+ font-weight: bold;
294
+ }
295
+ td.hdlist1 {
296
+ vertical-align: top;
297
+ font-style: normal;
298
+ padding-right: 0.8em;
299
+ color: navy;
300
+ }
301
+ td.hdlist2 {
302
+ vertical-align: top;
303
+ }
304
+ div.hdlist.compact tr {
305
+ margin: 0;
306
+ padding-bottom: 0;
307
+ }
308
+
309
+ .comment {
310
+ background: yellow;
311
+ }
312
+
313
+ @media print {
314
+ div#footer-badges { display: none; }
315
+ }
316
+
317
+ div#toctitle {
318
+ color: #527bbd;
319
+ font-family: sans-serif;
320
+ font-size: 1.1em;
321
+ font-weight: bold;
322
+ margin-top: 1.0em;
323
+ margin-bottom: 0.1em;
324
+ }
325
+
326
+ div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327
+ margin-top: 0;
328
+ margin-bottom: 0;
329
+ }
330
+ div.toclevel2 {
331
+ margin-left: 2em;
332
+ font-size: 0.9em;
333
+ }
334
+ div.toclevel3 {
335
+ margin-left: 4em;
336
+ font-size: 0.9em;
337
+ }
338
+ div.toclevel4 {
339
+ margin-left: 6em;
340
+ font-size: 0.9em;
341
+ }
342
+ </style>
343
+ <script type="text/javascript">
344
+ /*<![CDATA[*/
345
+ window.onload = function(){generateToc(3)}
346
+ /* Author: Mihai Bazon, September 2002
347
+ * http://students.infoiasi.ro/~mishoo
348
+ *
349
+ * Table Of Content generator
350
+ * Version: 0.4
351
+ *
352
+ * Feel free to use this script under the terms of the GNU General Public
353
+ * License, as long as you do not remove or alter this notice.
354
+ */
355
+
356
+ /* modified by Troy D. Hanson, September 2006. License: GPL */
357
+ /* modified by Stuart Rackham, October 2006. License: GPL */
358
+
359
+ function getText(el) {
360
+ var text = "";
361
+ for (var i = el.firstChild; i != null; i = i.nextSibling) {
362
+ if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
363
+ text += i.data;
364
+ else if (i.firstChild != null)
365
+ text += getText(i);
366
+ }
367
+ return text;
368
+ }
369
+
370
+ function TocEntry(el, text, toclevel) {
371
+ this.element = el;
372
+ this.text = text;
373
+ this.toclevel = toclevel;
374
+ }
375
+
376
+ function tocEntries(el, toclevels) {
377
+ var result = new Array;
378
+ var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
379
+ // Function that scans the DOM tree for header elements (the DOM2
380
+ // nodeIterator API would be a better technique but not supported by all
381
+ // browsers).
382
+ var iterate = function (el) {
383
+ for (var i = el.firstChild; i != null; i = i.nextSibling) {
384
+ if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
385
+ var mo = re.exec(i.tagName)
386
+ if (mo)
387
+ result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
388
+ iterate(i);
389
+ }
390
+ }
391
+ }
392
+ iterate(el);
393
+ return result;
394
+ }
395
+
396
+ // This function does the work. toclevels = 1..4.
397
+ function generateToc(toclevels) {
398
+ var toc = document.getElementById("toc");
399
+ var entries = tocEntries(document.getElementsByTagName("body")[0], toclevels);
400
+ for (var i = 0; i < entries.length; ++i) {
401
+ var entry = entries[i];
402
+ if (entry.element.id == "")
403
+ entry.element.id = "toc" + i;
404
+ var a = document.createElement("a");
405
+ a.href = "#" + entry.element.id;
406
+ a.appendChild(document.createTextNode(entry.text));
407
+ var div = document.createElement("div");
408
+ div.appendChild(a);
409
+ div.className = "toclevel" + entry.toclevel;
410
+ toc.appendChild(div);
411
+ }
412
+ if (entries.length == 0)
413
+ document.getElementById("header").removeChild(toc);
414
+ }
415
+ /*]]>*/
416
+ </script>
417
+ </head>
418
+ <body>
419
+ <div id="header">
420
+ <h1>Phusion Passenger users guide, Nginx version</h1>
421
+ <div id="toc">
422
+ <div id="toctitle">Table of Contents</div>
423
+ <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
424
+ </div>
425
+ </div>
426
+ <div id="preamble">
427
+ <div class="sectionbody">
428
+ <div class="paragraph"><p><span class="image">
429
+ <a class="image" href="http://www.phusion.nl/">
430
+ <img src="images/phusion_banner.png" alt="images/phusion_banner.png" />
431
+ </a>
432
+ </span></p></div>
433
+ <div class="paragraph"><p>Phusion Passenger is an Nginx module, which makes deploying Ruby and Ruby on
434
+ Rails applications on Nginx a breeze. It follows the usual Ruby on Rails
435
+ conventions, such as "Don&#8217;t-Repeat-Yourself" and ease of setup, while at the
436
+ same time providing enough flexibility.</p></div>
437
+ <div class="paragraph"><p>This users guide will teach you:</p></div>
438
+ <div class="ulist"><ul>
439
+ <li>
440
+ <p>
441
+ How to install Nginx with Phusion Passenger support.
442
+ </p>
443
+ </li>
444
+ <li>
445
+ <p>
446
+ How to configure Phusion Passenger.
447
+ </p>
448
+ </li>
449
+ <li>
450
+ <p>
451
+ How to deploy a Ruby on Rails application.
452
+ </p>
453
+ </li>
454
+ <li>
455
+ <p>
456
+ How to deploy a <a href="http://rack.rubyforge.org/">Rack</a>-based Ruby application.
457
+ </p>
458
+ </li>
459
+ <li>
460
+ <p>
461
+ How to solve common problems.
462
+ </p>
463
+ </li>
464
+ </ul></div>
465
+ <div class="paragraph"><p>This guide assumes that the reader is somewhat familiar with Nginx and with
466
+ using the commandline.</p></div>
467
+ </div>
468
+ </div>
469
+ <h2 id="_supported_operating_systems">1. Supported operating systems</h2>
470
+ <div class="sectionbody">
471
+ <div class="paragraph"><p>Phusion Passenger works on any POSIX-compliant operating system. In other
472
+ words: practically any operating system on earth, except Microsoft Windows.</p></div>
473
+ <div class="paragraph"><p>Phusion Passenger for Nginx has been tested on:</p></div>
474
+ <div class="ulist"><ul>
475
+ <li>
476
+ <p>
477
+ Ubuntu Linux 8.04 (x86)
478
+ </p>
479
+ </li>
480
+ <li>
481
+ <p>
482
+ Gentoo Linux (AMD64)
483
+ </p>
484
+ </li>
485
+ <li>
486
+ <p>
487
+ MacOS X Leopard (x86)
488
+ </p>
489
+ </li>
490
+ </ul></div>
491
+ <div class="paragraph"><p>Other operating systems have not been tested, but Phusion Passenger will probably
492
+ work fine on them. Please
493
+ <a href="http://code.google.com/p/phusion-passenger/issues/list">report a bug</a>
494
+ or
495
+ <a href="http://groups.google.com/group/phusion-passenger">join our discussion list</a>
496
+ if it doesn&#8217;t.</p></div>
497
+ </div>
498
+ <h2 id="install_passenger">2. Installing Phusion Passenger</h2>
499
+ <div class="sectionbody">
500
+ <h3 id="_overview">2.1. Overview</h3>
501
+ <div class="paragraph"><p>As you might already know, Nginx does not support loadable modules, in contrast
502
+ to most other web servers (e.g. Apache). Therefore, to install Phusion Passenger
503
+ for Nginx, one must recompile and reinstall Nginx with Phusion Passenger support.
504
+ There are two ways to do this:</p></div>
505
+ <div class="olist arabic"><ol class="arabic">
506
+ <li>
507
+ <p>
508
+ By running the Phusion Passenger installer for Nginx. This installer will
509
+ guide you through the entire installation process, including downloading,
510
+ compiling and installing Nginx. You should be able to get Nginx with Phusion
511
+ Passenger support up-and-running in a matter of minutes. This is the
512
+ recommended installation method.
513
+ </p>
514
+ </li>
515
+ <li>
516
+ <p>
517
+ By manually configuring and compiling Nginx with Phusion Passenger support,
518
+ through Nginx&#8217;s <tt>--add-module</tt> configure option. Generally, using our
519
+ installer is easier, so you should only use this method if you&#8217;re already
520
+ familiar with compiling Nginx.
521
+ </p>
522
+ </li>
523
+ </ol></div>
524
+ <div class="admonitionblock">
525
+ <table><tr>
526
+ <td class="icon">
527
+ <img src="./images/icons/tip.png" alt="Tip" />
528
+ </td>
529
+ <td class="content">You might have to run the installation commands in the following sections
530
+ as <em>root</em>. If the installer fails because of permission errors, it will tell
531
+ you.</td>
532
+ </tr></table>
533
+ </div>
534
+ <h3 id="specifying_ruby_installation">2.2. Specifying the correct Ruby installation</h3>
535
+ <div class="paragraph"><p>If your system has multiple Ruby installations&#8201;&#8212;&#8201;which is likely the case on
536
+ MacOS X, or if you&#8217;ve also installed
537
+ <a href="http://www.rubyenterpriseedition.com">Ruby Enterprise Edition</a>&#8201;&#8212;&#8201;then you
538
+ will need to tell the operating system which Ruby installation to use, prior to
539
+ running the Phusion Passenger installer. If you only have one Ruby installation
540
+ (the case on most Linux systems), then you can skip this section because Phusion
541
+ Passenger will automatically detect it.</p></div>
542
+ <div class="paragraph"><p>To specify a Ruby installation, prepend your Ruby installation&#8217;s <tt>bin</tt>
543
+ directory to the <tt>PATH</tt> environment variable. For example, if you have the
544
+ following Ruby installations:</p></div>
545
+ <div class="ulist"><ul>
546
+ <li>
547
+ <p>
548
+ /usr/bin/ruby
549
+ </p>
550
+ </li>
551
+ <li>
552
+ <p>
553
+ /opt/myruby/bin/ruby
554
+ </p>
555
+ </li>
556
+ </ul></div>
557
+ <div class="paragraph"><p>and you want to use the latter, then type:</p></div>
558
+ <div class="listingblock">
559
+ <div class="content">
560
+ <pre><tt>export PATH=/opt/myruby/bin:$PATH</tt></pre>
561
+ </div></div>
562
+ <h3 id="_installing_phusion_passenger_for_nginx_through_the_installer">2.3. Installing Phusion Passenger for Nginx through the installer</h3>
563
+ <h4 id="_obtaining_the_phusion_passenger_files_and_running_the_installer">2.3.1. Obtaining the Phusion Passenger files and running the installer</h4>
564
+ <div class="paragraph"><p>You must obtain the Phusion Passenger files in order to run the installer.
565
+ This can be done either by installing the Phusion Passenger gem, or by
566
+ downloading the source tarball.</p></div>
567
+ <h5 id="_gem">Gem</h5>
568
+ <div class="paragraph"><p>First, install the Phusion Passenger gem by running:</p></div>
569
+ <div class="listingblock">
570
+ <div class="content">
571
+ <pre><tt>gem install passenger</tt></pre>
572
+ </div></div>
573
+ <div class="paragraph"><p>Next, run the Phusion Passenger installer for Nginx:</p></div>
574
+ <div class="listingblock">
575
+ <div class="content">
576
+ <pre><tt>passenger-install-nginx-module</tt></pre>
577
+ </div></div>
578
+ <div class="paragraph"><p>Please follow the instructions given by the installer.</p></div>
579
+ <h5 id="_source_tarball">Source tarball</h5>
580
+ <div class="paragraph"><p>The source tarball can be download from the
581
+ <a href="http://www.modrails.com/">Phusion Passenger website</a>. Extract the tarball to
582
+ whatever location you prefer. <strong>The Phusion Passenger files are to reside in that
583
+ location permanently.</strong> For example, if you would like Phusion Passenger to
584
+ reside in <tt>/opt/passenger-x.x.x</tt>, then type:</p></div>
585
+ <div class="listingblock">
586
+ <div class="content">
587
+ <pre><tt>cd /opt
588
+ tar xzvf ~/YourDownloadsFolder/passenger-x.x.x.tar.gz</tt></pre>
589
+ </div></div>
590
+ <div class="paragraph"><p>Next, run the Phusion Passenger installer for Nginx:</p></div>
591
+ <div class="listingblock">
592
+ <div class="content">
593
+ <pre><tt>/opt/passenger-x.x.x/bin/passenger-install-nginx-module</tt></pre>
594
+ </div></div>
595
+ <div class="paragraph"><p>Please follow the instructions given by the installer.</p></div>
596
+ <div class="admonitionblock">
597
+ <table><tr>
598
+ <td class="icon">
599
+ <img src="./images/icons/important.png" alt="Important" />
600
+ </td>
601
+ <td class="content">Please do not remove the passenger-x.x.x folder after installation.
602
+ Furthermore, the passenger-x.x.x folder must be accessible by Nginx.</td>
603
+ </tr></table>
604
+ </div>
605
+ <h4 id="_non_interactive_automatic_installation">2.3.2. Non-interactive/automatic installation</h4>
606
+ <div class="paragraph"><p>By default, the installer is interactive. If you want to automate installation,
607
+ then you can do so by passing various answers to the installer through command
608
+ line options.</p></div>
609
+ <div class="paragraph"><p>Please run the installer with <tt>--help</tt> for a list of available command line
610
+ options.</p></div>
611
+ <h3 id="_installing_phusion_passenger_for_nginx_manually">2.4. Installing Phusion Passenger for Nginx manually</h3>
612
+ <div class="paragraph"><p>You can also install Phusion Passenger the way you install any other Nginx module.
613
+ To do this, run Nginx&#8217;s configure script with <tt>--add-module=/path-to-passenger-root/ext/nginx</tt>.</p></div>
614
+ <div class="paragraph"><p>If you installed Phusion Passenger via the gem, then <em>path-to-passenger-root</em>
615
+ can be obtained with the command:</p></div>
616
+ <div class="listingblock">
617
+ <div class="content">
618
+ <pre><tt>passenger-config --root</tt></pre>
619
+ </div></div>
620
+ <div class="paragraph"><p>This will probably output something along the lines of <em>/usr/lib/ruby/gems/1.8/gems/passenger-x.x.x</em>,
621
+ so you&#8217;ll probably have to specify something like <tt>--add-module=/usr/lib/ruby/gems/1.8/gems/passenger-x.x.x/ext/nginx</tt>.</p></div>
622
+ <div class="paragraph"><p>If you installed Phusion Passenger via a source tarball, then <em>path-to-passenger-root</em>
623
+ is the directory which contains the Phusion Passenger source code. So if you
624
+ extracted the Phusion Passenger source code to <em>/opt/passenger-x.x.x</em>, then you&#8217;ll
625
+ have to specify <tt>--add-module=/opt/passenger-x.x.x/ext/nginx</tt>.</p></div>
626
+ </div>
627
+ <h2 id="deploying_a_ror_app">3. Deploying a Ruby on Rails application</h2>
628
+ <div class="sectionbody">
629
+ <div class="paragraph"><p>Suppose you have a Ruby on Rails application in <em>/webapps/mycook</em>, and you own
630
+ the domain <em>www.mycook.com</em>. You can either deploy your application to the
631
+ virtual host&#8217;s root (i.e. the application will be accessible from the root URL,
632
+ <em>http://www.mycook.com/</em>), or in a sub URI (i.e. the application will be
633
+ accessible from a sub URL, such as <em>http://www.mycook.com/railsapplication</em>).</p></div>
634
+ <div class="admonitionblock">
635
+ <table><tr>
636
+ <td class="icon">
637
+ <img src="./images/icons/note.png" alt="Note" />
638
+ </td>
639
+ <td class="content">The default <tt>RAILS_ENV</tt> environment in which deployed Rails applications
640
+ are run, is &#8220;production&#8221;. You can change this by changing the
641
+ <a href="#RailsEnv">rails_env</a> configuration option.</td>
642
+ </tr></table>
643
+ </div>
644
+ <h3 id="_deploying_to_a_virtual_host_8217_s_root">3.1. Deploying to a virtual host&#8217;s root</h3>
645
+ <div class="paragraph"><p>Add a <em>server</em> virtual host entry to your Nginx configuration file. The virtual
646
+ host&#8217;s root must point to your Ruby on Rails application&#8217;s <em>public</em> folder.</p></div>
647
+ <div class="paragraph"><p>Inside the <em>server</em> block, set <em>passenger_enabled on</em>.</p></div>
648
+ <div class="paragraph"><p>For example:</p></div>
649
+ <div class="listingblock">
650
+ <div class="content">
651
+ <pre><tt>http {
652
+ ...
653
+
654
+ server {
655
+ listen 80;
656
+ server_name www.mycook.com;
657
+ root /webapps/mycook/public;
658
+ passenger_enabled on;
659
+ }
660
+
661
+ ...
662
+ }</tt></pre>
663
+ </div></div>
664
+ <div class="paragraph"><p>Then restart Nginx. The application has now been deployed.</p></div>
665
+ <h3 id="deploying_rails_to_sub_uri">3.2. Deploying to a sub URI</h3>
666
+ <div class="paragraph"><p>Suppose that you already have a <em>server</em> virtual host entry:</p></div>
667
+ <div class="listingblock">
668
+ <div class="content">
669
+ <pre><tt>http {
670
+ ...
671
+
672
+ server {
673
+ listen 80;
674
+ server_name www.phusion.nl;
675
+ root /websites/phusion;
676
+ }
677
+
678
+ ...
679
+ }</tt></pre>
680
+ </div></div>
681
+ <div class="paragraph"><p>And you want your Ruby on Rails application to be accessible from the URL
682
+ <em>http://www.phusion.nl/rails</em>.</p></div>
683
+ <div class="paragraph"><p>To do this, make a symlink from your Ruby on Rails application&#8217;s <em>public</em>
684
+ folder to a directory in the document root. For example:</p></div>
685
+ <div class="listingblock">
686
+ <div class="content">
687
+ <pre><tt>ln -s /webapps/mycook/public /websites/phusion/rails</tt></pre>
688
+ </div></div>
689
+ <div class="paragraph"><p>Next, set <em>passenger_enabled on</em> and add a <a href="#PassengerBaseURI">passenger_base_uri</a>
690
+ option to the <em>server</em> block:</p></div>
691
+ <div class="listingblock">
692
+ <div class="content">
693
+ <pre><tt>http {
694
+ ...
695
+
696
+ server {
697
+ listen 80;
698
+ server_name www.phusion.nl;
699
+ root /websites/phusion;
700
+ passenger_enabled on; # &lt;--- These lines have
701
+ passenger_base_uri /rails; # &lt;--- been added.
702
+ }
703
+
704
+ ...
705
+ }</tt></pre>
706
+ </div></div>
707
+ <div class="paragraph"><p>Then restart Nginx. The application has now been deployed.</p></div>
708
+ <div class="admonitionblock">
709
+ <table><tr>
710
+ <td class="icon">
711
+ <img src="./images/icons/tip.png" alt="Tip" />
712
+ </td>
713
+ <td class="content">
714
+ <div class="paragraph"><p>You can deploy multiple Rails applications under a virtual host, by specifying
715
+ <a href="#PassengerBaseURI">passenger_base_uri</a> multiple times. For example:</p></div>
716
+ <div class="listingblock">
717
+ <div class="content">
718
+ <pre><tt>server {
719
+ ...
720
+ passenger_base_uri /app1;
721
+ passenger_base_uri /app2;
722
+ passenger_base_uri /app3;
723
+ }</tt></pre>
724
+ </div></div>
725
+ </td>
726
+ </tr></table>
727
+ </div>
728
+ <h3 id="_redeploying_restarting_the_ruby_on_rails_application">3.3. Redeploying (restarting the Ruby on Rails application)</h3>
729
+ <div class="paragraph"><p>Deploying a new version of a Ruby on Rails application is as simple as
730
+ re-uploading the application files, and restarting the application.</p></div>
731
+ <div class="paragraph"><p>There are two ways to restart the application:</p></div>
732
+ <div class="olist arabic"><ol class="arabic">
733
+ <li>
734
+ <p>
735
+ By restarting Nginx.
736
+ </p>
737
+ </li>
738
+ <li>
739
+ <p>
740
+ By creating or modifying the file <em>tmp/restart.txt</em> in the Rails
741
+ application&#8217;s <a href="#application_root">root folder</a>. Phusion Passenger will
742
+ automatically restart the application.
743
+ </p>
744
+ </li>
745
+ </ol></div>
746
+ <div class="paragraph"><p>For example, to restart our example MyCook application, we type this in the
747
+ command line:</p></div>
748
+ <div class="listingblock">
749
+ <div class="content">
750
+ <pre><tt>touch /webapps/mycook/tmp/restart.txt</tt></pre>
751
+ </div></div>
752
+ <h3 id="_migrations">3.4. Migrations</h3>
753
+ <div class="paragraph"><p>Phusion Passenger is not related to Ruby on Rails migrations in any way. To
754
+ run migrations on your deployment server, please login to your deployment
755
+ server (e.g. with <em>ssh</em>) and type <tt>rake db:migrate RAILS_ENV=production</tt> in
756
+ a shell console, just like one would normally run migrations.</p></div>
757
+ <h3 id="_capistrano_integration">3.5. Capistrano integration</h3>
758
+ <div class="paragraph"><p>See <a href="#capistrano">Capistrano recipe</a>.</p></div>
759
+ </div>
760
+ <h2 id="deploying_a_rack_app">4. Deploying a Rack-based Ruby application</h2>
761
+ <div class="sectionbody">
762
+ <div class="paragraph"><p>Phusion Passenger supports arbitrary Ruby web applications that follow the
763
+ <a href="http://rack.rubyforge.org/">Rack</a> interface.</p></div>
764
+ <div class="paragraph"><p>Phusion Passenger assumes that Rack application directories have a certain layout.
765
+ Suppose that you have a Rack application in <em>/webapps/rackapp</em>. Then that
766
+ folder must contain at least three entries:</p></div>
767
+ <div class="ulist"><ul>
768
+ <li>
769
+ <p>
770
+ <em>config.ru</em>, a Rackup file for starting the Rack application. This file must contain
771
+ the complete logic for initializing the application.
772
+ </p>
773
+ </li>
774
+ <li>
775
+ <p>
776
+ <em>public/</em>, a folder containing public static web assets, like images and stylesheets.
777
+ </p>
778
+ </li>
779
+ <li>
780
+ <p>
781
+ <em>tmp/</em>, used for <em>restart.txt</em> (our application restart mechanism). This will
782
+ be explained in a following subsection.
783
+ </p>
784
+ </li>
785
+ </ul></div>
786
+ <div class="paragraph"><p>So <em>/webapps/rackapp</em> must, at minimum, look like this:</p></div>
787
+ <div class="listingblock">
788
+ <div class="content">
789
+ <pre><tt>/webapps/rackapp
790
+ |
791
+ +-- config.ru
792
+ |
793
+ +-- public/
794
+ |
795
+ +-- tmp/</tt></pre>
796
+ </div></div>
797
+ <div class="paragraph"><p>Suppose you own the domain <em>www.rackapp.com</em>. You can either deploy your application
798
+ to the virtual host&#8217;s root (i.e. the application will be accessible from the root URL,
799
+ <em>http://www.rackapp.com/</em>), or in a sub URI (i.e. the application will be
800
+ accessible from a sub URL, such as <em>http://www.rackapp.com/rackapp</em>).</p></div>
801
+ <div class="admonitionblock">
802
+ <table><tr>
803
+ <td class="icon">
804
+ <img src="./images/icons/note.png" alt="Note" />
805
+ </td>
806
+ <td class="content">The default <tt>RACK_ENV</tt> environment in which deployed Rack applications
807
+ are run, is &#8220;production&#8221;. You can change this by changing the
808
+ <a href="#RackEnv">rack_env</a> configuration option.</td>
809
+ </tr></table>
810
+ </div>
811
+ <h3 id="_tutorial_example_writing_and_deploying_a_hello_world_rack_application">4.1. Tutorial/example: writing and deploying a Hello World Rack application</h3>
812
+ <div class="paragraph"><p>First we create a Phusion Passenger-compliant Rack directory structure:</p></div>
813
+ <div class="listingblock">
814
+ <div class="content">
815
+ <pre><tt>$ mkdir /webapps/rack_example
816
+ $ mkdir /webapps/rack_example/public
817
+ $ mkdir /webapps/rack_example/tmp</tt></pre>
818
+ </div></div>
819
+ <div class="paragraph"><p>Next, we write a minimal "hello world" Rack application:</p></div>
820
+ <div class="listingblock">
821
+ <div class="content">
822
+ <pre><tt>$ cd /webapps/rack_example
823
+ $ some_awesome_editor config.ru
824
+ ...type in some source code...
825
+ $ cat config.ru
826
+ app = proc do |env|
827
+ return [200, { "Content-Type" =&gt; "text/html" }, "hello &lt;b&gt;world&lt;/b&gt;"]
828
+ end
829
+ run app</tt></pre>
830
+ </div></div>
831
+ <div class="paragraph"><p>Finally, we deploy it by adding the following configuration options to
832
+ the Apache configuration file:</p></div>
833
+ <div class="listingblock">
834
+ <div class="content">
835
+ <pre><tt>http {
836
+ ...
837
+ server {
838
+ listen 80;
839
+ server_name www.rackexample.com;
840
+ root /webapps/rack_example/public;
841
+ passenger_enabled on;
842
+ }
843
+ ...
844
+ }</tt></pre>
845
+ </div></div>
846
+ <div class="paragraph"><p>And we&#8217;re done! After an Nginx restart, the above Rack application will be available
847
+ under the URL <em>http://www.rackexample.com/</em>.</p></div>
848
+ <h3 id="_deploying_to_a_virtual_host_8217_s_root_2">4.2. Deploying to a virtual host&#8217;s root</h3>
849
+ <div class="paragraph"><p>Add a <em>server</em> virtual host entry to your Nginx configuration file. The virtual host&#8217;s
850
+ root must point to your Rack application&#8217;s <em>public</em> folder. You must also set
851
+ <em>passenger_enabled on</em> in the <em>server</em> block.</p></div>
852
+ <div class="paragraph"><p>For example:</p></div>
853
+ <div class="listingblock">
854
+ <div class="content">
855
+ <pre><tt>http {
856
+ ...
857
+ server {
858
+ listen 80;
859
+ server_name www.rackapp.com;
860
+ root /webapps/rackapp/public;
861
+ passenger_enabled on;
862
+ }
863
+ ...
864
+ }</tt></pre>
865
+ </div></div>
866
+ <div class="paragraph"><p>Then restart Nginx. The application has now been deployed.</p></div>
867
+ <h3 id="deploying_rack_to_sub_uri">4.3. Deploying to a sub URI</h3>
868
+ <div class="paragraph"><p>Suppose that you already have a virtual host:</p></div>
869
+ <div class="listingblock">
870
+ <div class="content">
871
+ <pre><tt>http {
872
+ ...
873
+
874
+ server {
875
+ listen 80;
876
+ server_name www.phusion.nl;
877
+ root /websites/phusion;
878
+ passenger_enabled on;
879
+ }
880
+
881
+ ...
882
+ }</tt></pre>
883
+ </div></div>
884
+ <div class="paragraph"><p>And you want your Rack application to be accessible from the URL
885
+ <em>http://www.phusion.nl/rack</em>.</p></div>
886
+ <div class="paragraph"><p>To do this, make a symlink from your Rack application&#8217;s <em>public</em>
887
+ folder to a directory in the document root. For example:</p></div>
888
+ <div class="listingblock">
889
+ <div class="content">
890
+ <pre><tt>ln -s /webapps/rackapp/public /websites/phusion/rack</tt></pre>
891
+ </div></div>
892
+ <div class="paragraph"><p>Next, set <em>passenger_enabled on</em> and add a <a href="#PassengerBaseURI">passenger_base_uri</a>
893
+ option to the <em>server</em> block:</p></div>
894
+ <div class="listingblock">
895
+ <div class="content">
896
+ <pre><tt>http {
897
+ ...
898
+
899
+ server {
900
+ listen 80;
901
+ server_name www.phusion.nl;
902
+ root /websites/phusion;
903
+ passenger_enabled on; # &lt;--- These lines have
904
+ passenger_base_uri /rack; # &lt;--- been added.
905
+ }
906
+
907
+ ...
908
+ }</tt></pre>
909
+ </div></div>
910
+ <div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
911
+ <div class="admonitionblock">
912
+ <table><tr>
913
+ <td class="icon">
914
+ <img src="./images/icons/tip.png" alt="Tip" />
915
+ </td>
916
+ <td class="content">
917
+ <div class="paragraph"><p>You can deploy multiple Rack applications under a virtual host, by specifying
918
+ <a href="#PassengerBaseURI">passenger_base_uri</a> multiple times. For example:</p></div>
919
+ <div class="listingblock">
920
+ <div class="content">
921
+ <pre><tt>server {
922
+ ...
923
+ passenger_base_uri /app1;
924
+ passenger_base_uri /app2;
925
+ passenger_base_uri /app3;
926
+ }</tt></pre>
927
+ </div></div>
928
+ </td>
929
+ </tr></table>
930
+ </div>
931
+ <h3 id="_redeploying_restarting_the_rack_application">4.4. Redeploying (restarting the Rack application)</h3>
932
+ <div class="paragraph"><p>Deploying a new version of a Rack application is as simple as
933
+ re-uploading the application files, and restarting the application.</p></div>
934
+ <div class="paragraph"><p>There are two ways to restart the application:</p></div>
935
+ <div class="olist arabic"><ol class="arabic">
936
+ <li>
937
+ <p>
938
+ By restarting Nginx.
939
+ </p>
940
+ </li>
941
+ <li>
942
+ <p>
943
+ By creating or modifying the file <em>tmp/restart.txt</em> in the Rack
944
+ application&#8217;s <a href="#application_root">root folder</a>. Phusion Passenger will
945
+ automatically restart the application.
946
+ </p>
947
+ </li>
948
+ </ol></div>
949
+ <div class="paragraph"><p>For example, to restart our example application, we type this in the
950
+ command line:</p></div>
951
+ <div class="listingblock">
952
+ <div class="content">
953
+ <pre><tt>touch /webapps/rackapp/tmp/restart.txt</tt></pre>
954
+ </div></div>
955
+ <h3 id="_rackup_specifications_for_various_web_frameworks">4.5. Rackup specifications for various web frameworks</h3>
956
+ <div class="paragraph"><p>This subsection shows example <em>config.ru</em> files for various web frameworks.</p></div>
957
+ <h4 id="_camping">4.5.1. Camping</h4>
958
+ <div class="listingblock">
959
+ <div class="content">
960
+ <pre><tt>require 'rubygems'
961
+ require 'rack'
962
+ require 'camping'
963
+
964
+ ##### Begin Camping application
965
+ Camping.goes :Blog
966
+
967
+ ...your application code here...
968
+ ##### End Camping application
969
+
970
+ run Rack::Adapter::Camping.new(Blog)</tt></pre>
971
+ </div></div>
972
+ <div class="paragraph"><p>For Camping versions 2.0 and up, using <tt>run Blog</tt> as the final line will do.</p></div>
973
+ <h4 id="_halcyon">4.5.2. Halcyon</h4>
974
+ <div class="listingblock">
975
+ <div class="content">
976
+ <pre><tt>require 'rubygems'
977
+ require 'halcyon'
978
+ $LOAD_PATH.unshift(Halcyon.root / 'lib')
979
+ Halcyon::Runner.load_config Halcyon.root/'config'/'config.yml'
980
+ run Halcyon::Runner.new</tt></pre>
981
+ </div></div>
982
+ <h4 id="_mack">4.5.3. Mack</h4>
983
+ <div class="listingblock">
984
+ <div class="content">
985
+ <pre><tt>ENV["MACK_ENV"] = ENV["RACK_ENV"]
986
+ load("Rakefile")
987
+ require 'rubygems'
988
+ require 'mack'
989
+ run Mack::Utils::Server.build_app</tt></pre>
990
+ </div></div>
991
+ <h4 id="_merb">4.5.4. Merb</h4>
992
+ <div class="listingblock">
993
+ <div class="content">
994
+ <pre><tt>require 'rubygems'
995
+ require 'merb-core'
996
+
997
+ Merb::Config.setup(
998
+ :merb_root =&gt; File.expand_path(File.dirname(__FILE__)),
999
+ :environment =&gt; ENV['RACK_ENV']
1000
+ )
1001
+ Merb.environment = Merb::Config[:environment]
1002
+ Merb.root = Merb::Config[:merb_root]
1003
+ Merb::BootLoader.run
1004
+
1005
+ run Merb::Rack::Application.new</tt></pre>
1006
+ </div></div>
1007
+ <h4 id="_ramaze">4.5.5. Ramaze</h4>
1008
+ <div class="listingblock">
1009
+ <div class="content">
1010
+ <pre><tt>require "start"
1011
+ Ramaze.trait[:essentials].delete Ramaze::Adapter
1012
+ Ramaze.start :force =&gt; true
1013
+ run Ramaze::Adapter::Base</tt></pre>
1014
+ </div></div>
1015
+ <h4 id="_sinatra">4.5.6. Sinatra</h4>
1016
+ <div class="listingblock">
1017
+ <div class="content">
1018
+ <pre><tt>require 'rubygems'
1019
+ require 'sinatra'
1020
+
1021
+ root_dir = File.dirname(__FILE__)
1022
+
1023
+ set :environment, ENV['RACK_ENV'].to_sym
1024
+ set :root, root_dir
1025
+ set :app_file, File.join(root_dir, 'app.rb')
1026
+ disable :run
1027
+
1028
+ run Sinatra::Application</tt></pre>
1029
+ </div></div>
1030
+ </div>
1031
+ <h2 id="_configuring_phusion_passenger">5. Configuring Phusion Passenger</h2>
1032
+ <div class="sectionbody">
1033
+ <div class="paragraph"><p>After installation, Phusion Passenger does not need any further configurations.
1034
+ Nevertheless, the system administrator may be interested in changing
1035
+ Phusion Passenger&#8217;s behavior. Phusion Passenger supports the following configuration
1036
+ options in the Nginx configuration file:</p></div>
1037
+ <h3 id="_passenger_root_lt_directory_gt">5.1. passenger_root &lt;directory&gt;</h3>
1038
+ <div class="paragraph"><p>The location to the Phusion Passenger root directory. This configuration option
1039
+ is essential to Phusion Passenger, and allows Phusion Passenger to locate its own
1040
+ data files. The correct value is given by the installer.</p></div>
1041
+ <div class="paragraph"><p>If you&#8217;ve moved Phusion Passenger to a different directory then you need to update
1042
+ this option as well. Please read
1043
+ <a href="#moving_phusion_passenger">Moving Phusion Passenger to a different directory</a> for more information.</p></div>
1044
+ <div class="paragraph"><p>This required option may only occur once, in the <em>http</em> configuration block.</p></div>
1045
+ <h3 id="_passenger_log_level_lt_integer_gt">5.2. passenger_log_level &lt;integer&gt;</h3>
1046
+ <div class="paragraph"><p>This option allows one to specify how much information Phusion Passenger should
1047
+ write to the Apache error log file. A higher log level value means that more
1048
+ information will be logged.</p></div>
1049
+ <div class="paragraph"><p>Possible values are:</p></div>
1050
+ <div class="ulist"><ul>
1051
+ <li>
1052
+ <p>
1053
+ <em>0</em>: Show only errors and warnings.
1054
+ </p>
1055
+ </li>
1056
+ <li>
1057
+ <p>
1058
+ <em>1</em>: Show the most important debugging information. This might be useful for
1059
+ system administrators who are trying to figure out the cause of a
1060
+ problem.
1061
+ </p>
1062
+ </li>
1063
+ <li>
1064
+ <p>
1065
+ <em>2</em>: Show more debugging information. This is typically only useful for developers.
1066
+ </p>
1067
+ </li>
1068
+ <li>
1069
+ <p>
1070
+ <em>3</em>: Show even more debugging information.
1071
+ </p>
1072
+ </li>
1073
+ </ul></div>
1074
+ <div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
1075
+ The default is <em>0</em>.</p></div>
1076
+ <h3 id="_passenger_ruby_lt_filename_gt">5.3. passenger_ruby &lt;filename&gt;</h3>
1077
+ <div class="paragraph"><p>This option allows one to specify the Ruby interpreter to use.</p></div>
1078
+ <div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
1079
+ The default is <em>ruby</em>.</p></div>
1080
+ <h3 id="PassengerUseGlobalQueue">5.4. passenger_use_global_queue &lt;on|off&gt;</h3>
1081
+ <div class="paragraph"><p>Turns the use of global queuing on or off.</p></div>
1082
+ <div class="paragraph"><p>This option may occur in the following places:</p></div>
1083
+ <div class="ulist"><ul>
1084
+ <li>
1085
+ <p>
1086
+ In a <em>server</em> configuration block.
1087
+ </p>
1088
+ </li>
1089
+ <li>
1090
+ <p>
1091
+ In a <em>location</em> configuration block.
1092
+ </p>
1093
+ </li>
1094
+ <li>
1095
+ <p>
1096
+ In an <em>if</em> configuration scope.
1097
+ </p>
1098
+ </li>
1099
+ </ul></div>
1100
+ <div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>off</em>.</p></div>
1101
+ <div class="paragraph"><p><em>This feature is sponsored by <a href="http://www.37signals.com/">37signals</a>.</em></p></div>
1102
+ <div class="paragraph"><div class="title">What does this option do?</div><p>Recall that Phusion Passenger spawns multiple backend processes (e.g. multiple
1103
+ Ruby on Rails processes), each which processes HTTP requests serially. One of
1104
+ Phusion Passenger&#8217;s jobs is to forward HTTP requests to a suitable backend
1105
+ process. A backend process may take an arbitrary amount of time to process a
1106
+ specific HTTP request. If the websites are (temporarily) under high load, and
1107
+ the backend processes cannot process the requests fast enough, then some
1108
+ requests may have to be queued.</p></div>
1109
+ <div class="paragraph"><p>If global queuing is turned off, then Phusion Passenger will use <em>fair load
1110
+ balancing</em>. This means that each backend process will have its own private
1111
+ queue. Phusion Passenger will forward an HTTP request to the backend process
1112
+ that has the least amount of requests in its queue.</p></div>
1113
+ <div class="paragraph"><p>If global queuing is turned on, then Phusion Passenger will use a global queue
1114
+ that&#8217;s shared between all backend processes. If an HTTP request comes in, and
1115
+ all the backend processes are still busy, then Phusion Passenger will wait until
1116
+ at least one backend process is done, and will then forward the request to that
1117
+ process.</p></div>
1118
+ <div class="paragraph"><div class="title">When to turn on global queuing?</div><p>You should turn on global queuing if one of your web applications may have
1119
+ long-running requests.</p></div>
1120
+ <div class="paragraph"><p>For example suppose that:</p></div>
1121
+ <div class="ulist"><ul>
1122
+ <li>
1123
+ <p>
1124
+ global queuing is turned off.
1125
+ </p>
1126
+ </li>
1127
+ <li>
1128
+ <p>
1129
+ we&#8217;re currently in a state where all backend processes have 3 requests in
1130
+ their queue, except for a single backend process, which has 1 request in its
1131
+ queue.
1132
+ </p>
1133
+ </li>
1134
+ </ul></div>
1135
+ <div class="paragraph"><p>The situation looks like this:</p></div>
1136
+ <div class="listingblock">
1137
+ <div class="content">
1138
+ <pre><tt>Backend process A: [* ] (1 request in queue)
1139
+ Backend process B: [*** ] (3 requests in queue)
1140
+ Backend process C: [*** ] (3 requests in queue)
1141
+ Backend process D: [*** ] (3 requests in queue)</tt></pre>
1142
+ </div></div>
1143
+ <div class="paragraph"><p>Each process is currently serving short-running requests.</p></div>
1144
+ <div class="paragraph"><p>Phusion Passenger will forward the next request to backend process A. A will
1145
+ now have 2 items in its queue. We&#8217;ll mark this new request with an X:</p></div>
1146
+ <div class="listingblock">
1147
+ <div class="content">
1148
+ <pre><tt>Backend process A: [*X ] (2 request in queue)
1149
+ Backend process B: [*** ] (3 requests in queue)
1150
+ Backend process C: [*** ] (3 requests in queue)
1151
+ Backend process D: [*** ] (3 requests in queue)</tt></pre>
1152
+ </div></div>
1153
+ <div class="paragraph"><p>Assuming that B, C and D still aren&#8217;t done with their current request, the next
1154
+ HTTP request - let&#8217;s call this Y - will be forwarded to backend process A as
1155
+ well, because it has the least number of items in its queue:</p></div>
1156
+ <div class="listingblock">
1157
+ <div class="content">
1158
+ <pre><tt>Backend process A: [*XY ] (3 requests in queue)
1159
+ Backend process B: [*** ] (3 requests in queue)
1160
+ Backend process C: [*** ] (3 requests in queue)
1161
+ Backend process D: [*** ] (3 requests in queue)</tt></pre>
1162
+ </div></div>
1163
+ <div class="paragraph"><p>But if request X happens to be a long-running request that needs 60 seconds to
1164
+ complete, then we&#8217;ll have a problem. Y won&#8217;t be processed for at least 60
1165
+ seconds. It would have been a better idea if Y was forward to processes B, C or
1166
+ D instead, because they only have short-living requests in their queues.</p></div>
1167
+ <div class="paragraph"><p>This problem will be avoided entirely if you turn global queuing on. With global
1168
+ queuing, all backend processes will share the same queue. The first backend
1169
+ process that becomes available will take from the queue, and so this
1170
+ &#8220;queuing-behind-long-running-request&#8221; problem will never occur.</p></div>
1171
+ <div class="paragraph"><p>Turning global queuing off will yield a minor performance improvement (about 5%,
1172
+ depending on how fast/slow your web application is), which is why it&#8217;s off by
1173
+ default.</p></div>
1174
+ <h3 id="PassengerUserSwitching">5.5. passenger_user_switching &lt;on|off&gt;</h3>
1175
+ <div class="paragraph"><p>Whether to enable <a href="#user_switching">user switching support</a>.</p></div>
1176
+ <div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
1177
+ The default value is <em>on</em>.</p></div>
1178
+ <h3 id="PassengerDefaultUser">5.6. passenger_default_user &lt;username&gt;</h3>
1179
+ <div class="paragraph"><p>Phusion Passenger enables <a href="#user_switching">user switching support</a> by default.
1180
+ This configuration option allows one to specify which user Rails/Rack
1181
+ applications must run as, if user switching fails or is disabled.</p></div>
1182
+ <div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
1183
+ The default value is <em>nobody</em>.</p></div>
1184
+ <h3 id="_important_deployment_options">5.7. Important deployment options</h3>
1185
+ <h4 id="_passenger_enabled_lt_on_off_gt">5.7.1. passenger_enabled &lt;on|off&gt;</h4>
1186
+ <div class="paragraph"><p>This option may be specified in a <em>server</em> configuration block, a
1187
+ <em>location</em> configuration block or an <em>if</em> configuration scope, to
1188
+ enable or disable Phusion Passenger for that server or that location.</p></div>
1189
+ <div class="paragraph"><p>Phusion Passenger is disabled by default, so you must explicitly enable
1190
+ it for server blocks that you wish to serve through Phusion Passenger.
1191
+ Please see <a href="#deploying_a_ror_app">Deploying a Ruby on Rails application</a>
1192
+ and <a href="#deploying_a_rack_app">Deploying a Rack-based Ruby application</a>
1193
+ for examples.</p></div>
1194
+ <h4 id="PassengerBaseURI">5.7.2. passenger_base_uri &lt;uri&gt;</h4>
1195
+ <div class="paragraph"><p>Used to specify that the given URI is an distinct application that should
1196
+ be served by Phusion Passenger. This option can be used for both Rails and
1197
+ Rack applications. See <a href="#deploying_rails_to_sub_uri">Deploying Rails to a sub URI</a>
1198
+ for an example.</p></div>
1199
+ <div class="paragraph"><p>It is allowed to specify this option multiple times. Do this to deploy multiple
1200
+ applications in different sub-URIs under the same virtual host.</p></div>
1201
+ <div class="paragraph"><p>This option may occur in the following places:</p></div>
1202
+ <div class="ulist"><ul>
1203
+ <li>
1204
+ <p>
1205
+ In a <em>server</em> configuration block.
1206
+ </p>
1207
+ </li>
1208
+ <li>
1209
+ <p>
1210
+ In a <em>location</em> configuration block.
1211
+ </p>
1212
+ </li>
1213
+ <li>
1214
+ <p>
1215
+ In an <em>if</em> configuration scope.
1216
+ </p>
1217
+ </li>
1218
+ </ul></div>
1219
+ <h3 id="_resource_control_and_optimization_options">5.8. Resource control and optimization options</h3>
1220
+ <h4 id="PassengerMaxPoolSize">5.8.1. passenger_max_pool_size &lt;integer&gt;</h4>
1221
+ <div class="paragraph"><p>The maximum number of Ruby on Rails or Rack application instances that may
1222
+ be simultaneously active. A larger number results in higher memory usage,
1223
+ but improved ability to handle concurrent HTTP clients.</p></div>
1224
+ <div class="paragraph"><p>The optimal value depends on your system&#8217;s hardware and the server&#8217;s average
1225
+ load. You should experiment with different values. But generally speaking,
1226
+ the value should be at least equal to the number of CPUs (or CPU cores) that
1227
+ you have. If your system has 2 GB of RAM, then we recommend a value of <em>30</em>.
1228
+ If your system is a Virtual Private Server (VPS) and has about 256 MB RAM, and
1229
+ is also running other services such as MySQL, then we recommend a value of <em>2</em>.</p></div>
1230
+ <div class="paragraph"><p>If you find that your server is unable to handle the load on your Rails/Rack websites
1231
+ (i.e. running out of memory) then you should lower this value. (Though if your
1232
+ sites are really that popular, then you should strongly consider upgrading your
1233
+ hardware or getting more servers.)</p></div>
1234
+ <div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration bock.
1235
+ The default value is <em>6</em>.</p></div>
1236
+ <div class="admonitionblock">
1237
+ <table><tr>
1238
+ <td class="icon">
1239
+ <img src="./images/icons/tip.png" alt="Tip" />
1240
+ </td>
1241
+ <td class="content">We strongly recommend you to <a href="#reducing_memory_usage">use Ruby Enterprise Edition</a>. This allows you to reduce the memory usage of your Ruby on Rails applications
1242
+ by about 33%. And it&#8217;s not hard to install.</td>
1243
+ </tr></table>
1244
+ </div>
1245
+ <h4 id="_passenger_max_instances_per_app_lt_integer_gt">5.8.2. passenger_max_instances_per_app &lt;integer&gt;</h4>
1246
+ <div class="paragraph"><p>The maximum number of seconds that an application instance may be idle. That is,
1247
+ if an application instance hasn&#8217;t received any traffic after the given number of
1248
+ seconds, then it will be shutdown in order to conserve memory.</p></div>
1249
+ <div class="paragraph"><p>Decreasing this value means that applications will have to be spawned
1250
+ more often. Since spawning is a relatively slow operation, some visitors may
1251
+ notice a small delay when they visit your Rails/Rack website. However, it will also
1252
+ free up resources used by applications more quickly.</p></div>
1253
+ <div class="paragraph"><p>The optimal value depends on the average time that a visitor spends on a single
1254
+ Rails/Rack web page. We recommend a value of <tt>2 * x</tt>, where <tt>x</tt> is the average
1255
+ number of seconds that a visitor spends on a single Rails/Rack web page. But your
1256
+ mileage may vary.</p></div>
1257
+ <div class="paragraph"><p>When this value is set to <em>0</em>, application instances will not be shutdown unless
1258
+ it&#8217;s really necessary, i.e. when Phusion Passenger is out of worker processes
1259
+ for a given application and one of the inactive application instances needs to
1260
+ make place for another application instance. Setting the value to 0 is
1261
+ recommended if you&#8217;re on a non-shared host that&#8217;s only running a few
1262
+ applications, each which must be available at all times.</p></div>
1263
+ <div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
1264
+ The default value is <em>300</em>.</p></div>
1265
+ <h4 id="PassengerPoolIdleTime">5.8.3. passenger_pool_idle_time &lt;integer&gt;</h4>
1266
+ <div class="paragraph"><p>The maximum number of seconds that an application instance may be idle. That is,
1267
+ if an application instance hasn&#8217;t received any traffic after the given number of
1268
+ seconds, then it will be shutdown in order to conserve memory.</p></div>
1269
+ <div class="paragraph"><p>Decreasing this value means that applications will have to be spawned
1270
+ more often. Since spawning is a relatively slow operation, some visitors may
1271
+ notice a small delay when they visit your Rails/Rack website. However, it will also
1272
+ free up resources used by applications more quickly.</p></div>
1273
+ <div class="paragraph"><p>The optimal value depends on the average time that a visitor spends on a single
1274
+ Rails/Rack web page. We recommend a value of <tt>2 * x</tt>, where <tt>x</tt> is the average
1275
+ number of seconds that a visitor spends on a single Rails/Rack web page. But your
1276
+ mileage may vary.</p></div>
1277
+ <div class="paragraph"><p>When this value is set to <em>0</em>, application instances will not be shutdown unless
1278
+ it&#8217;s really necessary, i.e. when Phusion Passenger is out of worker processes
1279
+ for a given application and one of the inactive application instances needs to
1280
+ make place for another application instance. Setting the value to 0 is
1281
+ recommended if you&#8217;re on a non-shared host that&#8217;s only running a few
1282
+ applications, each which must be available at all times.</p></div>
1283
+ <div class="paragraph"><p>This option may only occur once, in the <em>http</em> configuration block.
1284
+ The default value is <em>300</em>.</p></div>
1285
+ <h3 id="_ruby_on_rails_specific_options">5.9. Ruby on Rails-specific options</h3>
1286
+ <h4 id="RailsEnv">5.9.1. rails_env &lt;string&gt;</h4>
1287
+ <div class="paragraph"><p>This option allows one to specify the default <tt>RAILS_ENV</tt> value.</p></div>
1288
+ <div class="paragraph"><p>This option may occur in the following places:</p></div>
1289
+ <div class="ulist"><ul>
1290
+ <li>
1291
+ <p>
1292
+ In a <em>server</em> configuration block.
1293
+ </p>
1294
+ </li>
1295
+ <li>
1296
+ <p>
1297
+ In a <em>location</em> configuration block.
1298
+ </p>
1299
+ </li>
1300
+ <li>
1301
+ <p>
1302
+ In an <em>if</em> configuration scope.
1303
+ </p>
1304
+ </li>
1305
+ </ul></div>
1306
+ <div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>production</em>.</p></div>
1307
+ <h4 id="_rails_spawn_method_lt_string_gt">5.9.2. rails_spawn_method &lt;string&gt;</h4>
1308
+ <div class="admonitionblock">
1309
+ <table><tr>
1310
+ <td class="icon">
1311
+ <img src="./images/icons/tip.png" alt="Tip" />
1312
+ </td>
1313
+ <td class="content">
1314
+ <div class="title">"What spawn method should I use?"</div>
1315
+ <div class="paragraph"><p>This subsection attempts to describe spawn methods, but it&#8217;s okay if you don&#8217;t (want to)
1316
+ understand it, as it&#8217;s mostly a technical detail. You can basically follow this rule of thumb:</p></div>
1317
+ <div class="sidebarblock">
1318
+ <div class="content">
1319
+ <div class="paragraph"><p>If your application works on Mongrel, but not on Phusion Passenger, then set
1320
+ <tt>rails_spawn_method</tt> to <em>conservative</em>. Otherwise, leave it at <em>smart-lv2</em> (the default).</p></div>
1321
+ </div></div>
1322
+ <div class="paragraph"><p>However, we do recommend you to try to understand it. The <em>smart</em> and <em>smart-lv2</em> spawn
1323
+ methods bring many benefits.</p></div>
1324
+ </td>
1325
+ </tr></table>
1326
+ </div>
1327
+ <div class="paragraph"><p>Internally, Phusion Passenger spawns multiple Ruby on Rails processes in order to handle
1328
+ requests. But there are multiple ways with which processes can be spawned, each having
1329
+ its own set of pros and cons. Supported spawn methods are:</p></div>
1330
+ <div class="dlist"><dl>
1331
+ <dt class="hdlist1">
1332
+ <em>smart</em>
1333
+ </dt>
1334
+ <dd>
1335
+ <p>
1336
+ When this spawn method is used, Phusion Passenger will attempt to cache Ruby on Rails
1337
+ framework code and application code for a limited period of time. Please read
1338
+ <a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
1339
+ explanation of what smart spawning exactly does.
1340
+ </p>
1341
+ <div class="paragraph"><p><strong>Pros:</strong>
1342
+ This can significantly decrease spawn time (by as much as 90%). And, when Ruby Enterprise
1343
+ Edition is used, <a href="#reducing_memory_usage">memory usage can be reduced by 33% on average</a>.</p></div>
1344
+ <div class="paragraph"><p><strong>Cons:</strong>
1345
+ Some Ruby on Rails applications and libraries are not compatible with smart spawning.
1346
+ If that&#8217;s the case for your application, then you should use <em>conservative</em> as
1347
+ spawning method.</p></div>
1348
+ </dd>
1349
+ <dt class="hdlist1">
1350
+ <em>smart-lv2</em>
1351
+ </dt>
1352
+ <dd>
1353
+ <p>
1354
+ This spawning method is similar to <em>smart</em> but it skips the framework spawner
1355
+ and uses the application spawner directly. This means the framework code is not
1356
+ cached between multiple applications, although it is still cached within
1357
+ instances of the same application. Please read
1358
+ <a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
1359
+ explanation of what smart-lv2 spawning exactly does.
1360
+ </p>
1361
+ <div class="paragraph"><p><strong>Pros:</strong> It is compatible with a larger number of applications when compared to
1362
+ the <em>smart</em> method, and still performs some caching.</p></div>
1363
+ <div class="paragraph"><p><strong>Cons:</strong> It is slower than smart spawning if you have many applications which
1364
+ use the same framework version. It is therefore advised that shared hosts use the
1365
+ <em>smart</em> method instead.</p></div>
1366
+ </dd>
1367
+ <dt class="hdlist1">
1368
+ <em>conservative</em>
1369
+ </dt>
1370
+ <dd>
1371
+ <p>
1372
+ This spawning method is similar to the one used in Mongrel Cluster. It does not
1373
+ perform any code caching at all. Please read
1374
+ <a href="#spawning_methods_explained">Spawning methods explained</a> for a more detailed
1375
+ explanation of what conservative spawning exactly does.
1376
+ </p>
1377
+ <div class="paragraph"><p><strong>Pros:</strong>
1378
+ Conservative spawning is guaranteed to be compatible with all Rails applications
1379
+ and libraries.</p></div>
1380
+ <div class="paragraph"><p><strong>Cons:</strong>
1381
+ Much slower than smart spawning. Every spawn action will be equally slow, though no slower than
1382
+ the startup time of a single server in Mongrel Cluster. Conservative spawning will also
1383
+ render <a href="#reducing_memory_usage">Ruby Enterprise Edition&#8217;s memory reduction technology</a> useless.</p></div>
1384
+ </dd>
1385
+ </dl></div>
1386
+ <div class="paragraph"><p>This option may occur in the following places:</p></div>
1387
+ <div class="ulist"><ul>
1388
+ <li>
1389
+ <p>
1390
+ In the <em>http</em> configuration block.
1391
+ </p>
1392
+ </li>
1393
+ <li>
1394
+ <p>
1395
+ In a <em>server</em> configuration block.
1396
+ </p>
1397
+ </li>
1398
+ <li>
1399
+ <p>
1400
+ In a <em>location</em> configuration block.
1401
+ </p>
1402
+ </li>
1403
+ <li>
1404
+ <p>
1405
+ In an <em>if</em> configuration scope.
1406
+ </p>
1407
+ </li>
1408
+ </ul></div>
1409
+ <div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>smart-lv2</em>.</p></div>
1410
+ <h4 id="_rails_framework_spawner_idle_time_lt_integer_gt">5.9.3. rails_framework_spawner_idle_time &lt;integer&gt;</h4>
1411
+ <div class="paragraph"><p>The FrameworkSpawner server (explained in <a href="#spawning_methods_explained">Spawning methods explained</a>) has an idle timeout, just like the backend processes spawned by
1412
+ Phusion Passenger do. That is, it will automatically shutdown if it hasn&#8217;t done
1413
+ anything for a given period.</p></div>
1414
+ <div class="paragraph"><p>This option allows you to set the FrameworkSpawner server&#8217;s idle timeout, in
1415
+ seconds. A value of <em>0</em> means that it should never idle timeout.</p></div>
1416
+ <div class="paragraph"><p>Setting a higher value will mean that the FrameworkSpawner server is kept around
1417
+ longer, which may slightly increase memory usage. But as long as the
1418
+ FrameworkSpawner server is running, the time to spawn a Ruby on Rails backend
1419
+ process only takes about 40% of the time that is normally needed, assuming that
1420
+ you&#8217;re using the <em>smart</em> <a href="#RailsSpawnMethod">spawning method</a>. So if your
1421
+ system has enough memory, is it recommended that you set this option to a high
1422
+ value or to <em>0</em>.</p></div>
1423
+ <div class="paragraph"><p>This option may occur in the following places:</p></div>
1424
+ <div class="ulist"><ul>
1425
+ <li>
1426
+ <p>
1427
+ In the <em>http</em> configuration block.
1428
+ </p>
1429
+ </li>
1430
+ <li>
1431
+ <p>
1432
+ In a <em>server</em> configuration block.
1433
+ </p>
1434
+ </li>
1435
+ <li>
1436
+ <p>
1437
+ In a <em>location</em> configuration block.
1438
+ </p>
1439
+ </li>
1440
+ <li>
1441
+ <p>
1442
+ In an <em>if</em> configuration scope.
1443
+ </p>
1444
+ </li>
1445
+ </ul></div>
1446
+ <div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>1800</em> (30 minutes).</p></div>
1447
+ <h4 id="_rails_app_spawner_idle_time_lt_integer_gt">5.9.4. rails_app_spawner_idle_time &lt;integer&gt;</h4>
1448
+ <div class="paragraph"><p>The ApplicationSpawner server (explained in <a href="#spawning_methods_explained">Spawning methods explained</a>) has an idle timeout, just like the backend processes spawned by
1449
+ Phusion Passenger do. That is, it will automatically shutdown if it hasn&#8217;t done
1450
+ anything for a given period.</p></div>
1451
+ <div class="paragraph"><p>This option allows you to set the ApplicationSpawner server&#8217;s idle timeout, in
1452
+ seconds. A value of <em>0</em> means that it should never idle timeout.</p></div>
1453
+ <div class="paragraph"><p>Setting a higher value will mean that the ApplicationSpawner server is kept around
1454
+ longer, which may slightly increase memory usage. But as long as the
1455
+ ApplicationSpawner server is running, the time to spawn a Ruby on Rails backend
1456
+ process only takes about 10% of the time that is normally needed, assuming that
1457
+ you&#8217;re using the <em>smart</em> or <em>smart-lv2</em> <a href="#RailsSpawnMethod">spawning method</a>. So if your
1458
+ system has enough memory, is it recommended that you set this option to a high
1459
+ value or to <em>0</em>.</p></div>
1460
+ <div class="paragraph"><p>This option may occur in the following places:</p></div>
1461
+ <div class="ulist"><ul>
1462
+ <li>
1463
+ <p>
1464
+ In the <em>http</em> configuration block.
1465
+ </p>
1466
+ </li>
1467
+ <li>
1468
+ <p>
1469
+ In a <em>server</em> configuration block.
1470
+ </p>
1471
+ </li>
1472
+ <li>
1473
+ <p>
1474
+ In a <em>location</em> configuration block.
1475
+ </p>
1476
+ </li>
1477
+ <li>
1478
+ <p>
1479
+ In an <em>if</em> configuration scope.
1480
+ </p>
1481
+ </li>
1482
+ </ul></div>
1483
+ <div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>600</em> (10 minutes).</p></div>
1484
+ <h3 id="_rack_specific_options">5.10. Rack-specific options</h3>
1485
+ <h4 id="RackEnv">5.10.1. rack_env &lt;string&gt;</h4>
1486
+ <div class="paragraph"><p>This option allows one to specify the default <tt>RACK_ENV</tt> value.</p></div>
1487
+ <div class="paragraph"><p>This option may occur in the following places:</p></div>
1488
+ <div class="ulist"><ul>
1489
+ <li>
1490
+ <p>
1491
+ In a <em>server</em> configuration block.
1492
+ </p>
1493
+ </li>
1494
+ <li>
1495
+ <p>
1496
+ In a <em>location</em> configuration block.
1497
+ </p>
1498
+ </li>
1499
+ <li>
1500
+ <p>
1501
+ In an <em>if</em> configuration scope.
1502
+ </p>
1503
+ </li>
1504
+ </ul></div>
1505
+ <div class="paragraph"><p>In each place, it may be specified at most once. The default value is <em>production</em>.</p></div>
1506
+ </div>
1507
+ <h2 id="_analysis_and_system_maintenance_tools">6. Analysis and system maintenance tools</h2>
1508
+ <div class="sectionbody">
1509
+ <div class="paragraph"><p>Phusion Passenger provides a set of tools, which are useful for system analysis,
1510
+ maintenance and troubleshooting.</p></div>
1511
+ <h3 id="_inspecting_memory_usage">6.1. Inspecting memory usage</h3>
1512
+ <div class="paragraph"><p>Process inspection tools such as <tt>ps</tt> and <tt>top</tt> are useful, but they
1513
+ <a href="http://groups.google.com/group/phusion-passenger/msg/1fd1c233456d3180">rarely show the correct memory usage</a>.
1514
+ The real memory usage is usually lower than what <tt>ps</tt> and <tt>top</tt> report.</p></div>
1515
+ <div class="paragraph"><p>There are many technical reasons why this is so, but an explanation is beyond
1516
+ the scope of this Users Guide. We kindly refer the interested reader to
1517
+ operating systems literature about <em>virtual memory</em> and <em>copy-on-write</em>.</p></div>
1518
+ <div class="paragraph"><p>The tool <tt>passenger-memory-stats</tt> allows one to easily analyze Phusion Passenger&#8217;s
1519
+ and Apache&#8217;s real memory usage. For example:</p></div>
1520
+ <div class="listingblock">
1521
+ <div class="content">
1522
+ <pre><tt>[bash@localhost root]# passenger-memory-stats
1523
+ ------------- Apache processes --------------.
1524
+ PID PPID Threads VMSize Private Name
1525
+ ---------------------------------------------.
1526
+ 5947 1 9 90.6 MB 0.5 MB /usr/sbin/apache2 -k start
1527
+ 5948 5947 1 18.9 MB 0.7 MB /usr/sbin/fcgi-pm -k start
1528
+ 6029 5947 1 42.7 MB 0.5 MB /usr/sbin/apache2 -k start
1529
+ 6030 5947 1 42.7 MB 0.5 MB /usr/sbin/apache2 -k start
1530
+ 6031 5947 1 42.5 MB 0.3 MB /usr/sbin/apache2 -k start
1531
+ 6033 5947 1 42.5 MB 0.4 MB /usr/sbin/apache2 -k start
1532
+ 6034 5947 1 50.5 MB 0.4 MB /usr/sbin/apache2 -k start
1533
+ 23482 5947 1 82.6 MB 0.4 MB /usr/sbin/apache2 -k start
1534
+ ### Processes: 8
1535
+ ### Total private dirty RSS: 3.50 MB
1536
+
1537
+ --------- Passenger processes ---------.
1538
+ PID Threads VMSize Private Name
1539
+ ---------------------------------------.
1540
+ 6026 1 10.9 MB 4.7 MB Passenger spawn server
1541
+ 23481 1 26.7 MB 3.0 MB Passenger FrameworkSpawner: 2.0.2
1542
+ 23791 1 26.8 MB 2.9 MB Passenger ApplicationSpawner: /var/www/projects/app1-foobar
1543
+ 23793 1 26.9 MB 17.1 MB Rails: /var/www/projects/app1-foobar
1544
+ ### Processes: 4
1545
+ ### Total private dirty RSS: 27.76 M</tt></pre>
1546
+ </div></div>
1547
+ <div class="paragraph"><p>The <em>Private</em> or <em>private dirty RSS</em> field shows the <strong>real</strong> memory usage of processes. Here,
1548
+ we see that all the Apache worker processes only take less than 1 MB memory each.
1549
+ This is a lot less than the 50 MB-ish memory usage as shown in the <em>VMSize</em> column
1550
+ (which is what a lot of people think is the real memory usage, but is actually not).</p></div>
1551
+ <div class="admonitionblock">
1552
+ <table><tr>
1553
+ <td class="icon">
1554
+ <img src="./images/icons/note.png" alt="Note" />
1555
+ </td>
1556
+ <td class="content">Private dirty RSS reporting only works on Linux. Unfortunately other operating systems
1557
+ don&#8217;t provide facilities for determining processes' private dirty RSS. On non-Linux systems,
1558
+ the Resident Set Size is reported instead.</td>
1559
+ </tr></table>
1560
+ </div>
1561
+ <h3 id="_inspecting_phusion_passenger_8217_s_internal_status">6.2. Inspecting Phusion Passenger&#8217;s internal status</h3>
1562
+ <div class="paragraph"><p>One can inspect Phusion Passenger&#8217;s internal status with the tool <tt>passenger-status</tt>.
1563
+ This tool must typically be run as root. For example:</p></div>
1564
+ <div class="listingblock">
1565
+ <div class="content">
1566
+ <pre><tt>[bash@localhost root]# passenger-status
1567
+ ----------- General information -----------
1568
+ max = 6
1569
+ count = 1
1570
+ active = 0
1571
+ inactive = 1
1572
+
1573
+ ----------- Domains -----------
1574
+ /var/www/projects/app1-foobar:
1575
+ PID: 9617 Sessions: 0 Processed: 7 Uptime: 2m 23s</tt></pre>
1576
+ </div></div>
1577
+ <div class="paragraph"><p>The <em>general information</em> section shows the following information:</p></div>
1578
+ <div class="dlist"><dl>
1579
+ <dt class="hdlist1">
1580
+ max
1581
+ </dt>
1582
+ <dd>
1583
+ <p>
1584
+ The maximum number of application instances that Phusion Passenger will
1585
+ spawn. This equals the value given for <a href="#PassengerMaxPoolSize">PassengerMaxPoolSize</a> (Apache)
1586
+ or <a href="#PassengerMaxPoolSize">passenger_max_pool_size</a> (Nginx).
1587
+ </p>
1588
+ </dd>
1589
+ <dt class="hdlist1">
1590
+ count
1591
+ </dt>
1592
+ <dd>
1593
+ <p>
1594
+ The number of application instances that are currently alive. This value
1595
+ is always less than or equal to <em>max</em>.
1596
+ </p>
1597
+ </dd>
1598
+ <dt class="hdlist1">
1599
+ active
1600
+ </dt>
1601
+ <dd>
1602
+ <p>
1603
+ The number of application instances that are currently processing
1604
+ requests. This value is always less than or equal to <em>count</em>.
1605
+ </p>
1606
+ </dd>
1607
+ <dt class="hdlist1">
1608
+ inactive
1609
+ </dt>
1610
+ <dd>
1611
+ <p>
1612
+ The number of application instances that are currently <strong>not</strong> processing
1613
+ requests, i.e. are idle. Idle application instances will be shutdown after a while,
1614
+ as can be specified with <a href="#PassengerPoolIdleTime">PassengerPoolIdleTime (Apache)</a>/<a href="#PassengerPoolIdleTime">passenger_pool_idle_time (Nginx)</a> (unless this
1615
+ value is set to 0, in which case application instances are never shut down via idle
1616
+ time). The value of <em>inactive</em> equals <tt>count - active</tt>.
1617
+ </p>
1618
+ </dd>
1619
+ </dl></div>
1620
+ <div class="paragraph"><p>The <em>domains</em> section shows, for each application directory, information about running
1621
+ application instances:</p></div>
1622
+ <div class="dlist"><dl>
1623
+ <dt class="hdlist1">
1624
+ Sessions
1625
+ </dt>
1626
+ <dd>
1627
+ <p>
1628
+ Shows how many HTTP client are currently in the queue of that application
1629
+ Instance, waiting to be processed.
1630
+ </p>
1631
+ </dd>
1632
+ <dt class="hdlist1">
1633
+ Processed
1634
+ </dt>
1635
+ <dd>
1636
+ <p>
1637
+ Indicates how many requests the instance has served until now. <strong>Tip:</strong> it&#8217;s
1638
+ possible to limit this number with the <a href="#PassengerMaxRequests">PassengerMaxRequests</a>
1639
+ configuration directive.
1640
+ </p>
1641
+ </dd>
1642
+ <dt class="hdlist1">
1643
+ Uptime
1644
+ </dt>
1645
+ <dd>
1646
+ <p>
1647
+ Shows for how long the application instance has been running.
1648
+ </p>
1649
+ </dd>
1650
+ </dl></div>
1651
+ <div class="paragraph"><p>Since Phusion Passenger uses fair load balancing by default, the number of sessions for the
1652
+ application instances should be fairly close to each other. For example, this is fairly
1653
+ normal:</p></div>
1654
+ <div class="listingblock">
1655
+ <div class="content">
1656
+ <pre><tt> PID: 4281 Sessions: 2 Processed: 7 Uptime: 5m 11s
1657
+ PID: 4268 Sessions: 0 Processed: 5 Uptime: 4m 52s
1658
+ PID: 4265 Sessions: 1 Processed: 6 Uptime: 5m 38s
1659
+ PID: 4275 Sessions: 1 Processed: 7 Uptime: 3m 14s</tt></pre>
1660
+ </div></div>
1661
+ <div class="paragraph"><p>But if you see a "spike", i.e. an application instance has an unusually high number of
1662
+ sessions compared to the others, then there might be a problem:</p></div>
1663
+ <div class="listingblock">
1664
+ <div class="content">
1665
+ <pre><tt> PID: 4281 Sessions: 2 Processed: 7 Uptime: 5m 11s
1666
+ PID: 17468 Sessions: 8 &lt;-+ Processed: 2 Uptime: 4m 47s
1667
+ PID: 4265 Sessions: 1 | Processed: 6 Uptime: 5m 38s
1668
+ PID: 4275 Sessions: 1 | Processed: 7 Uptime: 3m 14s
1669
+ |
1670
+ +---- "spike"</tt></pre>
1671
+ </div></div>
1672
+ <div class="paragraph"><p>Possible reasons why spikes can occur:</p></div>
1673
+ <div class="olist arabic"><ol class="arabic">
1674
+ <li>
1675
+ <p>
1676
+ Your application is busy processing a request that takes a very long time.
1677
+ If this is the case, then you might want to turn
1678
+ <a href="#PassengerUseGlobalQueue">global queuing</a> on.
1679
+ </p>
1680
+ </li>
1681
+ <li>
1682
+ <p>
1683
+ Your application is frozen, i.e. has stopped responding. See
1684
+ <a href="#debugging_frozen">Debugging frozen applications</a> for tips.
1685
+ </p>
1686
+ </li>
1687
+ </ol></div>
1688
+ <h3 id="debugging_frozen">6.3. Debugging frozen applications</h3>
1689
+ <div class="paragraph"><p>If one of your application instances is frozen (stopped responding), then you
1690
+ can figure out where it is frozen by killing it with <em>SIGABRT</em>. This will cause the
1691
+ application to raise an exception, with a backtrace.</p></div>
1692
+ <div class="paragraph"><p>The exception (with full backtrace information) is normally logged into the Apache
1693
+ error log. But if your application or if its web framework has its own exception logging
1694
+ routines, then exceptions might be logged into the application&#8217;s log files instead.
1695
+ This is the case with Ruby on Rails. So if you kill a Ruby on Rails application with
1696
+ <em>SIGABRT</em>, please check the application&#8217;s <em>production.log</em> first (assuming that you&#8217;re
1697
+ running it in a <em>production</em> environment). If you don&#8217;t see a backtrace there, check
1698
+ the Apache error log.</p></div>
1699
+ <div class="admonitionblock">
1700
+ <table><tr>
1701
+ <td class="icon">
1702
+ <img src="./images/icons/note.png" alt="Note" />
1703
+ </td>
1704
+ <td class="content">It is safe to kill application instances, even in live environments. Phusion Passenger
1705
+ will restart killed application instances, as if nothing bad happened.</td>
1706
+ </tr></table>
1707
+ </div>
1708
+ </div>
1709
+ <h2 id="_tips">7. Tips</h2>
1710
+ <div class="sectionbody">
1711
+ <h3 id="user_switching">7.1. User switching (security)</h3>
1712
+ <div class="paragraph"><p>There is a problem that plagues most PHP web hosts, namely the fact that all PHP
1713
+ applications are run in the same user context as the web server. So for
1714
+ example, Joe&#8217;s PHP application will be able to read Jane&#8217;s PHP application&#8217;s
1715
+ passwords. This is obviously undesirable on many servers.</p></div>
1716
+ <div class="paragraph"><p>Phusion Passenger solves this problem by implementing <em>user switching</em>. A Rails
1717
+ application is started as the owner of the file <em>config/environment.rb</em>,
1718
+ and a Rack application is started as the owner of the file <em>config.ru</em>.
1719
+ So if <em>/home/webapps/foo/config/environment.rb</em> is owned by <em>joe</em>, then Phusion
1720
+ Passenger will launch the corresponding Rails application as <em>joe</em> as well.</p></div>
1721
+ <div class="paragraph"><p>This behavior is the default, and you don&#8217;t need to configure anything. But
1722
+ there are things that you should keep in mind:</p></div>
1723
+ <div class="ulist"><ul>
1724
+ <li>
1725
+ <p>
1726
+ The owner of <em>environment.rb</em> must have read access to the Rails application&#8217;s
1727
+ folder, and read/write access to the Rails application&#8217;s <em>logs</em> folder.
1728
+ Likewise, the owner of <em>config.ru</em> must have read access to the Rack application&#8217;s
1729
+ folder.
1730
+ </p>
1731
+ </li>
1732
+ <li>
1733
+ <p>
1734
+ This feature is only available if Apache is started by <em>root</em>. This is the
1735
+ case on most Apache installations.
1736
+ </p>
1737
+ </li>
1738
+ <li>
1739
+ <p>
1740
+ Under no circumstances will applications be run as <em>root</em>. If
1741
+ <em>environment.rb</em>/<em>config.ru</em> is owned as root or by an unknown user, then the
1742
+ Rails/Rack application will run as the user specified by
1743
+ <a href="#PassengerDefaultUser">PassengerDefaultUser (Apache)</a>/<a href="#PassengerDefaultUser">passenger_default_user (Nginx)</a>.
1744
+ </p>
1745
+ </li>
1746
+ </ul></div>
1747
+ <div class="paragraph"><p>User switching can be disabled with the
1748
+ <a href="#PassengerUserSwitching">PassengerUserSwitching (Apache)</a>/<a href="#PassengerUserSwitching">passenger_user_switching (Nginx)</a>
1749
+ option.</p></div>
1750
+ <h3 id="reducing_memory_usage">7.2. Reducing memory consumption of Ruby on Rails applications by 33%</h3>
1751
+ <div class="paragraph"><p>Is it possible to reduce memory consumption of your Rails applications by 33% on average,
1752
+ by using <a href="http://www.rubyenterpriseedition.com/">Ruby Enterprise Edition</a>.
1753
+ Please visit the website for details.</p></div>
1754
+ <div class="paragraph"><p>Note that this feature does not apply to Rack applications.</p></div>
1755
+ <h3 id="capistrano">7.3. Capistrano recipe</h3>
1756
+ <div class="paragraph"><p>Phusion Passenger can be combined with <a href="http://capify.org/">Capistrano</a>.
1757
+ The following Capistrano recipe demonstrates Phusion Passenger support.
1758
+ It assumes that you&#8217;re using Git as version control system.</p></div>
1759
+ <div class="listingblock">
1760
+ <div class="content">
1761
+ <pre><tt>set :application, "myapp"
1762
+ set :domain, "example.com"
1763
+ set :repository, "ssh://#{domain}/path-to-your-git-repo/#{application}.git"
1764
+ set :use_sudo, false
1765
+ set :deploy_to, "/path-to-your-web-app-directory/#{application}"
1766
+ set :scm, "git"
1767
+
1768
+ role :app, domain
1769
+ role :web, domain
1770
+ role :db, domain, :primary =&gt; true
1771
+
1772
+ namespace :deploy do
1773
+ task :start, :roles =&gt; :app do
1774
+ run "touch #{current_release}/tmp/restart.txt"
1775
+ end
1776
+
1777
+ task :stop, :roles =&gt; :app do
1778
+ # Do nothing.
1779
+ end
1780
+
1781
+ desc "Restart Application"
1782
+ task :restart, :roles =&gt; :app do
1783
+ run "touch #{current_release}/tmp/restart.txt"
1784
+ end
1785
+ end</tt></pre>
1786
+ </div></div>
1787
+ <h3 id="moving_phusion_passenger">7.4. Moving Phusion Passenger to a different directory</h3>
1788
+ <div class="paragraph"><p>It is possible to relocate the Phusion Passenger files to a different directory. It
1789
+ involves two steps:</p></div>
1790
+ <div class="olist arabic"><ol class="arabic">
1791
+ <li>
1792
+ <p>
1793
+ Moving the directory.
1794
+ </p>
1795
+ </li>
1796
+ <li>
1797
+ <p>
1798
+ Updating the &#8220;PassengerRoot&#8221; configuration option in Apache.
1799
+ </p>
1800
+ </li>
1801
+ </ol></div>
1802
+ <div class="paragraph"><p>For example, if Phusion Passenger is located in <em>/opt/passenger/</em>, and you&#8217;d like to
1803
+ move it to <em>/usr/local/passenger/</em>, then do this:</p></div>
1804
+ <div class="olist arabic"><ol class="arabic">
1805
+ <li>
1806
+ <p>
1807
+ Run the following command:
1808
+ </p>
1809
+ <div class="listingblock">
1810
+ <div class="content">
1811
+ <pre><tt>mv /opt/passenger /usr/local/passenger</tt></pre>
1812
+ </div></div>
1813
+ </li>
1814
+ <li>
1815
+ <p>
1816
+ Edit your Apache configuration file, and set:
1817
+ </p>
1818
+ <div class="listingblock">
1819
+ <div class="content">
1820
+ <pre><tt>PassengerRoot /usr/local/passenger</tt></pre>
1821
+ </div></div>
1822
+ </li>
1823
+ </ol></div>
1824
+ <h3 id="_installing_multiple_ruby_on_rails_versions">7.5. Installing multiple Ruby on Rails versions</h3>
1825
+ <div class="paragraph"><p>Each Ruby on Rails applications that are going to be deployed may require a
1826
+ specific Ruby on Rails version. You can install a specific version with
1827
+ this command:</p></div>
1828
+ <div class="listingblock">
1829
+ <div class="content">
1830
+ <pre><tt>gem install rails -v X.X.X</tt></pre>
1831
+ </div></div>
1832
+ <div class="paragraph"><p>where <em>X.X.X</em> is the version number of Ruby on Rails.</p></div>
1833
+ <div class="paragraph"><p>All of these versions will exist in parallel, and will not conflict with each
1834
+ other. Phusion Passenger will automatically make use of the correct version.</p></div>
1835
+ <h3 id="_making_the_application_restart_after_each_request">7.6. Making the application restart after each request</h3>
1836
+ <div class="paragraph"><p>In some situations it might be desirable to restart the web application after
1837
+ each request, for example when developing a non-Rails application that doesn&#8217;t
1838
+ support code reloading, or when developing a web framework.</p></div>
1839
+ <div class="paragraph"><p>To achieve this, simply create the file <em>tmp/always_restart.txt</em> in your
1840
+ application&#8217;s root folder. Unlike <em>restart.txt</em>, Phusion Passenger does not
1841
+ check for this file&#8217;s timestamp: Phusion Passenger will always restart the
1842
+ application, as long as <em>always_restart.txt</em> exists.</p></div>
1843
+ <div class="admonitionblock">
1844
+ <table><tr>
1845
+ <td class="icon">
1846
+ <img src="./images/icons/note.png" alt="Note" />
1847
+ </td>
1848
+ <td class="content">If you&#8217;re just developing a Rails application then you probably don&#8217;t need
1849
+ this feature. If you set <em>RailsEnv development</em> in your Apache configuration,
1850
+ then Rails will automatically reload your application code after each request.
1851
+ <em>always_restart.txt</em> is only useful if you&#8217;re working on Ruby on Rails itself,
1852
+ or when you&#8217;re not developing a Rails application and your web framework
1853
+ does not support code reloading.</td>
1854
+ </tr></table>
1855
+ </div>
1856
+ <h3 id="sub_uri_deployment_uri_fix">7.7. How to fix broken images/CSS/JavaScript URIs in sub-URI deployments</h3>
1857
+ <div class="paragraph"><p>Some people experience broken images and other broken static assets when they
1858
+ deploy their application to a sub-URI (i.e. <em>http://mysite.com/railsapp/</em>).
1859
+ The reason for this usually is that you used a
1860
+ static URI for your image in the views. This means your <em>img</em> source probably refers
1861
+ to something like <em>/images/foo.jpg</em>. The leading slash means that it&#8217;s an absolute URI:
1862
+ you&#8217;re telling the browser to always load <em>http://mysite.com/images/foo.jpg</em> no
1863
+ matter what. The problem is that the image is actually at
1864
+ <em>http://mysite.com/railsapp/images/foo.jpg</em>. There are two ways to fix this.</p></div>
1865
+ <div class="paragraph"><p>The first way (not recommended) is to change your view templates to refer to
1866
+ <em>images/foo.jpg</em>. This is a relative URI: note the lack of a leading slash). What
1867
+ this does is making the path relative to the current URI. The problem is that if you
1868
+ use restful URIs, then your images will probably break again when you add a level to
1869
+ the URI.
1870
+ For example, when you&#8217;re at <em>http://mysite.com/railsapp</em> the browser will look for
1871
+ <em>http://mysite.com/railsapp/images/foo.jpg</em>. But when you&#8217;re at
1872
+ <em>http://mysite.com/railsapp/controller</em>. the browser will look for
1873
+ <em>http://mysite.com/railsapp/controller/images/foo.jpg</em>.
1874
+ So relative URIs usually don&#8217;t work well with layout templates.</p></div>
1875
+ <div class="paragraph"><p>The second and highly recommended way is to always use Rails helper methods to
1876
+ output tags for static assets. These helper methods automatically take care
1877
+ of prepending the base URI that you&#8217;ve deployed the application to. For images
1878
+ there is <tt>image_tag</tt>, for JavaScript there is <tt>javascript_include_tag</tt> and for
1879
+ CSS there is <tt>stylesheet_link_tag</tt>. In the above example you would simply remove
1880
+ the <em>&lt;img&gt;</em> HTML tag and replace it with inline Ruby like this:</p></div>
1881
+ <div class="listingblock">
1882
+ <div class="content">
1883
+ <pre><tt>&lt;%= image_tag("foo.jpg") %&gt;</tt></pre>
1884
+ </div></div>
1885
+ <div class="paragraph"><p>This will generate the proper image tag to <tt>$RAILS_ROOT/public/images/foo.jpg</tt>
1886
+ so that your images will always work no matter what sub-URI you&#8217;ve deployed to.</p></div>
1887
+ <div class="paragraph"><p>These helper methods are more valuable than you may think. For example they also
1888
+ append a timestamp to the URI to better facilitate HTTP caching. For more information,
1889
+ please refer to
1890
+ <a href="http://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html">the Rails API docs</a>.</p></div>
1891
+ </div>
1892
+ <h2 id="_appendix_a_about_this_document">8. Appendix A: About this document</h2>
1893
+ <div class="sectionbody">
1894
+ <div class="paragraph"><p>The text of this document is licensed under the
1895
+ <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
1896
+ Attribution-Share Alike 3.0 Unported License</a>.</p></div>
1897
+ <div class="paragraph"><p><span class="image">
1898
+ <a class="image" href="http://creativecommons.org/licenses/by-sa/3.0/">
1899
+ <img src="images/by_sa.png" alt="images/by_sa.png" />
1900
+ </a>
1901
+ </span></p></div>
1902
+ <div class="paragraph"><p>Phusion Passenger is brought to you by <a href="http://www.phusion.nl/">Phusion</a>.</p></div>
1903
+ <div class="paragraph"><p><span class="image">
1904
+ <a class="image" href="http://www.phusion.nl/">
1905
+ <img src="images/phusion_banner.png" alt="images/phusion_banner.png" />
1906
+ </a>
1907
+ </span></p></div>
1908
+ <div class="paragraph"><p>Phusion Passenger is a trademark of Hongli Lai &amp; Ninh Bui.</p></div>
1909
+ </div>
1910
+ <h2 id="_appendix_b_terminology">9. Appendix B: Terminology</h2>
1911
+ <div class="sectionbody">
1912
+ <h3 id="application_root">9.1. Application root</h3>
1913
+ <div class="paragraph"><p>The root directory of an application that&#8217;s served by Phusion Passenger.</p></div>
1914
+ <div class="paragraph"><p>In case of Ruby on Rails applications, this is the directory that contains
1915
+ <em>Rakefile</em>, <em>app/</em>, <em>config/</em>, <em>public/</em>, etc. In other words, the directory
1916
+ pointed to by <tt>RAILS_ROOT</tt>. For example, take the following directory structure:</p></div>
1917
+ <div class="listingblock">
1918
+ <div class="content">
1919
+ <pre><tt>/apps/foo/ &lt;------ This is the Rails application's application root!
1920
+ |
1921
+ +- app/
1922
+ | |
1923
+ | +- controllers/
1924
+ | |
1925
+ | +- models/
1926
+ | |
1927
+ | +- views/
1928
+ |
1929
+ +- config/
1930
+ | |
1931
+ | +- environment.rb
1932
+ | |
1933
+ | +- ...
1934
+ |
1935
+ +- public/
1936
+ | |
1937
+ | +- ...
1938
+ |
1939
+ +- ...</tt></pre>
1940
+ </div></div>
1941
+ <div class="paragraph"><p>In case of Rack applications, this is the directory that contains <em>config.ru</em>.
1942
+ For example, take the following directory structure:</p></div>
1943
+ <div class="listingblock">
1944
+ <div class="content">
1945
+ <pre><tt>/apps/bar/ &lt;----- This is the Rack application's application root!
1946
+ |
1947
+ +- public/
1948
+ | |
1949
+ | +- ...
1950
+ |
1951
+ +- config.ru
1952
+ |
1953
+ +- ...</tt></pre>
1954
+ </div></div>
1955
+ <div class="paragraph"><p>In case of Python (WSGI) applications, this is the directory that contains
1956
+ <em>passenger_wsgi.py</em>. For example, take the following directory structure:</p></div>
1957
+ <div class="listingblock">
1958
+ <div class="content">
1959
+ <pre><tt>/apps/baz/ &lt;----- This is the WSGI application's application root!
1960
+ |
1961
+ +- public/
1962
+ | |
1963
+ | +- ...
1964
+ |
1965
+ +- passenger_wsgi.py
1966
+ |
1967
+ +- ...</tt></pre>
1968
+ </div></div>
1969
+ </div>
1970
+ <h2 id="spawning_methods_explained">10. Appendix C: Spawning methods explained</h2>
1971
+ <div class="sectionbody">
1972
+ <div class="paragraph"><p>At its core, Phusion Passenger is an HTTP proxy and process manager. It spawns
1973
+ Ruby on Rails/Rack/WSGI worker processes (which may also be referred to as
1974
+ <em>backend processes</em>), and forwards incoming HTTP request to one of the worker
1975
+ processes.</p></div>
1976
+ <div class="paragraph"><p>While this may sound simple, there&#8217;s not just one way to spawn worker processes.
1977
+ Let&#8217;s go over the different spawning methods. For simplicity&#8217;s sake, let&#8217;s
1978
+ assume that we&#8217;re only talking about Ruby on Rails applications.</p></div>
1979
+ <h3 id="_the_most_straightforward_and_traditional_way_conservative_spawning">10.1. The most straightforward and traditional way: conservative spawning</h3>
1980
+ <div class="paragraph"><p>Phusion Passenger could create a new Ruby process, which will then load the
1981
+ Rails application along with the entire Rails framework. This process will then
1982
+ enter an request handling main loop.</p></div>
1983
+ <div class="paragraph"><p>This is the most straightforward way to spawn worker processes. If you&#8217;re
1984
+ familiar with the Mongrel application server, then this approach is exactly
1985
+ what mongrel_cluster performs: it creates N worker processes, each which loads
1986
+ a full copy of the Rails application and the Rails framework in memory. The Thin
1987
+ application server employs pretty much the same approach.</p></div>
1988
+ <div class="paragraph"><p>Note that Phusion Passenger&#8217;s version of conservative spawning differs slightly
1989
+ from mongrel_cluster. Mongrel_cluster creates entirely new Ruby processes. In
1990
+ programmers jargon, mongrel_cluster creates new Ruby processes by forking the
1991
+ current process and exec()-ing a new Ruby interpreter. Phusion Passenger on the
1992
+ other hand creates processes that reuse the already loaded Ruby interpreter. In
1993
+ programmers jargon, Phusion Passenger calls fork(), but not exec().</p></div>
1994
+ <h3 id="_the_smart_spawning_method">10.2. The smart spawning method</h3>
1995
+ <div class="admonitionblock">
1996
+ <table><tr>
1997
+ <td class="icon">
1998
+ <img src="./images/icons/note.png" alt="Note" />
1999
+ </td>
2000
+ <td class="content">Smart spawning is only available for Ruby on Rails applications, not for
2001
+ Rack applications or WSGI applications.</td>
2002
+ </tr></table>
2003
+ </div>
2004
+ <div class="paragraph"><p>While conservative spawning works well, it&#8217;s not as efficient as it could be
2005
+ because each worker process has its own private copy of the Rails application
2006
+ as well as the Rails framework. This wastes memory as well as startup time.</p></div>
2007
+ <div class="paragraph"><p><span class="image">
2008
+ <img src="images/conservative_spawning.png" alt="Worker processes and conservative spawning" title="Worker processes and conservative spawning" />
2009
+ </span><br />
2010
+ <em>Figure: Worker processes and conservative spawning. Each worker process has its
2011
+ own private copy of the application code and Rails framework code.</em></p></div>
2012
+ <div class="paragraph"><p>It is possible to make the different worker processes share the memory occupied
2013
+ by application and Rails framework code, by utilizing so-called
2014
+ copy-on-write semantics of the virtual memory system on modern operating
2015
+ systems. As a side effect, the startup time is also reduced. This is technique
2016
+ is exploited by Phusion Passenger&#8217;s <em>smart</em> and <em>smart-lv2</em> spawn methods.</p></div>
2017
+ <h4 id="_how_it_works">10.2.1. How it works</h4>
2018
+ <div class="paragraph"><p>When the <em>smart-lv2</em> spawn method is being used, Phusion Passenger will first
2019
+ create a so-called <em>ApplicationSpawner server</em> process. This process loads the
2020
+ entire Rails application along with the Rails framework, by loading
2021
+ <em>environment.rb</em>. Then, whenever Phusion Passenger needs a new worker process,
2022
+ it will instruct the ApplicationSpawner server to do so. The ApplicationSpawner
2023
+ server will create a worker new process
2024
+ that reuses the already loaded Rails application/framework. Creating a worker
2025
+ process through an already running ApplicationSpawner server is very fast, about
2026
+ 10 times faster than loading the Rails application/framework from scratch. If
2027
+ the Ruby interpreter is copy-on-write friendly (that is, if you&#8217;re running
2028
+ <a href="#reducing_memory_usage">Ruby Enterprise Edition</a>) then all created worker
2029
+ processes will share as much common
2030
+ memory as possible. That is, they will all share the same application and Rails
2031
+ framework code.</p></div>
2032
+ <div class="paragraph"><p><span class="image">
2033
+ <img src="images/smart-lv2.png" alt="images/smart-lv2.png" />
2034
+ </span><br />
2035
+ <em>Figure: Worker processes and the smart-lv2 spawn method. All worker processes,
2036
+ as well as the ApplicationSpawner, share the same application code and Rails
2037
+ framework code.</em></p></div>
2038
+ <div class="paragraph"><p>The <em>smart</em> spawn method goes even further, by caching the Rails framework in
2039
+ another process called the <em>FrameworkSpawner server</em>. This process only loads
2040
+ the Rails framework, not the application. When a FrameworkSpawner server is
2041
+ instructed to create a new worker process, it will create a new
2042
+ ApplicationSpawner to which the instruction will be delegated. All those
2043
+ ApplicationSpawner servers, as well as all worker processes created by those
2044
+ ApplicationSpawner servers, will share the same Rails framework code.</p></div>
2045
+ <div class="paragraph"><p>The <em>smart-lv2</em> method allows different worker processes that belong to the same
2046
+ application to share memory. The <em>smart</em> method allows different worker
2047
+ processes - that happen to use the same Rails version - to share memory, even if
2048
+ they don&#8217;t belong to the same application.</p></div>
2049
+ <div class="paragraph"><p>Notes:</p></div>
2050
+ <div class="ulist"><ul>
2051
+ <li>
2052
+ <p>
2053
+ Vendored Rails frameworks cannot be shared by different applications, even if
2054
+ both vendored Rails frameworks are the same version. So for efficiency reasons
2055
+ we don&#8217;t recommend vendoring Rails.
2056
+ </p>
2057
+ </li>
2058
+ <li>
2059
+ <p>
2060
+ ApplicationSpawner and FrameworkSpawner servers have an idle timeout just
2061
+ like worker processes. If an ApplicationSpawner/FrameworkSpawner server hasn&#8217;t
2062
+ been instructed to do anything for a while, it will be shutdown in order to
2063
+ conserve memory. This idle timeout is configurable.
2064
+ </p>
2065
+ </li>
2066
+ </ul></div>
2067
+ <h4 id="_summary_of_benefits">10.2.2. Summary of benefits</h4>
2068
+ <div class="paragraph"><p>Suppose that Phusion Passenger needs a new worker process for an application
2069
+ that uses Rails 2.2.1.</p></div>
2070
+ <div class="ulist"><ul>
2071
+ <li>
2072
+ <p>
2073
+ If the <em>smart-lv2</em> spawning method is used, and an ApplicationSpawner server
2074
+ for this application is already running, then worker process creation time is
2075
+ about 10 times faster than conservative spawning. This worker process will also
2076
+ share application and Rails framework code memory with the ApplicationSpawner
2077
+ server and the worker processes that had been spawned by this ApplicationSpawner
2078
+ server.
2079
+ </p>
2080
+ </li>
2081
+ <li>
2082
+ <p>
2083
+ If the <em>smart</em> spawning method is used, and a FrameworkSpawner server for
2084
+ Rails 2.2.1 is already running, but no ApplicationSpawner server for this
2085
+ application is running, then worker process creation time is about 2 times
2086
+ faster than conservative spawning. If there is an ApplicationSpawner server
2087
+ for this application running, then worker process creation time is about 10
2088
+ times faster. This worker process will also share application and Rails
2089
+ framework code memory with the ApplicationSpawner and FrameworkSpawner
2090
+ servers.
2091
+ </p>
2092
+ </li>
2093
+ </ul></div>
2094
+ <div class="paragraph"><p>You could compare ApplicationSpawner and FrameworkSpawner servers with stem
2095
+ cells, that have the ability to quickly change into more specific cells (worker
2096
+ process).</p></div>
2097
+ <div class="paragraph"><p>In practice, the smart spawning methods could mean a memory saving of about 33%,
2098
+ assuming that your Ruby interpreter is <a href="#reducing_memory_usage">copy-on-write friendly</a>.</p></div>
2099
+ <div class="paragraph"><p>Of course, smart spawning is not without gotchas. But if you understand the
2100
+ gotchas you can easily reap the benefits of smart spawning.</p></div>
2101
+ <h3 id="_smart_spawning_gotcha_1_unintential_file_descriptor_sharing">10.3. Smart spawning gotcha #1: unintential file descriptor sharing</h3>
2102
+ <div class="paragraph"><p>Because worker processes are created by forking from an ApplicationSpawner
2103
+ server, it will share all file descriptors that are opened by the
2104
+ ApplicationSpawner server. (This is part of the semantics of the Unix
2105
+ <em>fork()</em> system call. You might want to Google it if you&#8217;re not familiar with
2106
+ it.) A file descriptor is a handle which can be an opened file, an opened socket
2107
+ connection, a pipe, etc. If different worker processes write to such a file
2108
+ descriptor at the same time, then their write calls will be interleaved, which
2109
+ may potentially cause problems.</p></div>
2110
+ <div class="paragraph"><p>The problem commonly involves socket connections that are unintentially being
2111
+ shared. You can fix it by closing and reestablishing the connection when Phusion
2112
+ Passenger is creating a new worker process. Phusion Passenger provides the API
2113
+ call <tt>PhusionPassenger.on_event(:starting_worker_process)</tt> to do so. So you
2114
+ could insert the following code in your <em>environment.rb</em>:</p></div>
2115
+ <div class="listingblock">
2116
+ <div class="content"><!-- Generator: GNU source-highlight 2.11.1
2117
+ by Lorenzo Bettini
2118
+ http://www.lorenzobettini.it
2119
+ http://www.gnu.org/software/src-highlite -->
2120
+ <pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
2121
+ PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
2122
+ <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
2123
+ <span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
2124
+ <span style="color: #990000">...</span> code to reestablish socket connections here <span style="color: #990000">...</span>
2125
+ <span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
2126
+ <span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
2127
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
2128
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
2129
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
2130
+ <div class="paragraph"><p>Note that Phusion Passenger automatically reestablishes the connection to the
2131
+ database upon creating a new worker process, which is why you normally do not
2132
+ encounter any database issues when using smart spawning mode.</p></div>
2133
+ <h4 id="_example_1_memcached_connection_sharing_harmful">10.3.1. Example 1: Memcached connection sharing (harmful)</h4>
2134
+ <div class="paragraph"><p>Suppose we have a Rails application that connects to a Memcached server in
2135
+ <em>environment.rb</em>. This causes the ApplicationSpawner to have a socket connection
2136
+ (file descriptor) to the Memcached server, as shown in the following figure:</p></div>
2137
+ <div class="literalblock">
2138
+ <div class="content">
2139
+ <pre><tt>+--------------------+
2140
+ | ApplicationSpawner |-----------[Memcached server]
2141
+ +--------------------+</tt></pre>
2142
+ </div></div>
2143
+ <div class="paragraph"><p>Phusion Passenger then proceeds with creating a new Rails worker process, which
2144
+ is to process incoming HTTP requests. The result will look like this:</p></div>
2145
+ <div class="literalblock">
2146
+ <div class="content">
2147
+ <pre><tt>+--------------------+
2148
+ | ApplicationSpawner |------+----[Memcached server]
2149
+ +--------------------+ |
2150
+ |
2151
+ +--------------------+ |
2152
+ | Worker process 1 |-----/
2153
+ +--------------------+</tt></pre>
2154
+ </div></div>
2155
+ <div class="paragraph"><p>Since a <em>fork()</em> makes a (virtual) complete copy of a process, all its file
2156
+ descriptors will be copied as well. What we see here is that ApplicationSpawner
2157
+ and Worker process 1 both share the same connection to Memcached.</p></div>
2158
+ <div class="paragraph"><p>Now supposed that your site gets Slashdotted and Phusion Passenger needs to
2159
+ spawn another worker process. It does so by forking ApplicationSpawner. The
2160
+ result is now as follows:</p></div>
2161
+ <div class="literalblock">
2162
+ <div class="content">
2163
+ <pre><tt>+--------------------+
2164
+ | ApplicationSpawner |------+----[Memcached server]
2165
+ +--------------------+ |
2166
+ |
2167
+ +--------------------+ |
2168
+ | Worker process 1 |-----/|
2169
+ +--------------------+ |
2170
+ |
2171
+ +--------------------+ |
2172
+ | Worker process 2 |-----/
2173
+ +--------------------+</tt></pre>
2174
+ </div></div>
2175
+ <div class="paragraph"><p>As you can see, Worker process 1 and Worker process 2 have the same Memcache
2176
+ connection.</p></div>
2177
+ <div class="paragraph"><p>Suppose that users Joe and Jane visit your website at the same time. Joe&#8217;s
2178
+ request is handled by Worker process 1, and Jane&#8217;s request is handled by Worker
2179
+ process 2. Both worker processes want to fetch something from Memcached. Suppose
2180
+ that in order to do that, both handlers need to send a "FETCH" command to Memcached.</p></div>
2181
+ <div class="paragraph"><p>But suppose that, after worker process 1 having only sent "FE", a context switch
2182
+ occurs, and worker process 2 starts sending a "FETCH" command to Memcached as
2183
+ well. If worker process 2 succeeds in sending only one bye, <em>F</em>, then Memcached
2184
+ will receive a command which begins with "FEF", a command that it does not
2185
+ recognize. In other words: the data from both handlers get interleaved. And thus
2186
+ Memcached is forced to handle this as an error.</p></div>
2187
+ <div class="paragraph"><p>This problem can be solved by reestablishing the connection to Memcached after forking:</p></div>
2188
+ <div class="literalblock">
2189
+ <div class="content">
2190
+ <pre><tt>+--------------------+
2191
+ | ApplicationSpawner |------+----[Memcached server]
2192
+ +--------------------+ | |
2193
+ | |
2194
+ +--------------------+ | |
2195
+ | Worker process 1 |-----/| |
2196
+ +--------------------+ | | &lt;--- created this
2197
+ X | new
2198
+ | connection
2199
+ X &lt;-- closed this |
2200
+ +--------------------+ | old |
2201
+ | Worker process 2 |-----/ connection |
2202
+ +--------------------+ |
2203
+ | |
2204
+ +-------------------------------------+</tt></pre>
2205
+ </div></div>
2206
+ <div class="paragraph"><p>Worker process 2 now has its own, separate communication channel with Memcached.
2207
+ The code in <em>environment.rb</em> looks like this:</p></div>
2208
+ <div class="listingblock">
2209
+ <div class="content"><!-- Generator: GNU source-highlight 2.11.1
2210
+ by Lorenzo Bettini
2211
+ http://www.lorenzobettini.it
2212
+ http://www.gnu.org/software/src-highlite -->
2213
+ <pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
2214
+ PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
2215
+ <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
2216
+ <span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
2217
+ reestablish_connection_to_memcached
2218
+ <span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
2219
+ <span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
2220
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
2221
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
2222
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
2223
+ <h4 id="_example_2_log_file_sharing_not_harmful">10.3.2. Example 2: Log file sharing (not harmful)</h4>
2224
+ <div class="paragraph"><p>There are also cases in which unintential file descriptor sharing is not harmful.
2225
+ One such case is log file file descriptor sharing. Even if two processes write
2226
+ to the log file at the same time, the worst thing that can happen is that the
2227
+ data in the log file is interleaved.</p></div>
2228
+ <div class="paragraph"><p>To guarantee that the data written to the log file is never interleaved, you
2229
+ must synchronize write access via an inter-process synchronization mechanism,
2230
+ such as file locks. Reopening the log file, like you would have done in the
2231
+ Memcached example, doesn&#8217;t help.</p></div>
2232
+ <h3 id="_smart_spawning_gotcha_2_the_need_to_revive_threads">10.4. Smart spawning gotcha #2: the need to revive threads</h3>
2233
+ <div class="paragraph"><p>Another part of the <em>fork()</em> system call&#8217;s semantics is the fact that threads
2234
+ disappear after a fork call. So if you&#8217;ve created any threads in environment.rb,
2235
+ then those threads will no longer be running in newly created worker process.
2236
+ You need to revive them when a new worker process is created. Use the
2237
+ <tt>:starting_worker_process</tt> event that Phusion Passenger provides, like this:</p></div>
2238
+ <div class="listingblock">
2239
+ <div class="content"><!-- Generator: GNU source-highlight 2.11.1
2240
+ by Lorenzo Bettini
2241
+ http://www.lorenzobettini.it
2242
+ http://www.gnu.org/software/src-highlite -->
2243
+ <pre><tt><span style="font-weight: bold"><span style="color: #0000FF">if</span></span> <span style="font-weight: bold"><span style="color: #0000FF">defined</span></span><span style="color: #990000">?(</span>PhusionPassenger<span style="color: #990000">)</span>
2244
+ PhusionPassenger<span style="color: #990000">.</span>on_event<span style="color: #990000">(:</span>starting_worker_process<span style="color: #990000">)</span> <span style="font-weight: bold"><span style="color: #0000FF">do</span></span> <span style="color: #990000">|</span>forked<span style="color: #990000">|</span>
2245
+ <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
2246
+ <span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
2247
+ <span style="color: #990000">...</span> code to revive threads here <span style="color: #990000">...</span>
2248
+ <span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
2249
+ <span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
2250
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
2251
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
2252
+ <span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
2253
+ <h3 id="_smart_spawning_gotcha_3_code_load_order">10.5. Smart spawning gotcha #3: code load order</h3>
2254
+ <div class="paragraph"><p>This gotcha is only applicable to the <em>smart</em> spawn method, not the <em>smart-lv2</em>
2255
+ spawn method.</p></div>
2256
+ <div class="paragraph"><p>If your application expects the Rails framework to be not loaded during the
2257
+ beginning of <em>environment.rb</em>, then it can cause problems when an
2258
+ ApplicationSpawner is created from a FrameworkSpawner, which already has the
2259
+ Rails framework loaded. The most common case is when applications try to patch
2260
+ Rails by dropping a modified file that has the same name as Rails&#8217;s own file,
2261
+ in a path that comes earlier in the Ruby search path.</p></div>
2262
+ <div class="paragraph"><p>For example, suppose that we have an application which has a patched version
2263
+ of <em>active_record/base.rb</em> located in <em>RAILS_ROOT/lib/patches</em>, and
2264
+ <em>RAILS_ROOT/lib/patches</em> comes first in the Ruby load path. When conservative
2265
+ spawning is used, the patched version of <em>base.rb</em> is properly loaded. When
2266
+ <em>smart</em> (not <em>smart-lv2</em>) spawning is used, the original <em>base.rb</em> is used
2267
+ because it was already loaded, so a subsequent <tt>require "active_record/base"</tt>
2268
+ has no effect.</p></div>
2269
+ </div>
2270
+ <div id="footer">
2271
+ <div id="footer-text">
2272
+ Last updated 2009-04-16 19:42:11 CEST
2273
+ </div>
2274
+ </div>
2275
+ </body>
2276
+ </html>