annotate MoinMoin/server/server_fastcgi.py @ 3107:c6e39279f83b

refactor logging usage
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sat, 23 Feb 2008 22:59:30 +0100
parents 80e1a910a2f1
children a7c1680aeaa0
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 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
26 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
27 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
28
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 # 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
30 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
31 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
32 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
33
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 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
35 """ 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
36 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
37 # 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
38
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 # 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
40 # -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
41 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
42
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 # 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
44 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
45
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 # 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
47 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
48
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
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 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
51 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
52
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 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
54 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
55 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
56 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
57