|
@@ -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:
|