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..3fb511a1 --- /dev/null +++ b/update/default_update/Update.py @@ -0,0 +1,44 @@ +#!/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() + + 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..5809fb38 --- /dev/null +++ b/update/default_update/Update.sh @@ -0,0 +1,52 @@ +#!/bin/bash + +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