From 3943b3ed9a7a48fdf79f98032e3e35daac1bdbbd Mon Sep 17 00:00:00 2001 From: Terrtia Date: Mon, 24 Jun 2019 15:51:42 +0200 Subject: [PATCH 1/2] fix: [Update] add default update script --- bin/Update.py | 6 +++- update/default_update/Update.py | 45 ++++++++++++++++++++++++++++ update/default_update/Update.sh | 53 +++++++++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100755 update/default_update/Update.py create mode 100755 update/default_update/Update.sh diff --git a/bin/Update.py b/bin/Update.py index 45b72918..72ab1009 100755 --- a/bin/Update.py +++ b/bin/Update.py @@ -258,7 +258,11 @@ def launch_update_version(version, roll_back_commit, current_version_path, is_fo print('{}------------------------------------------------------------------'.format(TERMINAL_YELLOW)) print('- Launching Update: {}{}{} -'.format(TERMINAL_BLUE, version, TERMINAL_YELLOW)) print('-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --{}'.format(TERMINAL_DEFAULT)) - process = subprocess.Popen(['bash', update_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if not os.path.isfile(update_path): + update_path = os.path.join(os.environ['AIL_HOME'], 'update', 'default_update', 'Update.sh') + process = subprocess.Popen(['bash', update_path, version], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + else: + process = subprocess.Popen(['bash', update_path], stdout=subprocess.PIPE, stderr=subprocess.PIPE) while True: output = process.stdout.readline().decode() if output == '' and process.poll() is not None: diff --git a/update/default_update/Update.py b/update/default_update/Update.py new file mode 100755 index 00000000..c6f039ae --- /dev/null +++ b/update/default_update/Update.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python3 +# -*-coding:UTF-8 -* + +import os +import sys +import time +import redis +import argparse +import datetime +import configparser + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='AIL default update') + parser.add_argument('-t', help='version tag' , type=str, dest='tag', required=True) + args = parser.parse_args() + print(args) + + if not args.tag: + parser.print_help() + sys.exit(0) + + # remove space + update_tag = args.tag.replace(' ', '') + + start_deb = time.time() + + configfile = os.path.join(os.environ['AIL_BIN'], 'packages/config.cfg') + if not os.path.exists(configfile): + raise Exception('Unable to find the configuration file. \ + Did you set environment variables? \ + Or activate the virtualenv.') + cfg = configparser.ConfigParser() + cfg.read(configfile) + + r_serv = redis.StrictRedis( + host=cfg.get("ARDB_DB", "host"), + port=cfg.getint("ARDB_DB", "port"), + db=cfg.getint("ARDB_DB", "db"), + decode_responses=True) + + #Set current ail version + r_serv.set('ail:version', update_tag) + + #Set current ail version + r_serv.hset('ail:update_date', update_tag, datetime.datetime.now().strftime("%Y%m%d")) diff --git a/update/default_update/Update.sh b/update/default_update/Update.sh new file mode 100755 index 00000000..66ac6562 --- /dev/null +++ b/update/default_update/Update.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +echo "First argument value : $1" +if [ -z "$1" ] + then + echo "No tags version supplied" +fi + +[ -z "$AIL_HOME" ] && echo "Needs the env var AIL_HOME. Run the script from the virtual environment." && exit 1; +[ -z "$AIL_REDIS" ] && echo "Needs the env var AIL_REDIS. Run the script from the virtual environment." && exit 1; +[ -z "$AIL_ARDB" ] && echo "Needs the env var AIL_ARDB. Run the script from the virtual environment." && exit 1; +[ -z "$AIL_BIN" ] && echo "Needs the env var AIL_ARDB. Run the script from the virtual environment." && exit 1; +[ -z "$AIL_FLASK" ] && echo "Needs the env var AIL_FLASK. Run the script from the virtual environment." && exit 1; + +export PATH=$AIL_HOME:$PATH +export PATH=$AIL_REDIS:$PATH +export PATH=$AIL_ARDB:$PATH +export PATH=$AIL_BIN:$PATH +export PATH=$AIL_FLASK:$PATH + +GREEN="\\033[1;32m" +DEFAULT="\\033[0;39m" + +echo -e $GREEN"Shutting down AIL ..."$DEFAULT +bash ${AIL_BIN}/LAUNCH.sh -k +wait + +echo "" +bash ${AIL_BIN}/LAUNCH.sh -lav +wait + +echo "" +echo -e $GREEN"Updating AIL VERSION ..."$DEFAULT +echo "" +python ${AIL_HOME}/update/default_update/Update.py "-t $1" +wait +echo "" +echo "" + +echo "" +echo -e $GREEN"Shutting down ARDB ..."$DEFAULT +bash ${AIL_BIN}/LAUNCH.sh -k +wait + +echo "" +echo -e $GREEN"Update thirdparty ..."$DEFAULT +bash ${AIL_BIN}/LAUNCH.sh -t +wait + + +echo "" + +exit 0 From 469388da67c3b1ef2b74e9887401a8711ee597a1 Mon Sep 17 00:00:00 2001 From: Terrtia Date: Mon, 24 Jun 2019 16:03:51 +0200 Subject: [PATCH 2/2] fix: [Update] clean output --- update/default_update/Update.py | 1 - update/default_update/Update.sh | 1 - 2 files changed, 2 deletions(-) diff --git a/update/default_update/Update.py b/update/default_update/Update.py index c6f039ae..3fb511a1 100755 --- a/update/default_update/Update.py +++ b/update/default_update/Update.py @@ -13,7 +13,6 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='AIL default update') parser.add_argument('-t', help='version tag' , type=str, dest='tag', required=True) args = parser.parse_args() - print(args) if not args.tag: parser.print_help() diff --git a/update/default_update/Update.sh b/update/default_update/Update.sh index 66ac6562..5809fb38 100755 --- a/update/default_update/Update.sh +++ b/update/default_update/Update.sh @@ -1,6 +1,5 @@ #!/bin/bash -echo "First argument value : $1" if [ -z "$1" ] then echo "No tags version supplied"