annotate MoinMoin/server/server_fastcgi.py @ 3105:80e1a910a2f1

make logging more configurable and flexible, packages/modules shall call MoinMoin.server.getLogger
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 21:43:47 +0100
parents 806cf4814612
children c6e39279f83b
rev   line source
3071
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
1 # -*- coding: iso-8859-1 -*-
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
2 """
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
3 MoinMoin.server.server_fastcgi
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
4
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
5 This is not really a server, it is just so that fastcgi stuff
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
6 (the real server is likely Apache2) fits the model we have for
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
7 Twisted and standalone server.
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
8
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
9 Minimal usage:
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
10
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
11 from MoinMoin.server.server_fastcgi import FastCgiConfig, run
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
12
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
13 class Config(FastCgiConfig):
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
14 pass
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
15
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
16 run(Config)
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
17
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
18 See more options in FastCgiConfig class.
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
19
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
20 @copyright: 2007 MoinMoin:ThomasWaldmann
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
21
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
22 @license: GNU GPL, see COPYING for details.
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
23 """
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
24
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
25 import logging
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
26
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
27 from MoinMoin.server import Config
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
28 from MoinMoin.request import request_fcgi
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
29 from MoinMoin.support import thfcgi
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
30
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
31 # Set threads flag, so other code can use proper locking.
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
32 from MoinMoin import config
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
33 config.use_threads = 1
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
34 del config
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
35
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
36 class FastCgiConfig(Config):
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
37 """ Set up default server """
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
38 properties = {}
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
39 # properties = {'script_name': '/'}
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
40
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
41 # how many requests shall be handled by a moin fcgi process before it dies,
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
42 # -1 mean "unlimited lifetime":
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
43 max_requests = -1
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
44
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
45 # how many threads to use (1 means use only main program, non-threaded)
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
46 max_threads = 5
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
47
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
48 # backlog, use in socket.listen(backlog) call
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
49 backlog = 5
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
50
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
51
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
52 def run(ConfigClass=FastCgiConfig):
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
53 config = ConfigClass()
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
54
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
55 handle_request = lambda req, env, form, properties=config.properties: \
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
56 request_fcgi.Request(req, env, form, properties=properties).run()
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
57 fcg = thfcgi.FCGI(handle_request, max_requests=config.max_requests, backlog=config.backlog, max_threads=config.max_threads)
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
58 fcg.run()
806cf4814612 get server/request package in sync with 1.6 branch (as of changeset 2559:eedcb9cfefdb)
Thomas Waldmann <tw AT waldmann-edv DOT de>
parents:
diff changeset
59