1
0
Fork 0
mirror of https://github.com/yweber/lodel2.git synced 2025-10-31 19:49:02 +01:00

webui & slim enhancement

Adds a LODEL2LOGDIR to buildconf.py
Adds a nginx-conf option to slim
...
This commit is contained in:
Yann 2016-09-16 16:44:47 +02:00
commit ca4952a264
6 changed files with 59 additions and 9 deletions

View file

@ -11,7 +11,17 @@ lodeldir=$(pkgpythondir)/
distclean-local:
-rm Makefile Makefile.in
do_subst = sed -e 's,\[@\]LODEL2_VARDIR\[@\],$(localstatedir)/lodel2/,g'
logdir = $(localstatedir)/log/lodel2/
do_subst = sed -e 's,\[@\]LODEL2_VARDIR\[@\],$(localstatedir)/lodel2/,g' \
-e 's,\[@\]LODEL2_LOGDIR\[@\],$(logdir),g'
install-data-hook:
-mkdir -p $(logdir)
uninstall-hook:
-rmdir $(logdir)
buildconf.py: buildconf.py.am
$(do_subst) < $(srcdir)/buildconf.py.am > buildconf.py

View file

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

View file

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

View file

@ -28,22 +28,27 @@ def uwsgi_fork(hook_name, caller, payload):
os.mkdir(sockfile)
sockfile = os.path.join(sockfile,
Settings.sitename.replace('/','_') + '.sock')
logfile = os.path.join(
buildconf.LODEL2LOGDIR, 'uwsgi_%s.log' % (
Settings.sitename.replace('/', '_')))
if standalone.lower() == 'true':
cmd='{uwsgi} --http-socket {addr}:{port} --module \
plugins.webui.run --socket {sockfile}'
plugins.webui.run --socket {sockfile} --logto {logfile}'
cmd = cmd.format(
addr = Settings.webui.listen_address,
port = Settings.webui.listen_port,
uwsgi= Settings.webui.uwsgicmd,
sockfile=sockfile)
sockfile=sockfile,
logfile = logfile)
if Settings.webui.virtualenv is not None:
cmd += " --virtualenv %s" % Settings.webui.virtualenv
elif Settings.webui.standalone == 'uwsgi':
cmd = '{uwsgi} --ini ./plugins/webui/uwsgi/uwsgi.ini \
--socket {sockfile}'
--socket {sockfile} --logto {logfile}'
cmd = cmd.format(uwsgi = Settings.webui.uwsgicmd,
sockfile = sockfile)
sockfile = sockfile, logfile = logfile)
try:
args = shlex.split(cmd)

View file

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

View file

@ -12,6 +12,7 @@ import json
import configparser
import signal
import subprocess
from lodel import buildconf
logging.basicConfig(level=logging.INFO)
@ -247,7 +248,7 @@ def start_instances(names, foreground):
os.chdir(store_datas[name]['path'])
args = [sys.executable, 'loader.py']
if foreground:
logging.info("Calling execl with : ", args)
logging.info("Calling execl with : %s" % args)
os.execl(args[0], *args)
return #only usefull if execl call fails (not usefull)
else:
@ -273,7 +274,7 @@ def stop_instances(names):
os.kill(pid, signal.SIGINT)
except ProcessLookupError:
logging.warning("The instance %s seems to be in error, no process \
with pid %d found" % (pids[name], name))
with pid %d found" % (name, pids[name]))
del(pids[name])
save_pids(pids)
@ -302,7 +303,7 @@ def get_specified(args):
names = args.name
else:
names = None
return names
return sorted(names)
##@brief Saves store datas
def save_datas(datas):
@ -370,6 +371,28 @@ def details_instance(name, verbosity, batch):
msg += "\t"+line
msg += "\n\t###########"
print(msg)
##@brief Given instance names generate nginx confs
#@param names list : list of instance names
def nginx_conf(names):
ret = """
server {
listen 80;
server_name _;
include uwsgi_params;
"""
for name in names:
name = name.replace('/', '_')
sockfile = os.path.join(buildconf.LODEL2VARDIR, 'uwsgi_sockets/')
sockfile = os.path.join(sockfile, name + '.sock')
ret += """
location /{instance_name}/ {{
uwsgi_pass unix://{sockfile};
}}""".format(instance_name = name, sockfile = sockfile)
ret += """
}
"""
print(ret)
##@brief Returns instanciated parser
def get_parser():
@ -415,6 +438,9 @@ def get_parser():
actions.add_argument('-m', '--make', metavar='TARGET', type=str,
nargs="?", default='not',
help='Run make for selected instances')
actions.add_argument('--nginx-conf', action='store_const',
default = False, const=True,
help="Output a conf for nginx given selected instances")
startstop.add_argument('--stop', action='store_const',
default=False, const=True, help="Stop instances")
@ -519,6 +545,13 @@ specified")
conffile = get_conffile(name)
os.system('editor "%s"' % conffile)
exit(0)
elif args.nginx_conf:
names = get_specified(args)
if len(names) == 0:
parser.print_help()
print("\nSpecify at least 1 instance or use --all")
exit(1)
nginx_conf(names)
elif args.interactive:
#Run loader.py in foreground
if args.name is None or len(args.name) != 1: