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 7 years ago
parent
commit
c1f627eb18

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

@@ -7,6 +7,12 @@ LODEL2_CONFSPECS = {
7 7
     'lodel2': {
8 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 16
     'lodel2.logging.*' : {
11 17
         'level': (  'ERROR',
12 18
                     SettingValidator('loglevel')),

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

@@ -0,0 +1,21 @@
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,11 +16,6 @@ from io import BufferedWriter
16 16
 from lodel.context import LodelContext
17 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 19
 ##@brief Set the poll interval to detect shutdown requests (do not work)
25 20
 SHUTDOWN_POLL_INTERVAL = 0.1 # <-- No impact because of ForkingTCPServer bug
26 21
 
@@ -86,6 +81,10 @@ class LodelWSGIHandler(wsgiref.simple_server.WSGIRequestHandler):
86 81
 #in a child process
87 82
 class ForkingWSGIServer(
88 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 88
     ##@brief Custom reimplementation of shutdown method in order to ensure
90 89
     #that we close all listening sockets
91 90
     #
@@ -152,9 +151,10 @@ def wsgi_router(env, start_response):
152 151
 
153 152
 ##@brief Starts the server until a SIGINT is received
154 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 158
     server = wsgiref.simple_server.make_server(
159 159
         listen_addr, listen_port, wsgi_router,
160 160
         server_class=ForkingWSGIServer, handler_class = LodelWSGIHandler)

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

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

Loading…
Cancel
Save