Browse Source

Add configurable stuff for the standalone server

Now listening address, listening port and max_children count can be configured using the Settings module
Yann Weber 8 years ago
parent
commit
c1f627eb18

+ 6
- 0
lodel/plugins/multisite/confspecs.py View File

7
     'lodel2': {
7
     'lodel2': {
8
         'debug': (True, SettingValidator('bool'))
8
         'debug': (True, SettingValidator('bool'))
9
     },
9
     },
10
+    'lodel2.server': {
11
+        'listen_address': ('', SettingValidator('dummy')),
12
+        #'listen_address': ('', SettingValidator('ip')), #<-- not implemented
13
+        'listen_port': ( 1337, SettingValidator('int')),
14
+        'max_children': (40, SettingValidator('int')),
15
+    },
10
     'lodel2.logging.*' : {
16
     'lodel2.logging.*' : {
11
         'level': (  'ERROR',
17
         'level': (  'ERROR',
12
                     SettingValidator('loglevel')),
18
                     SettingValidator('loglevel')),

+ 21
- 0
lodel/plugins/multisite/example_lodel2.ini View File

1
+[lodel2.logging.templog]
2
+level = INFO
3
+filename = /tmp/log
4
+context = True
5
+
6
+[lodel2.server]
7
+listen_address = 
8
+listen_port = 1337
9
+max_children = 100
10
+
11
+[lodel2.logging.stderr]
12
+level = WARNING
13
+filename = -
14
+context = True
15
+
16
+
17
+[lodel2.datasources.default]
18
+identifier = dummy_datasource.default
19
+
20
+[lodel2.datasource.dummy_datasource.default]
21
+dummy = dummy

+ 8
- 8
lodel/plugins/multisite/main.py View File

16
 from lodel.context import LodelContext
16
 from lodel.context import LodelContext
17
 from lodel.context import ContextError
17
 from lodel.context import ContextError
18
 
18
 
19
-##@brief On wich addr we want to bind. '' mean all interfaces
20
-LISTEN_ADDR = ''
21
-##@brief Listening socket port
22
-LISTEN_PORT = 1337
23
-
24
 ##@brief Set the poll interval to detect shutdown requests (do not work)
19
 ##@brief Set the poll interval to detect shutdown requests (do not work)
25
 SHUTDOWN_POLL_INTERVAL = 0.1 # <-- No impact because of ForkingTCPServer bug
20
 SHUTDOWN_POLL_INTERVAL = 0.1 # <-- No impact because of ForkingTCPServer bug
26
 
21
 
86
 #in a child process
81
 #in a child process
87
 class ForkingWSGIServer(
82
 class ForkingWSGIServer(
88
         wsgiref.simple_server.WSGIServer, socketserver.ForkingTCPServer):
83
         wsgiref.simple_server.WSGIServer, socketserver.ForkingTCPServer):
84
+    
85
+    ##@brief static property indicating the max number of childs allowed
86
+    max_children = 40
87
+
89
     ##@brief Custom reimplementation of shutdown method in order to ensure
88
     ##@brief Custom reimplementation of shutdown method in order to ensure
90
     #that we close all listening sockets
89
     #that we close all listening sockets
91
     #
90
     #
152
 
151
 
153
 ##@brief Starts the server until a SIGINT is received
152
 ##@brief Starts the server until a SIGINT is received
154
 def main_loop():
153
 def main_loop():
155
-    #Init app cache
156
-    listen_addr = LISTEN_ADDR
157
-    listen_port = LISTEN_PORT
154
+    LodelContext.expose_modules(globals(), {'lodel.settings': ['Settings']})
155
+    ForkingWSGIServer.max_children = Settings.server.max_children
156
+    listen_addr = Settings.server.listen_address
157
+    listen_port = Settings.server.listen_port
158
     server = wsgiref.simple_server.make_server(
158
     server = wsgiref.simple_server.make_server(
159
         listen_addr, listen_port, wsgi_router,
159
         listen_addr, listen_port, wsgi_router,
160
         server_class=ForkingWSGIServer, handler_class = LodelWSGIHandler)
160
         server_class=ForkingWSGIServer, handler_class = LodelWSGIHandler)

+ 1
- 0
lodel/settings/validator.py View File

27
 # Class instance are callable objects that takes a value argument (the value to validate). It raises
27
 # Class instance are callable objects that takes a value argument (the value to validate). It raises
28
 # a SettingsValidationError if validation fails, else it returns a properly
28
 # a SettingsValidationError if validation fails, else it returns a properly
29
 # casted value.
29
 # casted value.
30
+#@todo implement an IP validator and use it in multisite confspec
30
 class SettingValidator(object):
31
 class SettingValidator(object):
31
     
32
     
32
     _validators = dict()
33
     _validators = dict()

Loading…
Cancel
Save