passenger 2.1.2 → 2.1.3

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 (244) hide show
  1. data/Rakefile +7 -5
  2. data/doc/Architectural overview.html +729 -1
  3. data/doc/Architectural overview.txt +0 -5
  4. data/doc/Security of user switching support.html +605 -1
  5. data/doc/Users guide.html +110 -106
  6. data/doc/Users guide.txt +49 -0
  7. data/doc/cxxapi/ApplicationPoolServer_8h-source.html +400 -372
  8. data/doc/cxxapi/ApplicationPool_8h-source.html +1 -1
  9. data/doc/cxxapi/Application_8h-source.html +1 -1
  10. data/doc/cxxapi/Bucket_8h-source.html +1 -1
  11. data/doc/cxxapi/CachedFileStat_8h-source.html +56 -65
  12. data/doc/cxxapi/Configuration_8h-source.html +40 -32
  13. data/doc/cxxapi/DirectoryMapper_8h-source.html +1 -1
  14. data/doc/cxxapi/DummySpawnManager_8h-source.html +1 -1
  15. data/doc/cxxapi/Exceptions_8h-source.html +1 -1
  16. data/doc/cxxapi/FileChecker_8h-source.html +29 -30
  17. data/doc/cxxapi/Hooks_8h-source.html +1 -1
  18. data/doc/cxxapi/Logging_8h-source.html +1 -1
  19. data/doc/cxxapi/MessageChannel_8h-source.html +1 -1
  20. data/doc/cxxapi/PoolOptions_8h-source.html +1 -1
  21. data/doc/cxxapi/SpawnManager_8h-source.html +225 -219
  22. data/doc/cxxapi/StandardApplicationPool_8h-source.html +451 -445
  23. data/doc/cxxapi/SystemTime_8h-source.html +1 -1
  24. data/doc/cxxapi/Utils_8h-source.html +201 -140
  25. data/doc/cxxapi/annotated.html +2 -2
  26. data/doc/cxxapi/classClient-members.html +1 -1
  27. data/doc/cxxapi/classClient.html +1 -1
  28. data/doc/cxxapi/classHooks-members.html +1 -1
  29. data/doc/cxxapi/classHooks.html +1 -1
  30. data/doc/cxxapi/classPassenger_1_1Application-members.html +1 -1
  31. data/doc/cxxapi/classPassenger_1_1Application.html +1 -1
  32. data/doc/cxxapi/classPassenger_1_1ApplicationPool-members.html +1 -1
  33. data/doc/cxxapi/classPassenger_1_1ApplicationPool.html +1 -1
  34. data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer-members.html +1 -1
  35. data/doc/cxxapi/classPassenger_1_1ApplicationPoolServer.html +1 -1
  36. data/doc/cxxapi/classPassenger_1_1ApplicationPool__inherit__graph.png +0 -0
  37. data/doc/cxxapi/classPassenger_1_1Application_1_1Session-members.html +1 -1
  38. data/doc/cxxapi/classPassenger_1_1Application_1_1Session.html +1 -1
  39. data/doc/cxxapi/{classPassenger_1_1TempFile-members.html → classPassenger_1_1BufferedUpload-members.html} +5 -5
  40. data/doc/cxxapi/{classPassenger_1_1TempFile.html → classPassenger_1_1BufferedUpload.html} +33 -43
  41. data/doc/cxxapi/classPassenger_1_1BusyException-members.html +1 -1
  42. data/doc/cxxapi/classPassenger_1_1BusyException.html +1 -1
  43. data/doc/cxxapi/classPassenger_1_1ConfigurationException-members.html +1 -1
  44. data/doc/cxxapi/classPassenger_1_1ConfigurationException.html +1 -1
  45. data/doc/cxxapi/classPassenger_1_1DirectoryMapper-members.html +1 -1
  46. data/doc/cxxapi/classPassenger_1_1DirectoryMapper.html +1 -1
  47. data/doc/cxxapi/classPassenger_1_1DummySpawnManager-members.html +1 -1
  48. data/doc/cxxapi/classPassenger_1_1DummySpawnManager.html +1 -1
  49. data/doc/cxxapi/classPassenger_1_1FileChecker-members.html +1 -1
  50. data/doc/cxxapi/classPassenger_1_1FileChecker.html +2 -2
  51. data/doc/cxxapi/classPassenger_1_1FileNotFoundException-members.html +1 -1
  52. data/doc/cxxapi/classPassenger_1_1FileNotFoundException.html +1 -1
  53. data/doc/cxxapi/classPassenger_1_1FileNotFoundException__inherit__graph.png +0 -0
  54. data/doc/cxxapi/classPassenger_1_1FileSystemException-members.html +1 -1
  55. data/doc/cxxapi/classPassenger_1_1FileSystemException.html +1 -1
  56. data/doc/cxxapi/classPassenger_1_1FileSystemException__inherit__graph.png +0 -0
  57. data/doc/cxxapi/classPassenger_1_1IOException-members.html +1 -1
  58. data/doc/cxxapi/classPassenger_1_1IOException.html +1 -1
  59. data/doc/cxxapi/classPassenger_1_1IOException__inherit__graph.png +0 -0
  60. data/doc/cxxapi/classPassenger_1_1MessageChannel-members.html +1 -1
  61. data/doc/cxxapi/classPassenger_1_1MessageChannel.html +1 -1
  62. data/doc/cxxapi/classPassenger_1_1RuntimeException-members.html +1 -1
  63. data/doc/cxxapi/classPassenger_1_1RuntimeException.html +1 -1
  64. data/doc/cxxapi/classPassenger_1_1SpawnException-members.html +1 -1
  65. data/doc/cxxapi/classPassenger_1_1SpawnException.html +1 -1
  66. data/doc/cxxapi/classPassenger_1_1SpawnManager-members.html +1 -1
  67. data/doc/cxxapi/classPassenger_1_1SpawnManager.html +1 -1
  68. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool-members.html +1 -1
  69. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool.html +1 -1
  70. data/doc/cxxapi/classPassenger_1_1StandardApplicationPool__inherit__graph.png +0 -0
  71. data/doc/cxxapi/classPassenger_1_1SystemException-members.html +1 -1
  72. data/doc/cxxapi/classPassenger_1_1SystemException.html +1 -1
  73. data/doc/cxxapi/classPassenger_1_1SystemException__inherit__graph.png +0 -0
  74. data/doc/cxxapi/classPassenger_1_1SystemTime-members.html +1 -1
  75. data/doc/cxxapi/classPassenger_1_1SystemTime.html +1 -1
  76. data/doc/cxxapi/definitions_8h-source.html +1 -1
  77. data/doc/cxxapi/files.html +1 -1
  78. data/doc/cxxapi/functions.html +12 -11
  79. data/doc/cxxapi/functions_func.html +9 -7
  80. data/doc/cxxapi/functions_type.html +1 -1
  81. data/doc/cxxapi/functions_vars.html +2 -4
  82. data/doc/cxxapi/graph_legend.html +1 -1
  83. data/doc/cxxapi/graph_legend.png +0 -0
  84. data/doc/cxxapi/group__Configuration.html +3 -3
  85. data/doc/cxxapi/group__Configuration.png +0 -0
  86. data/doc/cxxapi/group__Core.html +1 -1
  87. data/doc/cxxapi/group__Core.png +0 -0
  88. data/doc/cxxapi/group__Exceptions.html +1 -1
  89. data/doc/cxxapi/group__Hooks.html +1 -1
  90. data/doc/cxxapi/group__Hooks.png +0 -0
  91. data/doc/cxxapi/group__Support.html +33 -16
  92. data/doc/cxxapi/hierarchy.html +2 -2
  93. data/doc/cxxapi/inherit__graph__0.png +0 -0
  94. data/doc/cxxapi/inherit__graph__1.png +0 -0
  95. data/doc/cxxapi/inherit__graph__10.map +1 -1
  96. data/doc/cxxapi/inherit__graph__10.md5 +1 -1
  97. data/doc/cxxapi/inherit__graph__10.png +0 -0
  98. data/doc/cxxapi/inherit__graph__11.map +1 -1
  99. data/doc/cxxapi/inherit__graph__11.md5 +1 -1
  100. data/doc/cxxapi/inherit__graph__11.png +0 -0
  101. data/doc/cxxapi/inherit__graph__12.map +1 -2
  102. data/doc/cxxapi/inherit__graph__12.md5 +1 -1
  103. data/doc/cxxapi/inherit__graph__12.png +0 -0
  104. data/doc/cxxapi/inherit__graph__13.map +2 -1
  105. data/doc/cxxapi/inherit__graph__13.md5 +1 -1
  106. data/doc/cxxapi/inherit__graph__13.png +0 -0
  107. data/doc/cxxapi/inherit__graph__14.map +1 -1
  108. data/doc/cxxapi/inherit__graph__14.md5 +1 -1
  109. data/doc/cxxapi/inherit__graph__14.png +0 -0
  110. data/doc/cxxapi/inherit__graph__15.map +1 -1
  111. data/doc/cxxapi/inherit__graph__15.md5 +1 -1
  112. data/doc/cxxapi/inherit__graph__15.png +0 -0
  113. data/doc/cxxapi/inherit__graph__16.map +1 -1
  114. data/doc/cxxapi/inherit__graph__16.md5 +1 -1
  115. data/doc/cxxapi/inherit__graph__16.png +0 -0
  116. data/doc/cxxapi/inherit__graph__17.map +1 -1
  117. data/doc/cxxapi/inherit__graph__17.md5 +1 -1
  118. data/doc/cxxapi/inherit__graph__17.png +0 -0
  119. data/doc/cxxapi/inherit__graph__18.map +1 -1
  120. data/doc/cxxapi/inherit__graph__18.md5 +1 -1
  121. data/doc/cxxapi/inherit__graph__18.png +0 -0
  122. data/doc/cxxapi/inherit__graph__19.map +1 -2
  123. data/doc/cxxapi/inherit__graph__19.md5 +1 -1
  124. data/doc/cxxapi/inherit__graph__19.png +0 -0
  125. data/doc/cxxapi/inherit__graph__2.png +0 -0
  126. data/doc/cxxapi/inherit__graph__20.map +2 -1
  127. data/doc/cxxapi/inherit__graph__20.md5 +1 -1
  128. data/doc/cxxapi/inherit__graph__20.png +0 -0
  129. data/doc/cxxapi/inherit__graph__21.map +1 -1
  130. data/doc/cxxapi/inherit__graph__21.md5 +1 -1
  131. data/doc/cxxapi/inherit__graph__21.png +0 -0
  132. data/doc/cxxapi/inherit__graph__3.png +0 -0
  133. data/doc/cxxapi/inherit__graph__4.png +0 -0
  134. data/doc/cxxapi/inherit__graph__5.png +0 -0
  135. data/doc/cxxapi/inherit__graph__6.png +0 -0
  136. data/doc/cxxapi/inherit__graph__7.map +1 -1
  137. data/doc/cxxapi/inherit__graph__7.md5 +1 -1
  138. data/doc/cxxapi/inherit__graph__7.png +0 -0
  139. data/doc/cxxapi/inherit__graph__8.map +1 -1
  140. data/doc/cxxapi/inherit__graph__8.md5 +1 -1
  141. data/doc/cxxapi/inherit__graph__8.png +0 -0
  142. data/doc/cxxapi/inherit__graph__9.map +1 -1
  143. data/doc/cxxapi/inherit__graph__9.md5 +1 -1
  144. data/doc/cxxapi/inherit__graph__9.png +0 -0
  145. data/doc/cxxapi/inherits.html +18 -18
  146. data/doc/cxxapi/main.html +1 -1
  147. data/doc/cxxapi/modules.html +1 -1
  148. data/doc/cxxapi/structPassenger_1_1AnythingToString-members.html +1 -1
  149. data/doc/cxxapi/structPassenger_1_1AnythingToString.html +1 -1
  150. data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4-members.html +1 -1
  151. data/doc/cxxapi/structPassenger_1_1AnythingToString_3_01vector_3_01string_01_4_01_4.html +1 -1
  152. data/doc/cxxapi/structPassenger_1_1PoolOptions-members.html +1 -1
  153. data/doc/cxxapi/structPassenger_1_1PoolOptions.html +1 -1
  154. data/doc/cxxapi/tree.html +4 -4
  155. data/doc/rdoc/classes/ConditionVariable.html +58 -58
  156. data/doc/rdoc/classes/Exception.html +11 -11
  157. data/doc/rdoc/classes/GC.html +4 -4
  158. data/doc/rdoc/classes/IO.html +14 -14
  159. data/doc/rdoc/classes/PhusionPassenger.html +11 -11
  160. data/doc/rdoc/classes/PhusionPassenger/AdminTools.html +1 -1
  161. data/doc/rdoc/classes/PhusionPassenger/AdminTools/ControlProcess.html +40 -39
  162. data/doc/rdoc/classes/PhusionPassenger/Application.html +14 -14
  163. data/doc/rdoc/classes/PhusionPassenger/HTMLTemplate.html +12 -12
  164. data/doc/rdoc/classes/PhusionPassenger/Railz.html +1 -1
  165. data/doc/rdoc/classes/PhusionPassenger/Utils.html +15 -8
  166. data/doc/rdoc/classes/PlatformInfo.html +257 -253
  167. data/doc/rdoc/classes/RakeExtensions.html +2 -2
  168. data/doc/rdoc/classes/Signal.html +26 -26
  169. data/doc/rdoc/created.rid +1 -1
  170. data/doc/rdoc/files/DEVELOPERS_TXT.html +1 -1
  171. data/doc/rdoc/files/README.html +1 -1
  172. data/doc/rdoc/files/ext/phusion_passenger/native_support_c.html +1 -1
  173. data/doc/rdoc/files/lib/phusion_passenger/abstract_request_handler_rb.html +1 -1
  174. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_collection_rb.html +1 -1
  175. data/doc/rdoc/files/lib/phusion_passenger/abstract_server_rb.html +1 -1
  176. data/doc/rdoc/files/lib/phusion_passenger/admin_tools/control_process_rb.html +1 -1
  177. data/doc/rdoc/files/lib/phusion_passenger/admin_tools_rb.html +1 -1
  178. data/doc/rdoc/files/lib/phusion_passenger/application_rb.html +1 -1
  179. data/doc/rdoc/files/lib/phusion_passenger/console_text_template_rb.html +1 -1
  180. data/doc/rdoc/files/lib/phusion_passenger/constants_rb.html +1 -1
  181. data/doc/rdoc/files/lib/phusion_passenger/dependencies_rb.html +1 -1
  182. data/doc/rdoc/files/lib/phusion_passenger/events_rb.html +1 -1
  183. data/doc/rdoc/files/lib/phusion_passenger/exceptions_rb.html +1 -1
  184. data/doc/rdoc/files/lib/phusion_passenger/html_template_rb.html +1 -1
  185. data/doc/rdoc/files/lib/phusion_passenger/message_channel_rb.html +1 -1
  186. data/doc/rdoc/files/lib/phusion_passenger/platform_info_rb.html +1 -1
  187. data/doc/rdoc/files/lib/phusion_passenger/rack/application_spawner_rb.html +1 -1
  188. data/doc/rdoc/files/lib/phusion_passenger/rack/request_handler_rb.html +1 -1
  189. data/doc/rdoc/files/lib/phusion_passenger/railz/application_spawner_rb.html +1 -1
  190. data/doc/rdoc/files/lib/phusion_passenger/railz/cgi_fixed_rb.html +1 -1
  191. data/doc/rdoc/files/lib/phusion_passenger/railz/framework_spawner_rb.html +1 -1
  192. data/doc/rdoc/files/lib/phusion_passenger/railz/request_handler_rb.html +1 -1
  193. data/doc/rdoc/files/lib/phusion_passenger/simple_benchmarking_rb.html +1 -1
  194. data/doc/rdoc/files/lib/phusion_passenger/spawn_manager_rb.html +1 -1
  195. data/doc/rdoc/files/lib/phusion_passenger/utils_rb.html +9 -9
  196. data/doc/rdoc/files/lib/phusion_passenger/wsgi/application_spawner_rb.html +1 -1
  197. data/doc/rdoc/files/{lib → misc}/rake/extensions_rb.html +2 -2
  198. data/doc/rdoc/fr_file_index.html +1 -1
  199. data/doc/rdoc/fr_method_index.html +22 -22
  200. data/ext/apache2/ApplicationPoolServer.h +43 -15
  201. data/ext/apache2/ApplicationPoolServerExecutable.cpp +27 -52
  202. data/ext/apache2/CachedFileStat.h +7 -16
  203. data/ext/apache2/Configuration.h +9 -1
  204. data/ext/apache2/FileChecker.h +4 -5
  205. data/ext/apache2/Hooks.cpp +20 -22
  206. data/ext/apache2/SpawnManager.h +6 -0
  207. data/ext/apache2/StandardApplicationPool.h +6 -0
  208. data/ext/apache2/Utils.cpp +174 -16
  209. data/ext/apache2/Utils.h +99 -38
  210. data/ext/boost/cstdint.hpp +2 -1
  211. data/ext/oxt/system_calls.cpp +20 -2
  212. data/ext/oxt/system_calls.hpp +2 -0
  213. data/lib/phusion_passenger/abstract_request_handler.rb +5 -1
  214. data/lib/phusion_passenger/admin_tools.rb +1 -1
  215. data/lib/phusion_passenger/admin_tools/control_process.rb +2 -1
  216. data/lib/phusion_passenger/dependencies.rb +7 -4
  217. data/lib/phusion_passenger/platform_info.rb +8 -2
  218. data/lib/phusion_passenger/rack/application_spawner.rb +1 -1
  219. data/lib/phusion_passenger/templates/version_not_found.html.erb +9 -0
  220. data/lib/phusion_passenger/utils.rb +13 -6
  221. data/lib/phusion_passenger/wsgi/application_spawner.rb +1 -1
  222. data/{lib → misc}/rake/cplusplus.rb +0 -0
  223. data/{lib → misc}/rake/extensions.rb +0 -0
  224. data/{lib → misc}/rake/gempackagetask.rb +0 -0
  225. data/{lib → misc}/rake/packagetask.rb +0 -0
  226. data/{lib → misc}/rake/rdoctask.rb +0 -0
  227. data/misc/render_error_pages.rb +6 -5
  228. data/test/CxxTestMain.cpp +109 -7
  229. data/test/UtilsTest.cpp +61 -51
  230. data/test/config.yml.example +6 -2
  231. data/test/integration_tests.rb +4 -0
  232. data/test/ruby/abstract_request_handler_spec.rb +9 -3
  233. data/test/ruby/rack/application_spawner_spec.rb +3 -2
  234. data/test/ruby/rails/application_spawner_spec.rb +15 -4
  235. data/test/ruby/rails/framework_spawner_spec.rb +4 -2
  236. data/test/ruby/rails/spawner_error_handling_spec.rb +4 -4
  237. data/test/ruby/spawn_manager_spec.rb +22 -9
  238. data/test/ruby/utils_spec.rb +18 -12
  239. data/test/ruby/wsgi/application_spawner_spec.rb +16 -7
  240. data/test/stub/apache2/httpd.conf.erb +1 -0
  241. data/test/stub/wsgi/passenger_wsgi.pyc +0 -0
  242. metadata +1064 -1090
  243. data/doc/Users guide Apache.html +0 -3127
  244. data/doc/Users guide Nginx.html +0 -1458
@@ -1,1458 +0,0 @@
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.3.4" />
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-right: 10%;
122
- margin-top: 1.5em;
123
- margin-bottom: 1.5em;
124
- }
125
- div.admonitionblock {
126
- margin-top: 2.5em;
127
- margin-bottom: 2.5em;
128
- }
129
-
130
- div.content { /* Block element content. */
131
- padding: 0;
132
- }
133
-
134
- /* Block element titles. */
135
- div.title, caption.title {
136
- color: #527bbd;
137
- font-family: sans-serif;
138
- font-weight: bold;
139
- text-align: left;
140
- margin-top: 1.0em;
141
- margin-bottom: 0.5em;
142
- }
143
- div.title + * {
144
- margin-top: 0;
145
- }
146
-
147
- td div.title:first-child {
148
- margin-top: 0.0em;
149
- }
150
- div.content div.title:first-child {
151
- margin-top: 0.0em;
152
- }
153
- div.content + div.title {
154
- margin-top: 0.0em;
155
- }
156
-
157
- div.sidebarblock > div.content {
158
- background: #ffffee;
159
- border: 1px solid silver;
160
- padding: 0.5em;
161
- }
162
-
163
- div.listingblock {
164
- margin-right: 0%;
165
- }
166
- div.listingblock > div.content {
167
- border: 1px solid silver;
168
- background: #f4f4f4;
169
- padding: 0.5em;
170
- }
171
-
172
- div.quoteblock {
173
- padding-left: 2.0em;
174
- }
175
- div.quoteblock > div.attribution {
176
- padding-top: 0.5em;
177
- text-align: right;
178
- }
179
-
180
- div.verseblock {
181
- padding-left: 2.0em;
182
- }
183
- div.verseblock > div.content {
184
- white-space: pre;
185
- }
186
- div.verseblock > div.attribution {
187
- padding-top: 0.75em;
188
- text-align: left;
189
- }
190
- /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
191
- div.verseblock + div.attribution {
192
- text-align: left;
193
- }
194
-
195
- div.admonitionblock .icon {
196
- vertical-align: top;
197
- font-size: 1.1em;
198
- font-weight: bold;
199
- text-decoration: underline;
200
- color: #527bbd;
201
- padding-right: 0.5em;
202
- }
203
- div.admonitionblock td.content {
204
- padding-left: 0.5em;
205
- border-left: 2px solid silver;
206
- }
207
-
208
- div.exampleblock > div.content {
209
- border-left: 2px solid silver;
210
- padding: 0.5em;
211
- }
212
-
213
- div.imageblock div.content { padding-left: 0; }
214
- div.imageblock img { border: 1px solid silver; }
215
- span.image img { border-style: none; }
216
-
217
- dl {
218
- margin-top: 0.8em;
219
- margin-bottom: 0.8em;
220
- }
221
- dt {
222
- margin-top: 0.5em;
223
- margin-bottom: 0;
224
- font-style: normal;
225
- color: navy;
226
- }
227
- dd > *:first-child {
228
- margin-top: 0.1em;
229
- }
230
-
231
- ul, ol {
232
- list-style-position: outside;
233
- }
234
- ol.arabic {
235
- list-style-type: decimal;
236
- }
237
- ol.loweralpha {
238
- list-style-type: lower-alpha;
239
- }
240
- ol.upperalpha {
241
- list-style-type: upper-alpha;
242
- }
243
- ol.lowerroman {
244
- list-style-type: lower-roman;
245
- }
246
- ol.upperroman {
247
- list-style-type: upper-roman;
248
- }
249
-
250
- div.compact ul, div.compact ol,
251
- div.compact p, div.compact p,
252
- div.compact div, div.compact div {
253
- margin-top: 0.1em;
254
- margin-bottom: 0.1em;
255
- }
256
-
257
- div.tableblock > table {
258
- border: 3px solid #527bbd;
259
- }
260
- thead {
261
- font-family: sans-serif;
262
- font-weight: bold;
263
- }
264
- tfoot {
265
- font-weight: bold;
266
- }
267
- td > div.verse {
268
- white-space: pre;
269
- }
270
- p.table {
271
- margin-top: 0;
272
- }
273
- /* Because the table frame attribute is overriden by CSS in most browsers. */
274
- div.tableblock > table[frame="void"] {
275
- border-style: none;
276
- }
277
- div.tableblock > table[frame="hsides"] {
278
- border-left-style: none;
279
- border-right-style: none;
280
- }
281
- div.tableblock > table[frame="vsides"] {
282
- border-top-style: none;
283
- border-bottom-style: none;
284
- }
285
-
286
-
287
- div.hdlist {
288
- margin-top: 0.8em;
289
- margin-bottom: 0.8em;
290
- }
291
- div.hdlist tr {
292
- padding-bottom: 15px;
293
- }
294
- dt.hdlist1.strong, td.hdlist1.strong {
295
- font-weight: bold;
296
- }
297
- td.hdlist1 {
298
- vertical-align: top;
299
- font-style: normal;
300
- padding-right: 0.8em;
301
- color: navy;
302
- }
303
- td.hdlist2 {
304
- vertical-align: top;
305
- }
306
- div.hdlist.compact tr {
307
- margin: 0;
308
- padding-bottom: 0;
309
- }
310
-
311
- .comment {
312
- background: yellow;
313
- }
314
-
315
- @media print {
316
- div#footer-badges { display: none; }
317
- }
318
-
319
- div#toctitle {
320
- color: #527bbd;
321
- font-family: sans-serif;
322
- font-size: 1.1em;
323
- font-weight: bold;
324
- margin-top: 1.0em;
325
- margin-bottom: 0.1em;
326
- }
327
-
328
- div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
329
- margin-top: 0;
330
- margin-bottom: 0;
331
- }
332
- div.toclevel2 {
333
- margin-left: 2em;
334
- font-size: 0.9em;
335
- }
336
- div.toclevel3 {
337
- margin-left: 4em;
338
- font-size: 0.9em;
339
- }
340
- div.toclevel4 {
341
- margin-left: 6em;
342
- font-size: 0.9em;
343
- }
344
- /* Workarounds for IE6's broken and incomplete CSS2. */
345
-
346
- div.sidebar-content {
347
- background: #ffffee;
348
- border: 1px solid silver;
349
- padding: 0.5em;
350
- }
351
- div.sidebar-title, div.image-title {
352
- color: #527bbd;
353
- font-family: sans-serif;
354
- font-weight: bold;
355
- margin-top: 0.0em;
356
- margin-bottom: 0.5em;
357
- }
358
-
359
- div.listingblock div.content {
360
- border: 1px solid silver;
361
- background: #f4f4f4;
362
- padding: 0.5em;
363
- }
364
-
365
- div.quoteblock-attribution {
366
- padding-top: 0.5em;
367
- text-align: right;
368
- }
369
-
370
- div.verseblock-content {
371
- white-space: pre;
372
- }
373
- div.verseblock-attribution {
374
- padding-top: 0.75em;
375
- text-align: left;
376
- }
377
-
378
- div.exampleblock-content {
379
- border-left: 2px solid silver;
380
- padding-left: 0.5em;
381
- }
382
-
383
- /* IE6 sets dynamically generated links as visited. */
384
- div#toc a:visited { color: blue; }
385
- </style>
386
- <script type="text/javascript">
387
- /*<![CDATA[*/
388
- window.onload = function(){generateToc(3)}
389
- /* Author: Mihai Bazon, September 2002
390
- * http://students.infoiasi.ro/~mishoo
391
- *
392
- * Table Of Content generator
393
- * Version: 0.4
394
- *
395
- * Feel free to use this script under the terms of the GNU General Public
396
- * License, as long as you do not remove or alter this notice.
397
- */
398
-
399
- /* modified by Troy D. Hanson, September 2006. License: GPL */
400
- /* modified by Stuart Rackham, October 2006. License: GPL */
401
-
402
- function getText(el) {
403
- var text = "";
404
- for (var i = el.firstChild; i != null; i = i.nextSibling) {
405
- if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
406
- text += i.data;
407
- else if (i.firstChild != null)
408
- text += getText(i);
409
- }
410
- return text;
411
- }
412
-
413
- function TocEntry(el, text, toclevel) {
414
- this.element = el;
415
- this.text = text;
416
- this.toclevel = toclevel;
417
- }
418
-
419
- function tocEntries(el, toclevels) {
420
- var result = new Array;
421
- var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
422
- // Function that scans the DOM tree for header elements (the DOM2
423
- // nodeIterator API would be a better technique but not supported by all
424
- // browsers).
425
- var iterate = function (el) {
426
- for (var i = el.firstChild; i != null; i = i.nextSibling) {
427
- if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
428
- var mo = re.exec(i.tagName)
429
- if (mo)
430
- result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
431
- iterate(i);
432
- }
433
- }
434
- }
435
- iterate(el);
436
- return result;
437
- }
438
-
439
- // This function does the work. toclevels = 1..4.
440
- function generateToc(toclevels) {
441
- var toc = document.getElementById("toc");
442
- var entries = tocEntries(document.getElementsByTagName("body")[0], toclevels);
443
- for (var i = 0; i < entries.length; ++i) {
444
- var entry = entries[i];
445
- if (entry.element.id == "")
446
- entry.element.id = "toc" + i;
447
- var a = document.createElement("a");
448
- a.href = "#" + entry.element.id;
449
- a.appendChild(document.createTextNode(entry.text));
450
- var div = document.createElement("div");
451
- div.appendChild(a);
452
- div.className = "toclevel" + entry.toclevel;
453
- toc.appendChild(div);
454
- }
455
- if (entries.length == 0)
456
- document.getElementById("header").removeChild(toc);
457
- }
458
- /*]]>*/
459
- </script>
460
- </head>
461
- <body>
462
- <div id="header">
463
- <h1>Phusion Passenger users guide, Nginx version</h1>
464
- <div id="toc">
465
- <div id="toctitle">Table of Contents</div>
466
- <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
467
- </div>
468
- </div>
469
- <div id="preamble">
470
- <div class="sectionbody">
471
- <div class="paragraph"><p><span class="image">
472
- <a class="image" href="http://www.phusion.nl/">
473
- <img src="images/phusion_banner.png" alt="images/phusion_banner.png" />
474
- </a>
475
- </span></p></div>
476
- <div class="paragraph"><p>Phusion Passenger is an Nginx module, which makes deploying Ruby and Ruby on
477
- Rails applications on Nginx a breeze. It follows the usual Ruby on Rails
478
- conventions, such as "Don&#8217;t-Repeat-Yourself" and ease of setup, while at the
479
- same time providing enough flexibility.</p></div>
480
- <div class="paragraph"><p>This users guide will teach you:</p></div>
481
- <div class="ulist"><ul>
482
- <li>
483
- <p>
484
- How to install Nginx with Phusion Passenger support.
485
- </p>
486
- </li>
487
- <li>
488
- <p>
489
- How to configure Phusion Passenger.
490
- </p>
491
- </li>
492
- <li>
493
- <p>
494
- How to deploy a Ruby on Rails application.
495
- </p>
496
- </li>
497
- <li>
498
- <p>
499
- How to deploy a <a href="http://rack.rubyforge.org/">Rack</a>-based Ruby application.
500
- </p>
501
- </li>
502
- <li>
503
- <p>
504
- How to solve common problems.
505
- </p>
506
- </li>
507
- </ul></div>
508
- <div class="paragraph"><p>This guide assumes that the reader is somewhat familiar with Nginx and with
509
- using the commandline.</p></div>
510
- </div>
511
- </div>
512
- <h2 id="_supported_operating_systems">1. Supported operating systems</h2>
513
- <div class="sectionbody">
514
- <div class="paragraph"><p>Phusion Passenger works on any POSIX-compliant operating system. In other
515
- words: practically any operating system on earth, except Microsoft Windows.</p></div>
516
- <div class="paragraph"><p>Phusion Passenger for Nginx has been tested on:</p></div>
517
- <div class="ulist"><ul>
518
- <li>
519
- <p>
520
- Ubuntu Linux 8.04 (x86)
521
- </p>
522
- </li>
523
- <li>
524
- <p>
525
- Gentoo Linux (AMD64)
526
- </p>
527
- </li>
528
- <li>
529
- <p>
530
- MacOS X Leopard (x86)
531
- </p>
532
- </li>
533
- </ul></div>
534
- <div class="paragraph"><p>Other operating systems have not been tested, but Phusion Passenger will probably
535
- work fine on them. Please
536
- <a href="http://code.google.com/p/phusion-passenger/issues/list">report a bug</a>
537
- or
538
- <a href="http://groups.google.com/group/phusion-passenger">join our discussion list</a>
539
- if it doesn&#8217;t.</p></div>
540
- </div>
541
- <h2 id="install_passenger">2. Installing Phusion Passenger</h2>
542
- <div class="sectionbody">
543
- <h3 id="_overview">2.1. Overview</h3><div style="clear:left"></div>
544
- <div class="paragraph"><p>As you might already know, Nginx does not support loadable modules, in contrast
545
- to most other web servers (e.g. Apache). Therefore, to install Phusion Passenger
546
- for Nginx, one must recompile and reinstall Nginx with Phusion Passenger support.
547
- There are two ways to do this:</p></div>
548
- <div class="olist arabic"><ol class="arabic">
549
- <li>
550
- <p>
551
- By running the Phusion Passenger installer for Nginx. This installer will
552
- guide you through the entire installation process, including downloading,
553
- compiling and installing Nginx. You should be able to get Nginx with Phusion
554
- Passenger support up-and-running in a matter of minutes. This is the
555
- recommended installation method.
556
- </p>
557
- </li>
558
- <li>
559
- <p>
560
- By manually configuring and compiling Nginx with Phusion Passenger support,
561
- through Nginx&#8217;s <tt>--add-module</tt> configure option. Generally, using our
562
- installer is easier, so you should only use this method if you&#8217;re already
563
- familiar with compiling Nginx.
564
- </p>
565
- </li>
566
- </ol></div>
567
- <div class="admonitionblock">
568
- <table><tr>
569
- <td class="icon">
570
- <img src="./images/icons/tip.png" alt="Tip" />
571
- </td>
572
- <td class="content">You might have to run the installation commands in the following sections
573
- as <em>root</em>. If the installer fails because of permission errors, it will tell
574
- you.</td>
575
- </tr></table>
576
- </div>
577
- <h3 id="specifying_ruby_installation">2.2. Specifying the correct Ruby installation</h3><div style="clear:left"></div>
578
- <div class="paragraph"><p>If your system has multiple Ruby installations&#8201;&#8212;&#8201;which is likely the case on
579
- MacOS X, or if you&#8217;ve also installed
580
- <a href="http://www.rubyenterpriseedition.com">Ruby Enterprise Edition</a>&#8201;&#8212;&#8201;then you
581
- will need to tell the operating system which Ruby installation to use, prior to
582
- running the Phusion Passenger installer. If you only have one Ruby installation
583
- (the case on most Linux systems), then you can skip this section because Phusion
584
- Passenger will automatically detect it.</p></div>
585
- <div class="paragraph"><p>To specify a Ruby installation, prepend your Ruby installation&#8217;s <tt>bin</tt>
586
- directory to the <tt>PATH</tt> environment variable. For example, if you have the
587
- following Ruby installations:</p></div>
588
- <div class="ulist"><ul>
589
- <li>
590
- <p>
591
- /usr/bin/ruby
592
- </p>
593
- </li>
594
- <li>
595
- <p>
596
- /opt/myruby/bin/ruby
597
- </p>
598
- </li>
599
- </ul></div>
600
- <div class="paragraph"><p>and you want to use the latter, then type:</p></div>
601
- <div class="listingblock">
602
- <div class="content">
603
- <pre><tt>export PATH=/opt/myruby/bin:$PATH</tt></pre>
604
- </div></div>
605
- <h3 id="_installing_phusion_passenger_for_nginx_through_the_installer">2.3. Installing Phusion Passenger for Nginx through the installer</h3><div style="clear:left"></div>
606
- <h4 id="_obtaining_the_phusion_passenger_files_and_running_the_installer">2.3.1. Obtaining the Phusion Passenger files and running the installer</h4>
607
- <div class="paragraph"><p>You must obtain the Phusion Passenger files in order to run the installer.
608
- This can be done either by installing the Phusion Passenger gem, or by
609
- downloading the source tarball.</p></div>
610
- <h5 id="_gem">Gem</h5>
611
- <div class="paragraph"><p>First, install the Phusion Passenger gem by running:</p></div>
612
- <div class="listingblock">
613
- <div class="content">
614
- <pre><tt>gem install passenger</tt></pre>
615
- </div></div>
616
- <div class="paragraph"><p>Next, run the Phusion Passenger installer for Nginx:</p></div>
617
- <div class="listingblock">
618
- <div class="content">
619
- <pre><tt>passenger-install-nginx-module</tt></pre>
620
- </div></div>
621
- <div class="paragraph"><p>Please follow the instructions given by the installer.</p></div>
622
- <h5 id="_source_tarball">Source tarball</h5>
623
- <div class="paragraph"><p>The source tarball can be download from the
624
- <a href="http://www.modrails.com/">Phusion Passenger website</a>. Extract the tarball to
625
- whatever location you prefer. <strong>The Phusion Passenger files are to reside in that
626
- location permanently.</strong> For example, if you would like Phusion Passenger to
627
- reside in <tt>/opt/passenger-x.x.x</tt>, then type:</p></div>
628
- <div class="listingblock">
629
- <div class="content">
630
- <pre><tt>cd /opt
631
- tar xzvf ~/YourDownloadsFolder/passenger-x.x.x.tar.gz</tt></pre>
632
- </div></div>
633
- <div class="paragraph"><p>Next, run the Phusion Passenger installer for Nginx:</p></div>
634
- <div class="listingblock">
635
- <div class="content">
636
- <pre><tt>/opt/passenger-x.x.x/bin/passenger-install-nginx-module</tt></pre>
637
- </div></div>
638
- <div class="paragraph"><p>Please follow the instructions given by the installer.</p></div>
639
- <div class="admonitionblock">
640
- <table><tr>
641
- <td class="icon">
642
- <img src="./images/icons/important.png" alt="Important" />
643
- </td>
644
- <td class="content">Please do not remove the passenger-x.x.x folder after installation.
645
- Furthermore, the passenger-x.x.x folder must be accessible by Nginx.</td>
646
- </tr></table>
647
- </div>
648
- <h4 id="_non_interactive_automatic_installation">2.3.2. Non-interactive/automatic installation</h4>
649
- <div class="paragraph"><p>By default, the installer is interactive. If you want to automate installation,
650
- then you can do so by passing various answers to the installer through command
651
- line options.</p></div>
652
- <div class="paragraph"><p>Please run the installer with <tt>--help</tt> for a list of available command line
653
- options.</p></div>
654
- <h3 id="_installing_phusion_passenger_for_nginx_manually">2.4. Installing Phusion Passenger for Nginx manually</h3><div style="clear:left"></div>
655
- <div class="paragraph"><p>You can install Phusion Passenger as a normal Nginx module. To do this, run
656
- Nginx&#8217;s configure script with <tt>--add-module=/path-to-passenger-root/ext/nginx</tt>.</p></div>
657
- <div class="paragraph"><p>If you installed Phusion Passenger via the gem, then <em>path-to-passenger-root</em>
658
- can be obtained with the command:</p></div>
659
- <div class="listingblock">
660
- <div class="content">
661
- <pre><tt>passenger-config --root</tt></pre>
662
- </div></div>
663
- <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>,
664
- 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>
665
- <div class="paragraph"><p>If you installed Phusion Passenger via a source tarball, then <em>path-to-passenger-root</em>
666
- is the directory which contains the Phusion Passenger source code. So if you
667
- extracted the Phusion Passenger source code to <em>/opt/passenger-x.x.x</em>, then you&#8217;ll
668
- have to specify <tt>--add-module=/opt/passenger-x.x.x/ext/nginx</tt>.</p></div>
669
- </div>
670
- <h2 id="_deploying_a_ruby_on_rails_application">3. Deploying a Ruby on Rails application</h2>
671
- <div class="sectionbody">
672
- <div class="paragraph"><p>Suppose you have a Ruby on Rails application in <em>/webapps/mycook</em>, and you own
673
- the domain <em>www.mycook.com</em>. You can either deploy your application to the
674
- virtual host&#8217;s root (i.e. the application will be accessible from the root URL,
675
- <em>http://www.mycook.com/</em>), or in a sub URI (i.e. the application will be
676
- accessible from a sub URL, such as <em>http://www.mycook.com/railsapplication</em>).</p></div>
677
- <div class="admonitionblock">
678
- <table><tr>
679
- <td class="icon">
680
- <img src="./images/icons/note.png" alt="Note" />
681
- </td>
682
- <td class="content">The default <tt>RAILS_ENV</tt> environment in which deployed Rails applications
683
- are run, is &#8220;production&#8221;. You can change this by changing the
684
- <a href="#rails_env"><em>RailsEnv</em></a> configuration option.</td>
685
- </tr></table>
686
- </div>
687
- <h3 id="_deploying_to_a_virtual_host_8217_s_root">3.1. Deploying to a virtual host&#8217;s root</h3><div style="clear:left"></div>
688
- <div class="paragraph"><p>Add a <em>server</em> virtual host entry to your Nginx configuration file. The virtual
689
- host&#8217;s root must point to your Ruby on Rails application&#8217;s <em>public</em> folder.</p></div>
690
- <div class="paragraph"><p>Inside the <em>server</em> block, set <em>passenger_enabled on</em>.</p></div>
691
- <div class="paragraph"><p>For example:</p></div>
692
- <div class="listingblock">
693
- <div class="content">
694
- <pre><tt>http {
695
- ...
696
-
697
- server {
698
- listen 80;
699
- server_name www.mycook.com;
700
- root /webapps/mycook/public;
701
- passenger_enabled on;
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
- <h3 id="deploying_rails_to_sub_uri">3.2. Deploying to a sub URI</h3><div style="clear:left"></div>
709
- <div class="paragraph"><p>Suppose that you already have a <em>server</em> virtual host entry:</p></div>
710
- <div class="listingblock">
711
- <div class="content">
712
- <pre><tt>http {
713
- ...
714
-
715
- server {
716
- listen 80;
717
- server_name www.phusion.nl;
718
- root /websites/phusion;
719
- }
720
-
721
- ...
722
- }</tt></pre>
723
- </div></div>
724
- <div class="paragraph"><p>And you want your Ruby on Rails application to be accessible from the URL
725
- <em>http://www.phusion.nl/rails</em>.</p></div>
726
- <div class="paragraph"><p>To do this, make a symlink from your Ruby on Rails application&#8217;s <em>public</em>
727
- folder to a directory in the document root. For example:</p></div>
728
- <div class="listingblock">
729
- <div class="content">
730
- <pre><tt>ln -s /webapps/mycook/public /websites/phusion/rails</tt></pre>
731
- </div></div>
732
- <div class="paragraph"><p>Next, set <em>passenger_enabled on</em> and add a <a href="#passenger_base_uri">[passenger_base_uri]</a> option to the
733
- <em>server</em> block:</p></div>
734
- <div class="listingblock">
735
- <div class="content">
736
- <pre><tt>http {
737
- ...
738
-
739
- server {
740
- listen 80;
741
- server_name www.phusion.nl;
742
- root /websites/phusion;
743
- passenger_enabled on; # &lt;--- These lines have
744
- passenger_base_uri /rails; # &lt;--- been added.
745
- }
746
-
747
- ...
748
- }</tt></pre>
749
- </div></div>
750
- <div class="paragraph"><p>Then restart Nginx. The application has now been deployed.</p></div>
751
- <div class="admonitionblock">
752
- <table><tr>
753
- <td class="icon">
754
- <img src="./images/icons/tip.png" alt="Tip" />
755
- </td>
756
- <td class="content">
757
- <div class="paragraph"><p>You can deploy multiple Rails applications under a virtual host, by specifying
758
- <a href="#passenger_base_uri">passenger_base_uri</a> multiple times. For example:</p></div>
759
- <div class="listingblock">
760
- <div class="content">
761
- <pre><tt>server {
762
- ...
763
- passenger_base_uri /app1;
764
- passenger_base_uri /app2;
765
- passenger_base_uri /app3;
766
- }</tt></pre>
767
- </div></div>
768
- </td>
769
- </tr></table>
770
- </div>
771
- <h3 id="_redeploying_restarting_the_ruby_on_rails_application">3.3. Redeploying (restarting the Ruby on Rails application)</h3><div style="clear:left"></div>
772
- <div class="paragraph"><p>Deploying a new version of a Ruby on Rails application is as simple as
773
- re-uploading the application files, and restarting the application.</p></div>
774
- <div class="paragraph"><p>There are two ways to restart the application:</p></div>
775
- <div class="olist arabic"><ol class="arabic">
776
- <li>
777
- <p>
778
- By restarting Nginx.
779
- </p>
780
- </li>
781
- <li>
782
- <p>
783
- By creating or modifying the file <em>tmp/restart.txt</em> in the Rails
784
- application&#8217;s <a href="#application_root">root folder</a>. Phusion Passenger will
785
- automatically restart the application.
786
- </p>
787
- </li>
788
- </ol></div>
789
- <div class="paragraph"><p>For example, to restart our example MyCook application, we type this in the
790
- command line:</p></div>
791
- <div class="listingblock">
792
- <div class="content">
793
- <pre><tt>touch /webapps/mycook/tmp/restart.txt</tt></pre>
794
- </div></div>
795
- <h3 id="_migrations">3.4. Migrations</h3><div style="clear:left"></div>
796
- <div class="paragraph"><p>Phusion Passenger is not related to Ruby on Rails migrations in any way. To
797
- run migrations on your deployment server, please login to your deployment
798
- server (e.g. with <em>ssh</em>) and type <tt>rake db:migrate RAILS_ENV=production</tt> in
799
- a shell console, just like one would normally run migrations.</p></div>
800
- <h3 id="_capistrano_integration">3.5. Capistrano integration</h3><div style="clear:left"></div>
801
- <div class="paragraph"><p>See <a href="#capistrano">Capistrano recipe</a>.</p></div>
802
- </div>
803
- <h2 id="_deploying_a_rack_based_ruby_application">4. Deploying a Rack-based Ruby application</h2>
804
- <div class="sectionbody">
805
- <div class="paragraph"><p>Phusion Passenger supports arbitrary Ruby web applications that follow the
806
- <a href="http://rack.rubyforge.org/">Rack</a> interface.</p></div>
807
- <div class="paragraph"><p>Phusion Passenger assumes that Rack application directories have a certain layout.
808
- Suppose that you have a Rack application in <em>/webapps/rackapp</em>. Then that
809
- folder must contain at least three entries:</p></div>
810
- <div class="ulist"><ul>
811
- <li>
812
- <p>
813
- <em>config.ru</em>, a Rackup file for starting the Rack application. This file must contain
814
- the complete logic for initializing the application.
815
- </p>
816
- </li>
817
- <li>
818
- <p>
819
- <em>public/</em>, a folder containing public static web assets, like images and stylesheets.
820
- </p>
821
- </li>
822
- <li>
823
- <p>
824
- <em>tmp/</em>, used for <em>restart.txt</em> (our application restart mechanism). This will
825
- be explained in a following subsection.
826
- </p>
827
- </li>
828
- </ul></div>
829
- <div class="paragraph"><p>So <em>/webapps/rackapp</em> must, at minimum, look like this:</p></div>
830
- <div class="listingblock">
831
- <div class="content">
832
- <pre><tt>/webapps/rackapp
833
- |
834
- +-- config.ru
835
- |
836
- +-- public/
837
- |
838
- +-- tmp/</tt></pre>
839
- </div></div>
840
- <div class="paragraph"><p>Suppose you own the domain <em>www.rackapp.com</em>. You can either deploy your application
841
- to the virtual host&#8217;s root (i.e. the application will be accessible from the root URL,
842
- <em>http://www.rackapp.com/</em>), or in a sub URI (i.e. the application will be
843
- accessible from a sub URL, such as <em>http://www.rackapp.com/rackapp</em>).</p></div>
844
- <div class="admonitionblock">
845
- <table><tr>
846
- <td class="icon">
847
- <img src="./images/icons/note.png" alt="Note" />
848
- </td>
849
- <td class="content">The default <tt>RACK_ENV</tt> environment in which deployed Rack applications
850
- are run, is &#8220;production&#8221;. You can change this by changing the
851
- <a href="#rack_env">rack_env</a> configuration option.</td>
852
- </tr></table>
853
- </div>
854
- <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><div style="clear:left"></div>
855
- <div class="paragraph"><p>First we create a Phusion Passenger-compliant Rack directory structure:</p></div>
856
- <div class="listingblock">
857
- <div class="content">
858
- <pre><tt>$ mkdir /webapps/rack_example
859
- $ mkdir /webapps/rack_example/public
860
- $ mkdir /webapps/rack_example/tmp</tt></pre>
861
- </div></div>
862
- <div class="paragraph"><p>Next, we write a minimal "hello world" Rack application:</p></div>
863
- <div class="listingblock">
864
- <div class="content">
865
- <pre><tt>$ cd /webapps/rack_example
866
- $ some_awesome_editor config.ru
867
- ...type in some source code...
868
- $ cat config.ru
869
- app = proc do |env|
870
- return [200, { "Content-Type" =&gt; "text/html" }, "hello &lt;b&gt;world&lt;/b&gt;"]
871
- end
872
- run app</tt></pre>
873
- </div></div>
874
- <div class="paragraph"><p>Finally, we deploy it by adding the following configuration options to
875
- the Apache configuration file:</p></div>
876
- <div class="listingblock">
877
- <div class="content">
878
- <pre><tt>http {
879
- ...
880
- server {
881
- listen 80;
882
- server_name www.rackexample.com;
883
- root /webapps/rack_example/public;
884
- passenger_enabled on;
885
- }
886
- ...
887
- }</tt></pre>
888
- </div></div>
889
- <div class="paragraph"><p>And we&#8217;re done! After an Nginx restart, the above Rack application will be available
890
- under the URL <em>http://www.rackexample.com/</em>.</p></div>
891
- <h3 id="_deploying_to_a_virtual_host_8217_s_root_2">4.2. Deploying to a virtual host&#8217;s root</h3><div style="clear:left"></div>
892
- <div class="paragraph"><p>Add a <em>server</em> virtual host entry to your Nginx configuration file. The virtual host&#8217;s
893
- root must point to your Rack application&#8217;s <em>public</em> folder. You must also set
894
- <em>passenger_enabled on</em> in the <em>server</em> block.</p></div>
895
- <div class="paragraph"><p>For example:</p></div>
896
- <div class="listingblock">
897
- <div class="content">
898
- <pre><tt>http {
899
- ...
900
- server {
901
- listen 80;
902
- server_name www.rackapp.com;
903
- root /webapps/rackapp/public;
904
- passenger_enabled on;
905
- }
906
- ...
907
- }</tt></pre>
908
- </div></div>
909
- <div class="paragraph"><p>Then restart Nginx. The application has now been deployed.</p></div>
910
- <h3 id="deploying_rack_to_sub_uri">4.3. Deploying to a sub URI</h3><div style="clear:left"></div>
911
- <div class="paragraph"><p>Suppose that you already have a virtual host:</p></div>
912
- <div class="listingblock">
913
- <div class="content">
914
- <pre><tt>http {
915
- ...
916
-
917
- server {
918
- listen 80;
919
- server_name www.phusion.nl;
920
- root /websites/phusion;
921
- passenger_enabled on;
922
- }
923
-
924
- ...
925
- }</tt></pre>
926
- </div></div>
927
- <div class="paragraph"><p>And you want your Rack application to be accessible from the URL
928
- <em>http://www.phusion.nl/rack</em>.</p></div>
929
- <div class="paragraph"><p>To do this, make a symlink from your Rack application&#8217;s <em>public</em>
930
- folder to a directory in the document root. For example:</p></div>
931
- <div class="listingblock">
932
- <div class="content">
933
- <pre><tt>ln -s /webapps/rackapp/public /websites/phusion/rack</tt></pre>
934
- </div></div>
935
- <div class="paragraph"><p>Next, set <em>passenger_enabled on</em> and add a <a href="#passenger_base_uri">[passenger_base_uri]</a> option to the
936
- <em>server</em> block:</p></div>
937
- <div class="listingblock">
938
- <div class="content">
939
- <pre><tt>http {
940
- ...
941
-
942
- server {
943
- listen 80;
944
- server_name www.phusion.nl;
945
- root /websites/phusion;
946
- passenger_enabled on; # &lt;--- These lines have
947
- passenger_base_uri /rack; # &lt;--- been added.
948
- }
949
-
950
- ...
951
- }</tt></pre>
952
- </div></div>
953
- <div class="paragraph"><p>Then restart Apache. The application has now been deployed.</p></div>
954
- <div class="admonitionblock">
955
- <table><tr>
956
- <td class="icon">
957
- <img src="./images/icons/tip.png" alt="Tip" />
958
- </td>
959
- <td class="content">
960
- <div class="paragraph"><p>You can deploy multiple Rack applications under a virtual host, by specifying
961
- <a href="#passenger_base_uri">passenger_base_uri</a> multiple times. For example:</p></div>
962
- <div class="listingblock">
963
- <div class="content">
964
- <pre><tt>server {
965
- ...
966
- passenger_base_uri /app1;
967
- passenger_base_uri /app2;
968
- passenger_base_uri /app3;
969
- }</tt></pre>
970
- </div></div>
971
- </td>
972
- </tr></table>
973
- </div>
974
- <h3 id="_redeploying_restarting_the_rack_application">4.4. Redeploying (restarting the Rack application)</h3><div style="clear:left"></div>
975
- <div class="paragraph"><p>Deploying a new version of a Rack application is as simple as
976
- re-uploading the application files, and restarting the application.</p></div>
977
- <div class="paragraph"><p>There are two ways to restart the application:</p></div>
978
- <div class="olist arabic"><ol class="arabic">
979
- <li>
980
- <p>
981
- By restarting Nginx.
982
- </p>
983
- </li>
984
- <li>
985
- <p>
986
- By creating or modifying the file <em>tmp/restart.txt</em> in the Rack
987
- application&#8217;s <a href="#application_root">root folder</a>. Phusion Passenger will
988
- automatically restart the application.
989
- </p>
990
- </li>
991
- </ol></div>
992
- <div class="paragraph"><p>For example, to restart our example application, we type this in the
993
- command line:</p></div>
994
- <div class="listingblock">
995
- <div class="content">
996
- <pre><tt>touch /webapps/rackapp/tmp/restart.txt</tt></pre>
997
- </div></div>
998
- <h3 id="_rackup_specifications_for_various_web_frameworks">4.5. Rackup specifications for various web frameworks</h3><div style="clear:left"></div>
999
- <div class="paragraph"><p>This subsection shows example <em>config.ru</em> files for various web frameworks.</p></div>
1000
- <h4 id="_camping">4.5.1. Camping</h4>
1001
- <div class="listingblock">
1002
- <div class="content">
1003
- <pre><tt>require 'rubygems'
1004
- require 'rack'
1005
- require 'camping'
1006
-
1007
- ##### Begin Camping application
1008
- Camping.goes :Blog
1009
-
1010
- ...your application code here...
1011
- ##### End Camping application
1012
-
1013
- run Rack::Adapter::Camping.new(Blog)</tt></pre>
1014
- </div></div>
1015
- <div class="paragraph"><p>For Camping versions 2.0 and up, using <tt>run Blog</tt> as the final line will do.</p></div>
1016
- <h4 id="_halcyon">4.5.2. Halcyon</h4>
1017
- <div class="listingblock">
1018
- <div class="content">
1019
- <pre><tt>require 'rubygems'
1020
- require 'halcyon'
1021
- $LOAD_PATH.unshift(Halcyon.root / 'lib')
1022
- Halcyon::Runner.load_config Halcyon.root/'config'/'config.yml'
1023
- run Halcyon::Runner.new</tt></pre>
1024
- </div></div>
1025
- <h4 id="_mack">4.5.3. Mack</h4>
1026
- <div class="listingblock">
1027
- <div class="content">
1028
- <pre><tt>ENV["MACK_ENV"] = ENV["RACK_ENV"]
1029
- load("Rakefile")
1030
- require 'rubygems'
1031
- require 'mack'
1032
- run Mack::Utils::Server.build_app</tt></pre>
1033
- </div></div>
1034
- <h4 id="_merb">4.5.4. Merb</h4>
1035
- <div class="listingblock">
1036
- <div class="content">
1037
- <pre><tt>require 'rubygems'
1038
- require 'merb-core'
1039
-
1040
- Merb::Config.setup(
1041
- :merb_root =&gt; File.expand_path(File.dirname(__FILE__)),
1042
- :environment =&gt; ENV['RACK_ENV']
1043
- )
1044
- Merb.environment = Merb::Config[:environment]
1045
- Merb.root = Merb::Config[:merb_root]
1046
- Merb::BootLoader.run
1047
-
1048
- run Merb::Rack::Application.new</tt></pre>
1049
- </div></div>
1050
- <h4 id="_ramaze">4.5.5. Ramaze</h4>
1051
- <div class="listingblock">
1052
- <div class="content">
1053
- <pre><tt>require "start"
1054
- Ramaze.trait[:essentials].delete Ramaze::Adapter
1055
- Ramaze.start :force =&gt; true
1056
- run Ramaze::Adapter::Base</tt></pre>
1057
- </div></div>
1058
- <h4 id="_sinatra">4.5.6. Sinatra</h4>
1059
- <div class="listingblock">
1060
- <div class="content">
1061
- <pre><tt>require 'rubygems'
1062
- require 'sinatra'
1063
-
1064
- root_dir = File.dirname(__FILE__)
1065
-
1066
- set :environment, ENV['RACK_ENV'].to_sym
1067
- set :root, root_dir
1068
- set :app_file, File.join(root_dir, 'app.rb')
1069
- disable :run
1070
-
1071
- run Sinatra::Application</tt></pre>
1072
- </div></div>
1073
- </div>
1074
- <h2 id="_appendix_a_about_this_document">5. Appendix A: About this document</h2>
1075
- <div class="sectionbody">
1076
- <div class="paragraph"><p>The text of this document is licensed under the
1077
- <a href="http://creativecommons.org/licenses/by-sa/3.0/">Creative Commons
1078
- Attribution-Share Alike 3.0 Unported License</a>.</p></div>
1079
- <div class="paragraph"><p><span class="image">
1080
- <a class="image" href="http://creativecommons.org/licenses/by-sa/3.0/">
1081
- <img src="images/by_sa.png" alt="images/by_sa.png" />
1082
- </a>
1083
- </span></p></div>
1084
- <div class="paragraph"><p>Phusion Passenger is brought to you by <a href="http://www.phusion.nl/">Phusion</a>.</p></div>
1085
- <div class="paragraph"><p><span class="image">
1086
- <a class="image" href="http://www.phusion.nl/">
1087
- <img src="images/phusion_banner.png" alt="images/phusion_banner.png" />
1088
- </a>
1089
- </span></p></div>
1090
- <div class="paragraph"><p>Phusion Passenger is a trademark of Hongli Lai &amp; Ninh Bui.</p></div>
1091
- </div>
1092
- <h2 id="_appendix_b_terminology">6. Appendix B: Terminology</h2>
1093
- <div class="sectionbody">
1094
- <h3 id="application_root">6.1. Application root</h3><div style="clear:left"></div>
1095
- <div class="paragraph"><p>The root directory of an application that&#8217;s served by Phusion Passenger.</p></div>
1096
- <div class="paragraph"><p>In case of Ruby on Rails applications, this is the directory that contains
1097
- <em>Rakefile</em>, <em>app/</em>, <em>config/</em>, <em>public/</em>, etc. In other words, the directory
1098
- pointed to by <tt>RAILS_ROOT</tt>. For example, take the following directory structure:</p></div>
1099
- <div class="listingblock">
1100
- <div class="content">
1101
- <pre><tt>/apps/foo/ &lt;------ This is the Rails application's application root!
1102
- |
1103
- +- app/
1104
- | |
1105
- | +- controllers/
1106
- | |
1107
- | +- models/
1108
- | |
1109
- | +- views/
1110
- |
1111
- +- config/
1112
- | |
1113
- | +- environment.rb
1114
- | |
1115
- | +- ...
1116
- |
1117
- +- public/
1118
- | |
1119
- | +- ...
1120
- |
1121
- +- ...</tt></pre>
1122
- </div></div>
1123
- <div class="paragraph"><p>In case of Rack applications, this is the directory that contains <em>config.ru</em>.
1124
- For example, take the following directory structure:</p></div>
1125
- <div class="listingblock">
1126
- <div class="content">
1127
- <pre><tt>/apps/bar/ &lt;----- This is the Rack application's application root!
1128
- |
1129
- +- public/
1130
- | |
1131
- | +- ...
1132
- |
1133
- +- config.ru
1134
- |
1135
- +- ...</tt></pre>
1136
- </div></div>
1137
- <div class="paragraph"><p>In case of Python (WSGI) applications, this is the directory that contains
1138
- <em>passenger_wsgi.py</em>. For example, take the following directory structure:</p></div>
1139
- <div class="listingblock">
1140
- <div class="content">
1141
- <pre><tt>/apps/baz/ &lt;----- This is the WSGI application's application root!
1142
- |
1143
- +- public/
1144
- | |
1145
- | +- ...
1146
- |
1147
- +- passenger_wsgi.py
1148
- |
1149
- +- ...</tt></pre>
1150
- </div></div>
1151
- </div>
1152
- <h2 id="spawning_methods_explained">7. Appendix C: Spawning methods explained</h2>
1153
- <div class="sectionbody">
1154
- <div class="paragraph"><p>At its core, Phusion Passenger is an HTTP proxy and process manager. It spawns
1155
- Ruby on Rails/Rack/WSGI worker processes (which may also be referred to as
1156
- <em>backend processes</em>), and forwards incoming HTTP request to one of the worker
1157
- processes.</p></div>
1158
- <div class="paragraph"><p>While this may sound simple, there&#8217;s not just one way to spawn worker processes.
1159
- Let&#8217;s go over the different spawning methods. For simplicity&#8217;s sake, let&#8217;s
1160
- assume that we&#8217;re only talking about Ruby on Rails applications.</p></div>
1161
- <h3 id="_the_most_straightforward_and_traditional_way_conservative_spawning">7.1. The most straightforward and traditional way: conservative spawning</h3><div style="clear:left"></div>
1162
- <div class="paragraph"><p>Phusion Passenger could create a new Ruby process, which will then load the
1163
- Rails application along with the entire Rails framework. This process will then
1164
- enter an request handling main loop.</p></div>
1165
- <div class="paragraph"><p>This is the most straightforward way to spawn worker processes. If you&#8217;re
1166
- familiar with the Mongrel application server, then this approach is exactly
1167
- what mongrel_cluster performs: it creates N worker processes, each which loads
1168
- a full copy of the Rails application and the Rails framework in memory. The Thin
1169
- application server employs pretty much the same approach.</p></div>
1170
- <div class="paragraph"><p>Note that Phusion Passenger&#8217;s version of conservative spawning differs slightly
1171
- from mongrel_cluster. Mongrel_cluster creates entirely new Ruby processes. In
1172
- programmers jargon, mongrel_cluster creates new Ruby processes by forking the
1173
- current process and exec()-ing a new Ruby interpreter. Phusion Passenger on the
1174
- other hand creates processes that reuse the already loaded Ruby interpreter. In
1175
- programmers jargon, Phusion Passenger calls fork(), but not exec().</p></div>
1176
- <h3 id="_the_smart_spawning_method">7.2. The smart spawning method</h3><div style="clear:left"></div>
1177
- <div class="admonitionblock">
1178
- <table><tr>
1179
- <td class="icon">
1180
- <img src="./images/icons/note.png" alt="Note" />
1181
- </td>
1182
- <td class="content">Smart spawning is only available for Ruby on Rails applications, not for
1183
- Rack applications or WSGI applications.</td>
1184
- </tr></table>
1185
- </div>
1186
- <div class="paragraph"><p>While conservative spawning works well, it&#8217;s not as efficient as it could be
1187
- because each worker process has its own private copy of the Rails application
1188
- as well as the Rails framework. This wastes memory as well as startup time.</p></div>
1189
- <div class="paragraph"><p><span class="image">
1190
- <img src="images/conservative_spawning.png" alt="Worker processes and conservative spawning" title="Worker processes and conservative spawning" />
1191
- </span><br />
1192
- <em>Figure: Worker processes and conservative spawning. Each worker process has its
1193
- own private copy of the application code and Rails framework code.</em></p></div>
1194
- <div class="paragraph"><p>It is possible to make the different worker processes share the memory occupied
1195
- by application and Rails framework code, by utilizing so-called
1196
- copy-on-write semantics of the virtual memory system on modern operating
1197
- systems. As a side effect, the startup time is also reduced. This is technique
1198
- is exploited by Phusion Passenger&#8217;s <em>smart</em> and <em>smart-lv2</em> spawn methods.</p></div>
1199
- <h4 id="_how_it_works">7.2.1. How it works</h4>
1200
- <div class="paragraph"><p>When the <em>smart-lv2</em> spawn method is being used, Phusion Passenger will first
1201
- create a so-called <em>ApplicationSpawner server</em> process. This process loads the
1202
- entire Rails application along with the Rails framework, by loading
1203
- <em>environment.rb</em>. Then, whenever Phusion Passenger needs a new worker process,
1204
- it will instruct the ApplicationSpawner server to do so. The ApplicationSpawner
1205
- server will create a worker new process
1206
- that reuses the already loaded Rails application/framework. Creating a worker
1207
- process through an already running ApplicationSpawner server is very fast, about
1208
- 10 times faster than loading the Rails application/framework from scratch. If
1209
- the Ruby interpreter is copy-on-write friendly (that is, if you&#8217;re running
1210
- <a href="#reducing_memory_usage">Ruby Enterprise Edition</a>) then all created worker
1211
- processes will share as much common
1212
- memory as possible. That is, they will all share the same application and Rails
1213
- framework code.</p></div>
1214
- <div class="paragraph"><p><span class="image">
1215
- <img src="images/smart-lv2.png" alt="images/smart-lv2.png" />
1216
- </span><br />
1217
- <em>Figure: Worker processes and the smart-lv2 spawn method. All worker processes,
1218
- as well as the ApplicationSpawner, share the same application code and Rails
1219
- framework code.</em></p></div>
1220
- <div class="paragraph"><p>The <em>smart</em> spawn method goes even further, by caching the Rails framework in
1221
- another process called the <em>FrameworkSpawner server</em>. This process only loads
1222
- the Rails framework, not the application. When a FrameworkSpawner server is
1223
- instructed to create a new worker process, it will create a new
1224
- ApplicationSpawner to which the instruction will be delegated. All those
1225
- ApplicationSpawner servers, as well as all worker processes created by those
1226
- ApplicationSpawner servers, will share the same Rails framework code.</p></div>
1227
- <div class="paragraph"><p>The <em>smart-lv2</em> method allows different worker processes that belong to the same
1228
- application to share memory. The <em>smart</em> method allows different worker
1229
- processes - that happen to use the same Rails version - to share memory, even if
1230
- they don&#8217;t belong to the same application.</p></div>
1231
- <div class="paragraph"><p>Notes:</p></div>
1232
- <div class="ulist"><ul>
1233
- <li>
1234
- <p>
1235
- Vendored Rails frameworks cannot be shared by different applications, even if
1236
- both vendored Rails frameworks are the same version. So for efficiency reasons
1237
- we don&#8217;t recommend vendoring Rails.
1238
- </p>
1239
- </li>
1240
- <li>
1241
- <p>
1242
- ApplicationSpawner and FrameworkSpawner servers have an idle timeout just
1243
- like worker processes. If an ApplicationSpawner/FrameworkSpawner server hasn&#8217;t
1244
- been instructed to do anything for a while, it will be shutdown in order to
1245
- conserve memory. This idle timeout is configurable.
1246
- </p>
1247
- </li>
1248
- </ul></div>
1249
- <h4 id="_summary_of_benefits">7.2.2. Summary of benefits</h4>
1250
- <div class="paragraph"><p>Suppose that Phusion Passenger needs a new worker process for an application
1251
- that uses Rails 2.2.1.</p></div>
1252
- <div class="ulist"><ul>
1253
- <li>
1254
- <p>
1255
- If the <em>smart-lv2</em> spawning method is used, and an ApplicationSpawner server
1256
- for this application is already running, then worker process creation time is
1257
- about 10 times faster than conservative spawning. This worker process will also
1258
- share application and Rails framework code memory with the ApplicationSpawner
1259
- server and the worker processes that had been spawned by this ApplicationSpawner
1260
- server.
1261
- </p>
1262
- </li>
1263
- <li>
1264
- <p>
1265
- If the <em>smart</em> spawning method is used, and a FrameworkSpawner server for
1266
- Rails 2.2.1 is already running, but no ApplicationSpawner server for this
1267
- application is running, then worker process creation time is about 2 times
1268
- faster than conservative spawning. If there is an ApplicationSpawner server
1269
- for this application running, then worker process creation time is about 10
1270
- times faster. This worker process will also share application and Rails
1271
- framework code memory with the ApplicationSpawner and FrameworkSpawner
1272
- servers.
1273
- </p>
1274
- </li>
1275
- </ul></div>
1276
- <div class="paragraph"><p>You could compare ApplicationSpawner and FrameworkSpawner servers with stem
1277
- cells, that have the ability to quickly change into more specific cells (worker
1278
- process).</p></div>
1279
- <div class="paragraph"><p>In practice, the smart spawning methods could mean a memory saving of about 33%,
1280
- assuming that your Ruby interpreter is <a href="#reducing_memory_usage">copy-on-write friendly</a>.</p></div>
1281
- <div class="paragraph"><p>Of course, smart spawning is not without gotchas. But if you understand the
1282
- gotchas you can easily reap the benefits of smart spawning.</p></div>
1283
- <h3 id="_smart_spawning_gotcha_1_unintential_file_descriptor_sharing">7.3. Smart spawning gotcha #1: unintential file descriptor sharing</h3><div style="clear:left"></div>
1284
- <div class="paragraph"><p>Because worker processes are created by forking from an ApplicationSpawner
1285
- server, it will share all file descriptors that are opened by the
1286
- ApplicationSpawner server. (This is part of the semantics of the Unix
1287
- <em>fork()</em> system call. You might want to Google it if you&#8217;re not familiar with
1288
- it.) A file descriptor is a handle which can be an opened file, an opened socket
1289
- connection, a pipe, etc. If different worker processes write to such a file
1290
- descriptor at the same time, then their write calls will be interleaved, which
1291
- may potentially cause problems.</p></div>
1292
- <div class="paragraph"><p>The problem commonly involves socket connections that are unintentially being
1293
- shared. You can fix it by closing and reestablishing the connection when Phusion
1294
- Passenger is creating a new worker process. Phusion Passenger provides the API
1295
- call <tt>PhusionPassenger.on_event(:starting_worker_process)</tt> to do so. So you
1296
- could insert the following code in your <em>environment.rb</em>:</p></div>
1297
- <div class="listingblock">
1298
- <div class="content"><!-- Generator: GNU source-highlight 2.4
1299
- by Lorenzo Bettini
1300
- http://www.lorenzobettini.it
1301
- http://www.gnu.org/software/src-highlite -->
1302
- <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>
1303
- PhusionPassenger<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">on_event</span></span><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>
1304
- <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
1305
- <span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
1306
- <span style="color: #990000">...</span> code to reestablish socket connections here <span style="color: #990000">...</span>
1307
- <span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
1308
- <span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
1309
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
1310
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
1311
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
1312
- <div class="paragraph"><p>Note that Phusion Passenger automatically reestablishes the connection to the
1313
- database upon creating a new worker process, which is why you normally do not
1314
- encounter any database issues when using smart spawning mode.</p></div>
1315
- <h4 id="_example_1_memcached_connection_sharing_harmful">7.3.1. Example 1: Memcached connection sharing (harmful)</h4>
1316
- <div class="paragraph"><p>Suppose we have a Rails application that connects to a Memcached server in
1317
- <em>environment.rb</em>. This causes the ApplicationSpawner to have a socket connection
1318
- (file descriptor) to the Memcached server, as shown in the following figure:</p></div>
1319
- <div class="literalblock">
1320
- <div class="content">
1321
- <pre><tt>+--------------------+
1322
- | ApplicationSpawner |-----------[Memcached server]
1323
- +--------------------+</tt></pre>
1324
- </div></div>
1325
- <div class="paragraph"><p>Phusion Passenger then proceeds with creating a new Rails worker process, which
1326
- is to process incoming HTTP requests. The result will look like this:</p></div>
1327
- <div class="literalblock">
1328
- <div class="content">
1329
- <pre><tt>+--------------------+
1330
- | ApplicationSpawner |------+----[Memcached server]
1331
- +--------------------+ |
1332
- |
1333
- +--------------------+ |
1334
- | Worker process 1 |-----/
1335
- +--------------------+</tt></pre>
1336
- </div></div>
1337
- <div class="paragraph"><p>Since a <em>fork()</em> makes a (virtual) complete copy of a process, all its file
1338
- descriptors will be copied as well. What we see here is that ApplicationSpawner
1339
- and Worker process 1 both share the same connection to Memcached.</p></div>
1340
- <div class="paragraph"><p>Now supposed that your site gets Slashdotted and Phusion Passenger needs to
1341
- spawn another worker process. It does so by forking ApplicationSpawner. The
1342
- result is now as follows:</p></div>
1343
- <div class="literalblock">
1344
- <div class="content">
1345
- <pre><tt>+--------------------+
1346
- | ApplicationSpawner |------+----[Memcached server]
1347
- +--------------------+ |
1348
- |
1349
- +--------------------+ |
1350
- | Worker process 1 |-----/|
1351
- +--------------------+ |
1352
- |
1353
- +--------------------+ |
1354
- | Worker process 2 |-----/
1355
- +--------------------+</tt></pre>
1356
- </div></div>
1357
- <div class="paragraph"><p>As you can see, Worker process 1 and Worker process 2 have the same Memcache
1358
- connection.</p></div>
1359
- <div class="paragraph"><p>Suppose that users Joe and Jane visit your website at the same time. Joe&#8217;s
1360
- request is handled by Worker process 1, and Jane&#8217;s request is handled by Worker
1361
- process 2. Both worker processes want to fetch something from Memcached. Suppose
1362
- that in order to do that, both handlers need to send a "FETCH" command to Memcached.</p></div>
1363
- <div class="paragraph"><p>But suppose that, after worker process 1 having only sent "FE", a context switch
1364
- occurs, and worker process 2 starts sending a "FETCH" command to Memcached as
1365
- well. If worker process 2 succeeds in sending only one bye, <em>F</em>, then Memcached
1366
- will receive a command which begins with "FEF", a command that it does not
1367
- recognize. In other words: the data from both handlers get interleaved. And thus
1368
- Memcached is forced to handle this as an error.</p></div>
1369
- <div class="paragraph"><p>This problem can be solved by reestablishing the connection to Memcached after forking:</p></div>
1370
- <div class="literalblock">
1371
- <div class="content">
1372
- <pre><tt>+--------------------+
1373
- | ApplicationSpawner |------+----[Memcached server]
1374
- +--------------------+ | |
1375
- | |
1376
- +--------------------+ | |
1377
- | Worker process 1 |-----/| |
1378
- +--------------------+ | | &lt;--- created this
1379
- X | new
1380
- | connection
1381
- X &lt;-- closed this |
1382
- +--------------------+ | old |
1383
- | Worker process 2 |-----/ connection |
1384
- +--------------------+ |
1385
- | |
1386
- +-------------------------------------+</tt></pre>
1387
- </div></div>
1388
- <div class="paragraph"><p>Worker process 2 now has its own, separate communication channel with Memcached.
1389
- The code in <em>environment.rb</em> looks like this:</p></div>
1390
- <div class="listingblock">
1391
- <div class="content"><!-- Generator: GNU source-highlight 2.4
1392
- by Lorenzo Bettini
1393
- http://www.lorenzobettini.it
1394
- http://www.gnu.org/software/src-highlite -->
1395
- <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>
1396
- PhusionPassenger<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">on_event</span></span><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>
1397
- <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
1398
- <span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
1399
- reestablish_connection_to_memcached
1400
- <span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
1401
- <span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
1402
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
1403
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
1404
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
1405
- <h4 id="_example_2_log_file_sharing_not_harmful">7.3.2. Example 2: Log file sharing (not harmful)</h4>
1406
- <div class="paragraph"><p>There are also cases in which unintential file descriptor sharing is not harmful.
1407
- One such case is log file file descriptor sharing. Even if two processes write
1408
- to the log file at the same time, the worst thing that can happen is that the
1409
- data in the log file is interleaved.</p></div>
1410
- <div class="paragraph"><p>To guarantee that the data written to the log file is never interleaved, you
1411
- must synchronize write access via an inter-process synchronization mechanism,
1412
- such as file locks. Reopening the log file, like you would have done in the
1413
- Memcached example, doesn&#8217;t help.</p></div>
1414
- <h3 id="_smart_spawning_gotcha_2_the_need_to_revive_threads">7.4. Smart spawning gotcha #2: the need to revive threads</h3><div style="clear:left"></div>
1415
- <div class="paragraph"><p>Another part of the <em>fork()</em> system call&#8217;s semantics is the fact that threads
1416
- disappear after a fork call. So if you&#8217;ve created any threads in environment.rb,
1417
- then those threads will no longer be running in newly created worker process.
1418
- You need to revive them when a new worker process is created. Use the
1419
- <tt>:starting_worker_process</tt> event that Phusion Passenger provides, like this:</p></div>
1420
- <div class="listingblock">
1421
- <div class="content"><!-- Generator: GNU source-highlight 2.4
1422
- by Lorenzo Bettini
1423
- http://www.lorenzobettini.it
1424
- http://www.gnu.org/software/src-highlite -->
1425
- <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>
1426
- PhusionPassenger<span style="color: #990000">.</span><span style="font-weight: bold"><span style="color: #000000">on_event</span></span><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>
1427
- <span style="font-weight: bold"><span style="color: #0000FF">if</span></span> forked
1428
- <span style="font-style: italic"><span style="color: #9A1900"># We're in smart spawning mode.</span></span>
1429
- <span style="color: #990000">...</span> code to revive threads here <span style="color: #990000">...</span>
1430
- <span style="font-weight: bold"><span style="color: #0000FF">else</span></span>
1431
- <span style="font-style: italic"><span style="color: #9A1900"># We're in conservative spawning mode. We don't need to do anything.</span></span>
1432
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
1433
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span>
1434
- <span style="font-weight: bold"><span style="color: #0000FF">end</span></span></tt></pre></div></div>
1435
- <h3 id="_smart_spawning_gotcha_3_code_load_order">7.5. Smart spawning gotcha #3: code load order</h3><div style="clear:left"></div>
1436
- <div class="paragraph"><p>This gotcha is only applicable to the <em>smart</em> spawn method, not the <em>smart-lv2</em>
1437
- spawn method.</p></div>
1438
- <div class="paragraph"><p>If your application expects the Rails framework to be not loaded during the
1439
- beginning of <em>environment.rb</em>, then it can cause problems when an
1440
- ApplicationSpawner is created from a FrameworkSpawner, which already has the
1441
- Rails framework loaded. The most common case is when applications try to patch
1442
- Rails by dropping a modified file that has the same name as Rails&#8217;s own file,
1443
- in a path that comes earlier in the Ruby search path.</p></div>
1444
- <div class="paragraph"><p>For example, suppose that we have an application which has a patched version
1445
- of <em>active_record/base.rb</em> located in <em>RAILS_ROOT/lib/patches</em>, and
1446
- <em>RAILS_ROOT/lib/patches</em> comes first in the Ruby load path. When conservative
1447
- spawning is used, the patched version of <em>base.rb</em> is properly loaded. When
1448
- <em>smart</em> (not <em>smart-lv2</em>) spawning is used, the original <em>base.rb</em> is used
1449
- because it was already loaded, so a subsequent <tt>require "active_record/base"</tt>
1450
- has no effect.</p></div>
1451
- </div>
1452
- <div id="footer">
1453
- <div id="footer-text">
1454
- Last updated 2009-03-12 19:53:58 CEST
1455
- </div>
1456
- </div>
1457
- </body>
1458
- </html>