Browse Source

webui & slim enhancement

Adds a LODEL2LOGDIR to buildconf.py
Adds a nginx-conf option to slim
...
Yann Weber 7 years ago
parent
commit
ca4952a264

+ 11
- 1
lodel/Makefile.am View File

@@ -11,7 +11,17 @@ lodeldir=$(pkgpythondir)/
11 11
 distclean-local:
12 12
 	-rm Makefile Makefile.in
13 13
 
14
-do_subst = sed -e 's,\[@\]LODEL2_VARDIR\[@\],$(localstatedir)/lodel2/,g'
14
+logdir = $(localstatedir)/log/lodel2/
15
+
16
+do_subst = sed 	-e 's,\[@\]LODEL2_VARDIR\[@\],$(localstatedir)/lodel2/,g' \
17
+		-e 's,\[@\]LODEL2_LOGDIR\[@\],$(logdir),g'
18
+
19
+
20
+install-data-hook:
21
+	-mkdir -p $(logdir)
22
+
23
+uninstall-hook:
24
+	-rmdir $(logdir)
15 25
 
16 26
 buildconf.py: buildconf.py.am
17 27
 	$(do_subst) < $(srcdir)/buildconf.py.am > buildconf.py

+ 1
- 0
lodel/buildconf.py.am.in View File

@@ -5,3 +5,4 @@ PYMONGO=@PYMONGO@
5 5
 WEBUI=@WEBUI@
6 6
 #Populated by make
7 7
 LODEL2VARDIR="[@]LODEL2_VARDIR[@]"
8
+LODEL2LOGDIR="[@]LODEL2_LOGDIR[@]"

+ 1
- 1
plugins/webui/confspec.py View File

@@ -12,7 +12,7 @@ CONFSPEC = {
12 12
                        SettingValidator('path', none_is_valid=True)),
13 13
         'uwsgicmd': ('/usr/bin/uwsgi_python3', SettingValidator('dummy')),
14 14
         'cookie_secret_key': ('ConfigureYourOwnCookieSecretKey', SettingValidator('dummy')),
15
-        'cookie_session_id': ('lodel', SettingValidator('dummy'))
15
+        'cookie_session_id': ('lodel', SettingValidator('dummy')),
16 16
     },
17 17
     'lodel2.webui.sessions': {
18 18
         'directory': (  '/tmp',

+ 9
- 4
plugins/webui/main.py View File

@@ -28,22 +28,27 @@ def uwsgi_fork(hook_name, caller, payload):
28 28
             os.mkdir(sockfile)
29 29
         sockfile = os.path.join(sockfile,
30 30
             Settings.sitename.replace('/','_') + '.sock')
31
+        logfile = os.path.join(
32
+            buildconf.LODEL2LOGDIR, 'uwsgi_%s.log' % (
33
+                Settings.sitename.replace('/', '_')))
34
+            
31 35
         if standalone.lower() == 'true':
32 36
             cmd='{uwsgi} --http-socket {addr}:{port} --module \
33
-plugins.webui.run --socket {sockfile}'
37
+plugins.webui.run --socket {sockfile} --logto {logfile}'
34 38
             cmd = cmd.format(
35 39
                         addr = Settings.webui.listen_address,
36 40
                         port = Settings.webui.listen_port,
37 41
                         uwsgi= Settings.webui.uwsgicmd,
38
-                        sockfile=sockfile)
42
+                        sockfile=sockfile,
43
+                        logfile = logfile)
39 44
             if Settings.webui.virtualenv is not None:
40 45
                 cmd += " --virtualenv %s" % Settings.webui.virtualenv
41 46
 
42 47
         elif Settings.webui.standalone == 'uwsgi':
43 48
             cmd = '{uwsgi} --ini ./plugins/webui/uwsgi/uwsgi.ini \
44
---socket {sockfile}'
49
+--socket {sockfile} --logto {logfile}'
45 50
             cmd = cmd.format(uwsgi = Settings.webui.uwsgicmd, 
46
-                sockfile = sockfile)
51
+                sockfile = sockfile, logfile = logfile)
47 52
         
48 53
         try:
49 54
             args = shlex.split(cmd)

+ 1
- 0
progs/slim/install_model/conf.d/lodel2.ini View File

@@ -2,6 +2,7 @@
2 2
 debug = False
3 3
 sitename = noname
4 4
 datasource_connectors = dummy_datasource
5
+session_handler = filesystem_session
5 6
 interface =
6 7
 
7 8
 [lodel2.editorialmodel]

+ 36
- 3
progs/slim/slim.py View File

@@ -12,6 +12,7 @@ import json
12 12
 import configparser
13 13
 import signal
14 14
 import subprocess
15
+from lodel import buildconf
15 16
 
16 17
 logging.basicConfig(level=logging.INFO)
17 18
 
@@ -247,7 +248,7 @@ def start_instances(names, foreground):
247 248
         os.chdir(store_datas[name]['path'])
248 249
         args = [sys.executable, 'loader.py']
249 250
         if foreground:
250
-            logging.info("Calling execl with : ", args)
251
+            logging.info("Calling execl with : %s" % args)
251 252
             os.execl(args[0], *args)
252 253
             return #only usefull if execl call fails (not usefull)
253 254
         else:
@@ -273,7 +274,7 @@ def stop_instances(names):
273 274
             os.kill(pid, signal.SIGINT)
274 275
         except ProcessLookupError:
275 276
             logging.warning("The instance %s seems to be in error, no process \
276
-with pid %d found" % (pids[name], name))
277
+with pid %d found" % (name, pids[name]))
277 278
         del(pids[name])
278 279
     save_pids(pids)
279 280
 
@@ -302,7 +303,7 @@ def get_specified(args):
302 303
         names = args.name
303 304
     else:
304 305
         names = None
305
-    return names
306
+    return sorted(names)
306 307
 
307 308
 ##@brief Saves store datas
308 309
 def save_datas(datas):
@@ -370,6 +371,28 @@ def details_instance(name, verbosity, batch):
370 371
                     msg += "\t"+line
371 372
             msg += "\n\t###########"
372 373
         print(msg)
374
+
375
+##@brief Given instance names generate nginx confs
376
+#@param names list : list of instance names
377
+def nginx_conf(names):
378
+    ret = """
379
+server {
380
+    listen 80;
381
+    server_name _;
382
+    include uwsgi_params;
383
+"""
384
+    for name in names:
385
+        name = name.replace('/', '_')
386
+        sockfile = os.path.join(buildconf.LODEL2VARDIR, 'uwsgi_sockets/')
387
+        sockfile = os.path.join(sockfile, name + '.sock')
388
+        ret += """
389
+    location /{instance_name}/ {{
390
+        uwsgi_pass unix://{sockfile};
391
+    }}""".format(instance_name =  name, sockfile = sockfile)
392
+    ret += """
393
+}
394
+"""
395
+    print(ret)
373 396
     
374 397
 ##@brief Returns instanciated parser
375 398
 def get_parser():
@@ -415,6 +438,9 @@ def get_parser():
415 438
     actions.add_argument('-m', '--make', metavar='TARGET', type=str,
416 439
         nargs="?", default='not',
417 440
         help='Run make for selected instances')
441
+    actions.add_argument('--nginx-conf', action='store_const',
442
+        default = False, const=True,
443
+        help="Output a conf for nginx given selected instances")
418 444
 
419 445
     startstop.add_argument('--stop', action='store_const', 
420 446
         default=False, const=True, help="Stop instances")
@@ -519,6 +545,13 @@ specified")
519 545
         conffile = get_conffile(name)
520 546
         os.system('editor "%s"' % conffile)
521 547
         exit(0)
548
+    elif args.nginx_conf:
549
+        names = get_specified(args)
550
+        if len(names) == 0:
551
+            parser.print_help()
552
+            print("\nSpecify at least 1 instance or use --all")
553
+            exit(1)
554
+        nginx_conf(names)
522 555
     elif args.interactive:
523 556
         #Run loader.py in foreground
524 557
         if args.name is None or len(args.name) != 1:

Loading…
Cancel
Save