Merge lp:~mcfletch/modwsgideploy/parameterized into lp:~szybalski/modwsgideploy/trunk
- parameterized
- Merge into trunk
Status: | Needs review |
---|---|
Proposed branch: | lp:~mcfletch/modwsgideploy/parameterized |
Merge into: | lp:~szybalski/modwsgideploy/trunk |
Diff against target: |
671 lines (+346/-179) 7 files modified
trunk/README.txt (+6/-6) trunk/modwsgideploy.egg-info/PKG-INFO (+1/-1) trunk/modwsgideploy.egg-info/entry_points.txt (+1/-1) trunk/modwsgideploy/commands.py (+150/-55) trunk/modwsgideploy/templates/apache/+package+.wsgi_tmpl (+74/-36) trunk/modwsgideploy/templates/apache/+package+_tmpl (+64/-43) trunk/modwsgideploy/templates/apache/README.txt_tmpl (+50/-37) |
To merge this branch: | bzr merge lp:~mcfletch/modwsgideploy/parameterized |
Related bugs: |
Commit message
Description of the change
Hi Lucas,
I've made a few changes and enhancements to the modwsgi_deploy script:
* parameterized almost all paths, names and the like
* updated for use with any Python 2.x interpreter
* tried to compress the code using conditionals
* numerous typo fixes
* cleaned out some copy-and-paste code that wasn't getting used
* generate warnings if referenced paths don't exist with instructions on how to fix
* reformatted the .wsgi file to look more like a Python module
I haven't finished testing, just wanted to give you a heads-up so you could look over the changes and see whether you're interested in integrating them.
Enjoy,
Mike
Unmerged revisions
- 21. By Mike C. Fletcher
-
Testing of default operation on Apache shows we're getting close.
python-eggs test/warning on configuration - 20. By Mike C. Fletcher
-
Even more parameterization.
Log warnings to the user about not-yet-finished operations in the setup.
Fix missing application virtualenv option.
Make the apache template slightly more compact.
Rewrite readme as (loosely) .rst format. - 19. By Mike C. Fletcher
-
Yet more parameterization.
Clean up the generated .wsgi file to look a little more like a Python file, with a docstring, wrapped lines, only the configured pieces, etceteras - 18. By Mike C. Fletcher
-
Cleanup usage string to eliminate old copy-and-pasted descriptions that no longer apply.
Make deployment and baseline directories command-line configurable
Make logging setup configurable from the command line.
Use the current Python version as the default for the lib/.../ links, allow command-line override. - 17. By Mike C. Fletcher
-
Minor typo fix
Preview Diff
1 | === modified file 'trunk/README.txt' | |||
2 | --- trunk/README.txt 2009-09-27 03:29:25 +0000 | |||
3 | +++ trunk/README.txt 2010-03-08 17:56:30 +0000 | |||
4 | @@ -34,7 +34,7 @@ | |||
5 | 34 | cd modwsgideploy_code/trunk | 34 | cd modwsgideploy_code/trunk |
6 | 35 | python setup.py develop | 35 | python setup.py develop |
7 | 36 | 36 | ||
9 | 37 | Run modwsgi_deploy | 37 | Run modwsgi_deploy |
10 | 38 | ------------------ | 38 | ------------------ |
11 | 39 | 39 | ||
12 | 40 | Go into your python application project folder and type in:: | 40 | Go into your python application project folder and type in:: |
13 | @@ -45,7 +45,7 @@ | |||
14 | 45 | Example | 45 | Example |
15 | 46 | ------- | 46 | ------- |
16 | 47 | 47 | ||
18 | 48 | Here is a typical installation, from start to finish on Debian Linux. You might have to use you OS specific commands for installing apache. | 48 | Here is a typical installation, from start to finish on Debian Linux. You might have to use you OS specific commands for installing apache. |
19 | 49 | 49 | ||
20 | 50 | The steps are: | 50 | The steps are: |
21 | 51 | 1) Install apache and modwsgi | 51 | 1) Install apache and modwsgi |
22 | @@ -62,7 +62,7 @@ | |||
23 | 62 | source BASELINE/bin/activate | 62 | source BASELINE/bin/activate |
24 | 63 | easy_install -i http://www.turbogears.org/2.0/downloads/current/index tg.devtools | 63 | easy_install -i http://www.turbogears.org/2.0/downloads/current/index tg.devtools |
25 | 64 | paster quickstart myapp | 64 | paster quickstart myapp |
27 | 65 | 65 | ||
28 | 66 | Install modwsgideploy:: | 66 | Install modwsgideploy:: |
29 | 67 | 67 | ||
30 | 68 | easy_install modwsgideploy | 68 | easy_install modwsgideploy |
31 | @@ -80,14 +80,14 @@ | |||
32 | 80 | | |-- myapp | 80 | | |-- myapp |
33 | 81 | | |-- myapp.wsgi | 81 | | |-- myapp.wsgi |
34 | 82 | | `-- test.wsgi | 82 | | `-- test.wsgi |
36 | 83 | 83 | ||
37 | 84 | 84 | ||
38 | 85 | 1. Read the README.txt | 85 | 1. Read the README.txt |
39 | 86 | 2. myapp is a apache configuration file that you need to copy into your apache configuration folder after all the settings are set. | 86 | 2. myapp is a apache configuration file that you need to copy into your apache configuration folder after all the settings are set. |
40 | 87 | 3. myapp.wsgi is an modwsgi script that is called from myapp apache file | 87 | 3. myapp.wsgi is an modwsgi script that is called from myapp apache file |
41 | 88 | 4. test.wsgi is a test script that you can call to see if you modwsgi was properly installed and working. | 88 | 4. test.wsgi is a test script that you can call to see if you modwsgi was properly installed and working. |
42 | 89 | 89 | ||
44 | 90 | Edit myapp file to change any paths and/or apache configurations. Then copy to apache folder. | 90 | Edit myapp file to change any paths and/or apache configurations. Then copy to apache folder. |
45 | 91 | 91 | ||
46 | 92 | On my operating system I copy this file to:: | 92 | On my operating system I copy this file to:: |
47 | 93 | 93 | ||
48 | @@ -103,5 +103,5 @@ | |||
49 | 103 | Feedback | 103 | Feedback |
50 | 104 | -------- | 104 | -------- |
51 | 105 | 105 | ||
53 | 106 | If you have a useful sample wsgi script or apache config that you would like to share, please sent it to Turbogears mailing list. | 106 | If you have a useful sample wsgi script or apache config that you would like to share, please send it to Turbogears mailing list. |
54 | 107 | 107 | ||
55 | 108 | 108 | ||
56 | === modified file 'trunk/modwsgideploy.egg-info/PKG-INFO' | |||
57 | --- trunk/modwsgideploy.egg-info/PKG-INFO 2009-09-27 03:58:24 +0000 | |||
58 | +++ trunk/modwsgideploy.egg-info/PKG-INFO 2010-03-08 17:56:30 +0000 | |||
59 | @@ -1,6 +1,6 @@ | |||
60 | 1 | Metadata-Version: 1.0 | 1 | Metadata-Version: 1.0 |
61 | 2 | Name: modwsgideploy | 2 | Name: modwsgideploy |
63 | 3 | Version: 0.4.18dev | 3 | Version: 0.4.20dev |
64 | 4 | Summary: Deploy Turbogears2 or Pylons via apache and modwsgi. | 4 | Summary: Deploy Turbogears2 or Pylons via apache and modwsgi. |
65 | 5 | Home-page: http://lucasmanual.com/mywiki/modwsgideploy | 5 | Home-page: http://lucasmanual.com/mywiki/modwsgideploy |
66 | 6 | Author: Lukasz Szybalski | 6 | Author: Lukasz Szybalski |
67 | 7 | 7 | ||
68 | === modified file 'trunk/modwsgideploy.egg-info/entry_points.txt' | |||
69 | --- trunk/modwsgideploy.egg-info/entry_points.txt 2009-04-10 20:17:26 +0000 | |||
70 | +++ trunk/modwsgideploy.egg-info/entry_points.txt 2010-03-08 17:56:30 +0000 | |||
71 | @@ -1,4 +1,4 @@ | |||
72 | 1 | 1 | ||
73 | 2 | [paste.global_paster_command] | 2 | [paste.global_paster_command] |
74 | 3 | modwsgi_deploy = modwsgideploy.commands:ModwsgiCommand | 3 | modwsgi_deploy = modwsgideploy.commands:ModwsgiCommand |
75 | 4 | |||
76 | 5 | \ No newline at end of file | 4 | \ No newline at end of file |
77 | 5 | |||
78 | 6 | \ No newline at end of file | 6 | \ No newline at end of file |
79 | 7 | 7 | ||
80 | === modified file 'trunk/modwsgideploy/commands.py' | |||
81 | --- trunk/modwsgideploy/commands.py 2008-12-16 04:47:54 +0000 | |||
82 | +++ trunk/modwsgideploy/commands.py 2010-03-08 17:56:30 +0000 | |||
83 | @@ -7,48 +7,16 @@ | |||
84 | 7 | 7 | ||
85 | 8 | modwsgi_deploy | 8 | modwsgi_deploy |
86 | 9 | """ | 9 | """ |
87 | 10 | |||
88 | 11 | import os | 10 | import os |
89 | 12 | import sys | 11 | import sys |
91 | 13 | 12 | import logging, pprint | |
92 | 13 | log = logging.getLogger( 'modwsgideploy' ) | ||
93 | 14 | from paste.script.command import Command, BadCommand | 14 | from paste.script.command import Command, BadCommand |
94 | 15 | from paste.script.filemaker import FileOp | 15 | from paste.script.filemaker import FileOp |
95 | 16 | from paste.script.copydir import copy_dir | 16 | from paste.script.copydir import copy_dir |
96 | 17 | |||
97 | 18 | |||
98 | 19 | #Needed to manipulate egg information | 17 | #Needed to manipulate egg information |
99 | 20 | from paste.script import pluginlib | 18 | from paste.script import pluginlib |
100 | 21 | 19 | ||
101 | 22 | def can_import(name): | ||
102 | 23 | """Attempt to __import__ the specified package/module, returning True when | ||
103 | 24 | succeeding, otherwise False""" | ||
104 | 25 | try: | ||
105 | 26 | __import__(name) | ||
106 | 27 | return True | ||
107 | 28 | except ImportError: | ||
108 | 29 | return False | ||
109 | 30 | |||
110 | 31 | def validateName(name): | ||
111 | 32 | """Validate that the name for the layer isn't present on the | ||
112 | 33 | path already""" | ||
113 | 34 | if not name: | ||
114 | 35 | # This happens when the name is an existing directory | ||
115 | 36 | raise BadCommand('Please give the name of a layer.') | ||
116 | 37 | # 'setup' is a valid controller name, but when paster controller is ran | ||
117 | 38 | # from the root directory of a project, importing setup will import the | ||
118 | 39 | # project's setup.py causing a sys.exit(). Blame relative imports | ||
119 | 40 | if name != 'setup' and can_import(name): | ||
120 | 41 | raise BadCommand( | ||
121 | 42 | "\n\nA module named '%s' is already present in your " | ||
122 | 43 | "PYTHON_PATH.\nChoosing a conflicting name will likely cause " | ||
123 | 44 | "import problems in\nyour controller at some point. It's " | ||
124 | 45 | "suggested that you choose an\nalternate name, and if you'd " | ||
125 | 46 | "like that name to be accessible as\n'%s', add a route " | ||
126 | 47 | "to your projects config/routing.py file similar\nto:\n" | ||
127 | 48 | " map.connect('%s', controller='my_%s')" \ | ||
128 | 49 | % (name, name, name, name)) | ||
129 | 50 | return True | ||
130 | 51 | |||
131 | 52 | class ModwsgiCommand(Command): | 20 | class ModwsgiCommand(Command): |
132 | 53 | """Create a modwsgi apache configuration. | 21 | """Create a modwsgi apache configuration. |
133 | 54 | 22 | ||
134 | @@ -57,17 +25,10 @@ | |||
135 | 57 | Example usage:: | 25 | Example usage:: |
136 | 58 | 26 | ||
137 | 59 | yourproj% paster modwsgi_deploy | 27 | yourproj% paster modwsgi_deploy |
149 | 60 | Creating yourproj/yourproj/controllers/foos.py | 28 | |
150 | 61 | Creating yourproj/yourproj/tests/functional/test_foos.py | 29 | Or, with logging enabled: |
151 | 62 | 30 | ||
152 | 63 | If you'd like to have controllers underneath a directory, just include | 31 | yourproj% paster modwsgi_deploy --logging |
142 | 64 | the path as the controller name and the necessary directories will be | ||
143 | 65 | created for you:: | ||
144 | 66 | |||
145 | 67 | yourproj% paster geo-controller admin/foos | ||
146 | 68 | Creating yourproj/controllers/admin | ||
147 | 69 | Creating yourproj/yourproj/controllers/admin/foos.py | ||
148 | 70 | Creating yourproj/yourproj/tests/functional/test_admin_foos.py | ||
153 | 71 | """ | 32 | """ |
154 | 72 | summary = __doc__.splitlines()[0] | 33 | summary = __doc__.splitlines()[0] |
155 | 73 | usage = '\n' + __doc__ | 34 | usage = '\n' + __doc__ |
156 | @@ -79,17 +40,58 @@ | |||
157 | 79 | default_verbosity = 3 | 40 | default_verbosity = 3 |
158 | 80 | 41 | ||
159 | 81 | parser = Command.standard_parser(simulate=True) | 42 | parser = Command.standard_parser(simulate=True) |
160 | 82 | parser.add_option('--no-test', | ||
161 | 83 | action='store_true', | ||
162 | 84 | dest='no_test', | ||
163 | 85 | help="Don't create the test; just the controller") | ||
164 | 86 | parser.add_option('-o', '--output-dir', | 43 | parser.add_option('-o', '--output-dir', |
165 | 87 | dest='output_dir', | 44 | dest='output_dir', |
166 | 88 | metavar='DIR', | 45 | metavar='DIR', |
167 | 89 | default='.', | 46 | default='.', |
169 | 90 | help="Write put the directory into DIR (default current directory)") | 47 | help="Write Apache2 configuration files in DIR/apache (default current directory)") |
170 | 48 | parser.add_option('-b', '--baseline', | ||
171 | 49 | dest='baseline', | ||
172 | 50 | metavar='DIR', | ||
173 | 51 | default='/usr/local/pythonenv/BASELINE', | ||
174 | 52 | help="Path to the BASELINE VirtualEnv shared by applications, if set to '', then no BASELINE VirtualEnv is configured") | ||
175 | 53 | parser.add_option('-e', '--virtualenv', | ||
176 | 54 | dest='virtualenv', | ||
177 | 55 | action='store', | ||
178 | 56 | default=os.pathsep, | ||
179 | 57 | help="Path to the application's VirtualEnv, if explicitly set to '', use system python, if not specified, use directory <package_name> next to BASELINE") | ||
180 | 58 | parser.add_option('-d', '--deployment', | ||
181 | 59 | dest='deployment', | ||
182 | 60 | metavar='DIR', | ||
183 | 61 | default='/usr/local/turbogears', | ||
184 | 62 | help="Path where applications are installed, your app will be ${deployment}/package_name") | ||
185 | 63 | parser.add_option('-c', '--config', | ||
186 | 64 | dest='config', | ||
187 | 65 | action="store", | ||
188 | 66 | default = 'production.ini', | ||
189 | 67 | help="Name of the TurboGears2 configuration file (default production.ini)") | ||
190 | 68 | parser.add_option('-p', '--python', | ||
191 | 69 | dest='python_version', | ||
192 | 70 | default='python%s.%s'%( sys.version_info[:2] ), | ||
193 | 71 | help="Python version for the deployment") | ||
194 | 72 | parser.add_option('-l', '--logging', | ||
195 | 73 | dest='logging', | ||
196 | 74 | action="store_true", | ||
197 | 75 | default=False, | ||
198 | 76 | help="Whether to enable logging for the config (default False)") | ||
199 | 77 | parser.add_option('-m', '--subsite', | ||
200 | 78 | dest='mount', | ||
201 | 79 | action="store", | ||
202 | 80 | default = '', | ||
203 | 81 | help="URL sub-path at which to mount the application default (/package or '/' if virtualhost specified), use '/' to mount as the root of the site") | ||
204 | 82 | parser.add_option('-H', '--virtualhost', | ||
205 | 83 | dest='vhost', | ||
206 | 84 | action="store", | ||
207 | 85 | default = '', | ||
208 | 86 | help="Virtual Host (Domain Name) to use for this configuration, such as 'myvirtual.mydomain.com', default is not to use a VirtualHost") | ||
209 | 87 | parser.add_option('-E', '--embedded-mode', | ||
210 | 88 | dest='embedded', | ||
211 | 89 | action='store_true', | ||
212 | 90 | default=False, | ||
213 | 91 | help="Use mod_wsgi embedded mode (only recommended on Win32)") | ||
214 | 91 | def command(self): | 92 | def command(self): |
215 | 92 | """Main command to create a modwsgi configuration files""" | 93 | """Main command to create a modwsgi configuration files""" |
216 | 94 | logging.basicConfig(level=logging.INFO) | ||
217 | 93 | #Output directory is current folder unless specified vi output command. | 95 | #Output directory is current folder unless specified vi output command. |
218 | 94 | output_dir = os.path.join(self.options.output_dir, 'apache') | 96 | output_dir = os.path.join(self.options.output_dir, 'apache') |
219 | 95 | #Input where the templates are at. | 97 | #Input where the templates are at. |
220 | @@ -110,12 +112,105 @@ | |||
221 | 110 | #Add package names | 112 | #Add package names |
222 | 111 | vars['project']=plugins | 113 | vars['project']=plugins |
223 | 112 | vars['package']=plugins | 114 | vars['package']=plugins |
224 | 115 | vars['deployment'] = self.options.deployment | ||
225 | 116 | vars['baseline'] = self.options.baseline | ||
226 | 117 | vars['python_version'] = self.options.python_version | ||
227 | 118 | vars['logging'] = self.options.logging | ||
228 | 119 | vars['vhost'] = self.options.vhost | ||
229 | 120 | vars['embedded'] = self.options.embedded | ||
230 | 121 | if self.options.virtualenv == os.pathsep and vars['baseline']: | ||
231 | 122 | # user didn't specify, use (calculated) default | ||
232 | 123 | # basically the package name next to baseline... | ||
233 | 124 | virtualenv = os.path.join( | ||
234 | 125 | os.path.dirname( vars['baseline'] ), | ||
235 | 126 | plugins, | ||
236 | 127 | ) | ||
237 | 128 | elif self.options.virtualenv: | ||
238 | 129 | # explicit | ||
239 | 130 | virtualenv = self.options.virtualenv | ||
240 | 131 | else: | ||
241 | 132 | # not specified and no baseline | ||
242 | 133 | virtualenv = '' | ||
243 | 134 | vars['virtualenv'] = virtualenv | ||
244 | 135 | if self.options.vhost: | ||
245 | 136 | default_mount = '/' | ||
246 | 137 | else: | ||
247 | 138 | default_mount = '/%s'%( plugins, ) | ||
248 | 139 | vars['mount'] = self.options.mount or default_mount | ||
249 | 140 | if not vars['mount'].endswith( '/' ): | ||
250 | 141 | vars['mount'] += '/' | ||
251 | 142 | vars['config'] = self.options.config | ||
252 | 143 | |||
253 | 113 | vars['egg']=pluginlib.egg_name(str(dist_name)) | 144 | vars['egg']=pluginlib.egg_name(str(dist_name)) |
255 | 114 | 145 | ||
256 | 146 | log.info( | ||
257 | 147 | 'Generating Apache2 Configuration in %s with:\n%s', | ||
258 | 148 | output_dir, | ||
259 | 149 | pprint.pformat( vars ), | ||
260 | 150 | ) | ||
261 | 151 | self.validate_vars( vars ) | ||
262 | 152 | |||
263 | 115 | #Copy my template direcotry to destination. | 153 | #Copy my template direcotry to destination. |
264 | 116 | copy_dir(input_dir, output_dir, vars, verbosity=1, simulate=False, use_cheetah=True) | 154 | copy_dir(input_dir, output_dir, vars, verbosity=1, simulate=False, use_cheetah=True) |
269 | 117 | print 'Thank you for using modwsgideploy!' | 155 | log.info( 'Thank you for using modwsgideploy!' ) |
270 | 118 | print 'Please read README.txt in apache folder.' | 156 | log.info( 'Please read README.txt in apache folder.' ) |
271 | 119 | print 'http://lucasmanual.com/mywiki/modwsgideploy' | 157 | log.info( 'http://lucasmanual.com/mywiki/modwsgideploy' ) |
272 | 120 | print 'Made in Chicago,IL USA' | 158 | log.info( 'Made in Chicago,IL USA' ) |
273 | 121 | 159 | ||
274 | 160 | def validate_vars( self, vars ): | ||
275 | 161 | """Validate variables and log warnings""" | ||
276 | 162 | if not os.path.exists( vars['deployment'] ): | ||
277 | 163 | log.warn( | ||
278 | 164 | "You need to create the deployment directory\n\tmkdir %s", | ||
279 | 165 | vars['deployment'], | ||
280 | 166 | ) | ||
281 | 167 | final_dir = os.path.join( vars['deployment'], vars['package'] ) | ||
282 | 168 | final_file = os.path.join( final_dir, vars['config'] ) | ||
283 | 169 | egg_dir = os.path.join( final_dir, 'python-eggs' ) | ||
284 | 170 | if not os.path.exists( final_dir ): | ||
285 | 171 | log.warn( | ||
286 | 172 | "You need to move/copy/checkout your project to the deployment directory:\n\tcp -r ../%s %s/\n\tchown -R www-data:www-data %s/%s", | ||
287 | 173 | vars['package'], | ||
288 | 174 | vars['deployment'], | ||
289 | 175 | vars['deployment'],vars['package'], | ||
290 | 176 | ) | ||
291 | 177 | if not os.path.exists( final_file ): | ||
292 | 178 | log.warn( | ||
293 | 179 | 'You need to create a %s file, edit it for production, and install it in %s:\n\tpaster make-config %s %s\n\tcp %s %s', | ||
294 | 180 | vars['config'], | ||
295 | 181 | final_dir, | ||
296 | 182 | vars['package'], | ||
297 | 183 | vars['config'], | ||
298 | 184 | vars['config'], | ||
299 | 185 | final_dir, | ||
300 | 186 | ) | ||
301 | 187 | if not os.path.exists( egg_dir ): | ||
302 | 188 | log.warn( | ||
303 | 189 | 'You need to create an egg-unpacking directory:\n\tmkdir %s\n\tchown www-data:www-data %s', | ||
304 | 190 | egg_dir, | ||
305 | 191 | egg_dir, | ||
306 | 192 | ) | ||
307 | 193 | if not vars['baseline']: | ||
308 | 194 | log.warn( | ||
309 | 195 | "You have disabled BASELINE environment support, this is not recommended!", | ||
310 | 196 | ) | ||
311 | 197 | elif not os.path.exists( vars['baseline'] ): | ||
312 | 198 | parent = os.path.dirname( vars['baseline'] ) | ||
313 | 199 | log.warn( | ||
314 | 200 | "You need to create the BASELINE VirtualEnv:\n\tmkdir %s\n\tcd %s\n\tvirtualenv --no-site-packages %s\n\tchown -R www-data:www-data %s", | ||
315 | 201 | parent, | ||
316 | 202 | parent, | ||
317 | 203 | os.path.basename( vars['baseline'] ), | ||
318 | 204 | os.path.basename( vars['baseline'] ), | ||
319 | 205 | ) | ||
320 | 206 | if vars['virtualenv'] and not os.path.exists( vars['virtualenv'] ): | ||
321 | 207 | log.warn( | ||
322 | 208 | "You need to create your application's VirtualEnv:\n\tmkdir %s\n\tcd %s\n\tvirtualenv --no-site-packages %s\n\tchown -R www-data:www-data %s\n\t#install packages into this virtualenv now", | ||
323 | 209 | vars['virtualenv'], | ||
324 | 210 | vars['virtualenv'], | ||
325 | 211 | os.path.basename( vars['virtualenv'] ), | ||
326 | 212 | os.path.basename( vars['virtualenv'] ), | ||
327 | 213 | ) | ||
328 | 214 | if vars['embedded']: | ||
329 | 215 | log.warn( 'Embedded mode is not recommended for Linux or OSX servers' ) | ||
330 | 216 | return vars | ||
331 | 122 | 217 | ||
332 | === modified file 'trunk/modwsgideploy/templates/apache/+package+.wsgi_tmpl' | |||
333 | --- trunk/modwsgideploy/templates/apache/+package+.wsgi_tmpl 2009-10-17 18:05:06 +0000 | |||
334 | +++ trunk/modwsgideploy/templates/apache/+package+.wsgi_tmpl 2010-03-08 17:56:30 +0000 | |||
335 | @@ -1,51 +1,89 @@ | |||
345 | 1 | \#modwsgi script for $package | 1 | """Apache mod_wsgi script for ${package} |
346 | 2 | 2 | ||
347 | 3 | \#1.Point to this script in your apache config file. | 3 | Point to this script in your apache config file. |
348 | 4 | \#Default location for all apps is: | 4 | A template config file was generated as the file `${package}` sitting |
349 | 5 | \#Debian: /usr/local/turbogears/${package} | 5 | next to this file |
350 | 6 | 6 | ||
351 | 7 | \#2. Make sure apache user own the folder. | 7 | Make sure the apache user (normally www-data) owns your application's |
352 | 8 | \#Debian: chown -R www-data:www-data /usr/local/turbogears/${package} | 8 | deployment path (${deployment}/${package}). On Linux machines you can |
353 | 9 | 9 | accomplish this with: | |
354 | 10 | |||
355 | 11 | .. code-block:: bash | ||
356 | 12 | |||
357 | 13 | sudo chown -R www-data:www-data ${deployment}/${package} | ||
358 | 14 | |||
359 | 15 | #if $baseline | ||
360 | 16 | The BASELINE pattern creates a root VirtualEnv on which your | ||
361 | 17 | application-specific VirtualEnv's will be based, and which will | ||
362 | 18 | can shared among potentially multiple projects. If you haven't | ||
363 | 19 | yet created the BASELINE VirtualEnv you can created it with: | ||
364 | 20 | |||
365 | 21 | .. code-block:: bash | ||
366 | 22 | |||
367 | 23 | sudo mkdir /usr/local/pythonenv | ||
368 | 24 | sudo virtualenv --no-site-packages ${baseline} | ||
369 | 25 | |||
370 | 26 | Make sure that the apache user owns the ${baseline} virtualenv. | ||
371 | 27 | On Linux machines you can ensure this with: | ||
372 | 28 | |||
373 | 29 | .. code-block:: bash | ||
374 | 30 | |||
375 | 31 | sudo chown -R www-data:www-data ${baseline} | ||
376 | 32 | #else | ||
377 | 33 | You have not configured BASELINE support. If you wish to include it, | ||
378 | 34 | either specify a --baseline=somedir parameter to `paster modwsgi_deploy` | ||
379 | 35 | or leave off the baseline parameter entirely to use the default. | ||
380 | 36 | #end if | ||
381 | 37 | |||
382 | 38 | For details on BASELINE and the general mod_wsgi/VirtualEnv pattern | ||
383 | 39 | used here, see: | ||
384 | 40 | |||
385 | 41 | http://code.google.com/p/modwsgi/wiki/VirtualEnvironments | ||
386 | 42 | """ | ||
387 | 10 | import sys | 43 | import sys |
388 | 11 | 44 | ||
396 | 12 | \#3. start of virtualenv (enabled by default). | 45 | #if $baseline |
397 | 13 | \#Please comment out until 4 if you don't use virtualenv. | 46 | \# This block provides support for the default virtualenv |
398 | 14 | \#Make sure root owns the virtualenv folder. Example:(root:root) | 47 | \# deployment pattern. The option `--virtualenv=` on the |
399 | 15 | \#Create virtualenv if you didn't create it yet: | 48 | \# `paster modwsgi_deploy` command line will skip this section entirely. |
393 | 16 | \#mkdir /usr/local/pythonenv | ||
394 | 17 | \#virtualenv --no-site-packages /usr/local/pythonenv/BASELINE | ||
395 | 18 | |||
400 | 19 | prev_sys_path = list(sys.path) | 49 | prev_sys_path = list(sys.path) |
401 | 20 | 50 | ||
404 | 21 | import site | 51 | import site |
405 | 22 | site.addsitedir('/usr/local/pythonenv/BASELINE/lib/python2.5/site-packages') | 52 | site.addsitedir('${virtualenv}/lib/${python_version}/site-packages') |
406 | 23 | 53 | ||
408 | 24 | \#Move just added item to the front of the python system path. | 54 | \#Move just added item to the front of the python system path. |
409 | 25 | \#Not needed if modwsgi>=3.0. Uncomment next 6 lines. | 55 | \#Not needed if modwsgi>=3.0. Uncomment next 6 lines. |
410 | 26 | new_sys_path = [] | 56 | new_sys_path = [] |
411 | 27 | for item in list(sys.path): | 57 | for item in list(sys.path): |
412 | 28 | if item not in prev_sys_path: | 58 | if item not in prev_sys_path: |
413 | 29 | new_sys_path.append(item) | 59 | new_sys_path.append(item) |
414 | 30 | sys.path.remove(item) | 60 | sys.path.remove(item) |
420 | 31 | sys.path[:0] = new_sys_path | 61 | sys.path[:0] = new_sys_path |
421 | 32 | 62 | \#End of virtualenv support | |
422 | 33 | \#End of virtualenv | 63 | |
423 | 34 | 64 | #end if | |
424 | 35 | \#4. Your website file location. | 65 | \# This adds your project's root path to the PYTHONPATH so that you can import |
425 | 66 | \# top-level modules from your project path. This is how TurboGears QuickStarted | ||
426 | 67 | \# projects are laid out by default. | ||
427 | 36 | import os, sys | 68 | import os, sys |
434 | 37 | sys.path.append('/usr/local/turbogears/${package}') | 69 | sys.path.append('${deployment}/${package}') |
435 | 38 | 70 | ||
436 | 39 | \#5. Set the environment variable PYTHON_EGG_CACHE to an appropriate directory where the Apache user has write permission and into which it can unpack egg files. | 71 | \# Set the environment variable PYTHON_EGG_CACHE to an appropriate directory |
437 | 40 | os.environ['PYTHON_EGG_CACHE'] = '/usr/local/turbogears/${package}/python-eggs' | 72 | \# where the Apache user has write permission and into which it can unpack egg files. |
438 | 41 | 73 | os.environ['PYTHON_EGG_CACHE'] = '${deployment}/${package}/python-eggs' | |
439 | 42 | \#6.[Optional]If you want to enable logging you need to initialize logging. You also need to setup logger handlers in your production.ini. When done uncomment next two lines. | 74 | |
440 | 75 | #if logging | ||
441 | 76 | \# Initialize logging module from your TurboGears config file | ||
442 | 77 | from paste.script.util.logging_config import fileConfig | ||
443 | 78 | fileConfig('${deployment}/${package}/${config}') | ||
444 | 79 | #else | ||
445 | 80 | \# If you want to enable logging you need to initialize logging. | ||
446 | 81 | \# You also need to setup logger handlers in your ${config}. | ||
447 | 82 | \# When done uncomment next two lines. | ||
448 | 43 | \#from paste.script.util.logging_config import fileConfig | 83 | \#from paste.script.util.logging_config import fileConfig |
450 | 44 | \#fileConfig('/usr/local/turbogears/${package}/production.ini') | 84 | \#fileConfig('${deployment}/${package}/${config}') |
451 | 85 | #end if | ||
452 | 45 | 86 | ||
454 | 46 | \#7. Load your application production.ini file. | 87 | \# Finally, load your application's ${config} file. |
455 | 47 | from paste.deploy import loadapp | 88 | from paste.deploy import loadapp |
460 | 48 | application = loadapp('config:/usr/local/turbogears/${package}/production.ini') | 89 | application = loadapp('config:${deployment}/${package}/${config}') |
457 | 49 | |||
458 | 50 | |||
459 | 51 | \#8.[Optional] If you want to test modwsgi only, uncomment section 3 in your /usr/local/turbogears/${package}/apache/${package} | ||
461 | 52 | 90 | ||
462 | === modified file 'trunk/modwsgideploy/templates/apache/+package+_tmpl' | |||
463 | --- trunk/modwsgideploy/templates/apache/+package+_tmpl 2009-10-21 21:13:01 +0000 | |||
464 | +++ trunk/modwsgideploy/templates/apache/+package+_tmpl 2010-03-08 17:56:30 +0000 | |||
465 | @@ -1,50 +1,71 @@ | |||
494 | 1 | \#Apache configuration File | 1 | \# Apache configuration File for ${package} |
495 | 2 | \#Read README.txt | 2 | \# Read README.txt |
496 | 3 | \#1. This file is the apache2 config file. It should be added to your apache config folder. If you mounting your app as a site wide package, you can rename the file to something like 002-${package} and put anything else that you want to be available in 001-someapp; When done copy to apache config folder. On Debian copy to /etc/apache2/sites-available/ | 3 | \# This should be added to your apache config folder. |
497 | 4 | \#cp ./apache/${package} /etc/apache2/sites-available/${package} | 4 | \# If you are mounting your app as a site wide you can rename the file |
498 | 5 | \#a2ensite ${package} | 5 | \# to something like `002-${package}` |
499 | 6 | 6 | \# and put anything else that you want to be available in 001-someapp; | |
500 | 7 | 7 | \# When done editing this file copy to apache config folder. | |
501 | 8 | \#Default location for tg2 project is /usr/local/turbogears/${package}. That is where you should put your project. This folder should be outside of apache location. Your package should not be installed into python site-package. | 8 | \# On Debian copy to /etc/apache2/sites-available/ |
502 | 9 | 9 | \# cp ./apache/${package} /etc/apache2/sites-available/${package} | |
503 | 10 | \#2. Alias/Allow apache to serve static content. | 10 | \# a2ensite ${package} |
504 | 11 | Alias /${package}/images /usr/local/turbogears/${package}/${package}/public/images | 11 | |
505 | 12 | Alias /${package}/css /usr/local/turbogears/${package}/${package}/public/css | 12 | \# Your TurboGears project needs to be installed at:: |
506 | 13 | Alias /${package}/javascript /usr/local/turbogears/${package}/${package}/public/javascript | 13 | \# ${deployment}/${package} |
507 | 14 | 14 | \# So that this file is present:: | |
508 | 15 | \#[Optional] Embeded mode (http://example.com/${package}).For big websites with a lot of memory and visitors. As of version 0.4.16 deamon mode is default and it should be used on Linux. On windows use embeded mode. | 15 | \# ${deployment}/${package}/${config} |
509 | 16 | 16 | \# You can reconfigure this with:: | |
510 | 17 | \#WSGIScriptAlias /${package} /usr/local/turbogears/${package}/apache/${package}.wsgi | 17 | \# paster modwsgi_deploy --deployment=somedir |
511 | 18 | 18 | \# This folder should be outside of apache's "file" location. | |
512 | 19 | \#3. Test if modwsgi is working. Uncomment below line, and go to http://localhost/test: | 19 | \# Your package should not be installed into python site-package. |
513 | 20 | \#WSGIScriptAlias /test /usr/local/turbogears/${package}/apache/test.wsgi | 20 | |
514 | 21 | 21 | #if $baseline | |
515 | 22 | \#4. [Optional] Sitewide (http://example.com/) | 22 | WSGIPythonHome ${baseline} |
516 | 23 | \#Alias /images /usr/local/turbogears/${package}/${package}/public/images | 23 | #end if |
517 | 24 | \#Alias /css /usr/local/turbogears/${package}/${package}/public/css | 24 | \# TODO: confirm that this line is appropriate for Daemon mode... |
518 | 25 | \#Alias /javascript /usr/local/turbogears/${package}/${package}/public/javascript | 25 | WSGIPythonPath ${virtualenv}/lib/${python_version}/site-packages |
519 | 26 | \#WSGIScriptAlias / /usr/local/turbogears/apache/${package}.wsgi | 26 | |
520 | 27 | 27 | ||
521 | 28 | \#5.Deamon mode with 10 threads and 3 processes. For small to medium website. | 28 | #if $vhost |
522 | 29 | \# VirtualHost support is enabled: | ||
523 | 30 | \# the '*' here specifies "all ip addresses on the host", you can use | ||
524 | 31 | \# *:port to specify a non-standard port on all ip addresses, or specify | ||
525 | 32 | \# a particular IP address rather than * | ||
526 | 33 | \# This first line tells apache to enable Named Virtual Hosts on all IPs | ||
527 | 34 | \# If you see a warning from Apache saying that NameVirtualHost *:80 has | ||
528 | 35 | \# no virtual hosts, you likely are on Ubuntu and the base installation of | ||
529 | 36 | \# Apache has set up an *:80 NameVirtualHost already, you can ignore the | ||
530 | 37 | \# error or comment out the following line. | ||
531 | 38 | |||
532 | 39 | NameVirtualHost * | ||
533 | 40 | |||
534 | 41 | \# This block configures our particular named virtual host | ||
535 | 42 | <VirtualHost *> | ||
536 | 43 | ServerName ${vhost} | ||
537 | 44 | #end if | ||
538 | 45 | \# Allow apache to serve static content. | ||
539 | 46 | \# Your site is configured to mount at ${mount} (use --mount to change this) | ||
540 | 47 | |||
541 | 48 | Alias ${mount}images ${deployment}/${package}/${package}/public/images | ||
542 | 49 | Alias ${mount}css ${deployment}/${package}/${package}/public/css | ||
543 | 50 | Alias ${mount}javascript ${deployment}/${package}/${package}/public/javascript | ||
544 | 51 | |||
545 | 52 | \# Choose deamon mode with 10 threads and 3 processes. | ||
546 | 53 | \# For small to medium website. | ||
547 | 54 | #if not $embedded | ||
548 | 29 | WSGIDaemonProcess ${package} threads=10 processes=3 | 55 | WSGIDaemonProcess ${package} threads=10 processes=3 |
549 | 30 | WSGIProcessGroup ${package} | 56 | WSGIProcessGroup ${package} |
551 | 31 | WSGIScriptAlias /${package} /usr/local/turbogears/${package}/apache/${package}.wsgi | 57 | #end if |
552 | 58 | WSGIScriptAlias ${mount} ${deployment}/${package}/apache/${package}.wsgi | ||
553 | 32 | 59 | ||
556 | 33 | \#6. Directory Permission. | 60 | \# Directory Permissions. |
557 | 34 | <Directory /usr/local/turbogears/${package}/apache> | 61 | <Directory ${deployment}/${package}/apache> |
558 | 35 | Order deny,allow | 62 | Order deny,allow |
559 | 36 | Allow from all | 63 | Allow from all |
560 | 37 | </Directory> | 64 | </Directory> |
561 | 38 | 65 | ||
574 | 39 | \#7. [Optional] If you want to use Virtualhost apache settings. | 66 | #if $vhost |
575 | 40 | \#Sample Virtual Host configuration would look like this: | 67 | </VirtualHost> |
576 | 41 | 68 | #else | |
577 | 42 | \#<Directory /usr/local/turbogears/${package}/apache> | 69 | \# You have not specified a VirtualHost name, pass --virtualhost=my.example.com |
578 | 43 | \# Order allow,deny | 70 | \# to paster modwsgi_deploy to use VirtualHost support. |
579 | 44 | \# Allow from all | 71 | #end if |
568 | 45 | \#</Directory> | ||
569 | 46 | |||
570 | 47 | \#NameVirtualHost *:81 | ||
571 | 48 | \#<VirtualHost *:81> | ||
572 | 49 | \# WSGIScriptAlias / /usr/local/turbogears/${package}/apache/${package}.wsgi | ||
573 | 50 | \#</VirtualHost> | ||
580 | 51 | 72 | ||
581 | === modified file 'trunk/modwsgideploy/templates/apache/README.txt_tmpl' | |||
582 | --- trunk/modwsgideploy/templates/apache/README.txt_tmpl 2009-10-17 18:05:06 +0000 | |||
583 | +++ trunk/modwsgideploy/templates/apache/README.txt_tmpl 2010-03-08 17:56:30 +0000 | |||
584 | @@ -1,37 +1,50 @@ | |||
622 | 1 | #Here is a numbered list of what you need to do to deploy your Turbogears2 or Pylons application. Follow 1 through 6. | 1 | Here is the process to deploy your Turbogears2 or Pylons application. |
623 | 2 | 2 | ||
624 | 3 | #1. Create production.ini configuration file if its not there already. Example: | 3 | # Create production.ini configuration file (if it's not there already). Example:: |
625 | 4 | paster make-config ${package} production.ini | 4 | |
626 | 5 | #Edit production.ini and comment out the port settings, update the url for the production database. | 5 | paster make-config ${package} production.ini |
627 | 6 | 6 | ||
628 | 7 | #2. Change or check the apache settings file. | 7 | Edit production.ini and comment out the port settings, update the url |
629 | 8 | #Edit /usr/local/turbogears/${package}/apache/${package} and make sure it has the necessary apache configurations you need. Please update any paths if youi are placing your app somewehere other then /usr/local/turbogears/${package}/ | 8 | for the production database. |
630 | 9 | 9 | ||
631 | 10 | #Copy {$package} apache config file to apache folder. Example: | 10 | # Change or check the apache settings file (sitting next to this README) and |
632 | 11 | cp /usr/local/turbogears/${package}/apache/${package} /etc/apache2/sites-available/${package} | 11 | install it. Edit the file:: |
633 | 12 | 12 | ||
634 | 13 | #3.Check if permissions are the same as other apache sites usually (root:root) | 13 | apache/${package} |
635 | 14 | 14 | ||
636 | 15 | ls -l /etc/apache2/sites-available/ | 15 | and make sure it has the necessary apache configurations you need. |
637 | 16 | #You shoud see | 16 | Note: you may wish to re-run paster modwsgi_deploy with other options |
638 | 17 | #total 16 | 17 | if you want to put your package in a nonstandard location. |
639 | 18 | #-rw-r--r-- 1 root root 950 2008-08-08 13:06 default | 18 | |
640 | 19 | #-rw-r--r-- 1 root root 7366 2008-08-08 13:06 default-ssl | 19 | # Copy {$package} apache config file to apache folder. Example:: |
641 | 20 | #-rw-r--r-- 1 root root 1077 2008-11-08 12:38 ${package} | 20 | |
642 | 21 | 21 | cp ${package}/apache/${package} /etc/apache2/sites-available/${package} | |
643 | 22 | #4.Enable your site. | 22 | |
644 | 23 | a2ensite ${package} | 23 | # Check if permissions are the same as other apache sites usually (root:root):: |
645 | 24 | 24 | ||
646 | 25 | #5. Check if your project has proper permissions, usually apache user. (Example: www-data:www-data on Debian). | 25 | ls -l /etc/apache2/sites-available/ |
647 | 26 | ls -l /usr/local/turbogears/${package}/apache/ | 26 | total 16 |
648 | 27 | #total 16 | 27 | -rw-r--r-- 1 root root 950 2008-08-08 13:06 default |
649 | 28 | #-rw-r--r-- 1 www-data www-data 1077 2008-11-26 22:35 ${package} | 28 | -rw-r--r-- 1 root root 7366 2008-08-08 13:06 default-ssl |
650 | 29 | #-rw-r--r-- 1 www-data www-data 2319 2008-11-26 23:25 ${package}.wsgi | 29 | -rw-r--r-- 1 root root 1077 2008-11-08 12:38 ${package} |
651 | 30 | #-rw-r--r-- 1 www-data www-data 594 2008-11-26 22:35 README.txt | 30 | |
652 | 31 | #-rw-r--r-- 1 www-data www-data 538 2008-11-26 22:35 test.wsgi | 31 | # Enable your site:: |
653 | 32 | 32 | ||
654 | 33 | #6.Reload apache | 33 | a2ensite ${package} |
655 | 34 | /etc/init.d/apache2 reload | 34 | |
656 | 35 | 35 | # Check if your project has proper permissions, usually apache user. | |
657 | 36 | 36 | (Example: www-data:www-data on Debian).:: | |
658 | 37 | #You are done. Your application should be working. Check the access.log, warn.log, and error.log in /var/log/apache to see if there are any errors. | 37 | |
659 | 38 | ls -l /usr/local/turbogears/${package}/apache/ | ||
660 | 39 | total 16 | ||
661 | 40 | -rw-r--r-- 1 www-data www-data 1077 2008-11-26 22:35 ${package} | ||
662 | 41 | -rw-r--r-- 1 www-data www-data 2319 2008-11-26 23:25 ${package}.wsgi | ||
663 | 42 | -rw-r--r-- 1 www-data www-data 594 2008-11-26 22:35 README.txt | ||
664 | 43 | -rw-r--r-- 1 www-data www-data 538 2008-11-26 22:35 test.wsgi | ||
665 | 44 | |||
666 | 45 | # Reload apache:: | ||
667 | 46 | |||
668 | 47 | /etc/init.d/apache2 reload | ||
669 | 48 | |||
670 | 49 | You are done. Your application should be working. Check the access.log, | ||
671 | 50 | warn.log, and error.log in /var/log/apache to see if there are any errors. |