library/roles/smartgears/dataminer_app/templates/algorithms-updater.j2: Better logging.

This commit is contained in:
Andrea Dell'Amico 2017-07-19 18:26:35 +02:00
parent 9450bfe6b1
commit 1660fb37b0
2 changed files with 45 additions and 7 deletions

View File

@ -19,7 +19,7 @@
- name: Install a script that updates the algorithms repository and adds the missing algorithms configurations
become_user: "{{ d4science_ansible_become_user | default('root') }}"
template: src=algorithms-updater.j2 dest=/usr/local/bin/algorithms-updater mode=0755
tags: [ 'tomcat', 'dataminer', 'wps', 'dataminer_algorithms' ]
tags: [ 'tomcat', 'dataminer', 'wps', 'dataminer_algorithms', 'dataminer_algorithms_script' ]
- name: Cron job that updates the algorithms repository and adds the missing algorithms configurations
cron: name="SVN update the algorithms repository" minute="*/10" job="/usr/local/bin/algorithms-updater" user='{{ smartgears_user }}' state=present

View File

@ -11,6 +11,7 @@ OUT_DIR=$( mktemp -d -t algorithms-updater.XXXXXXXXXX )
ALGORITHMS_TEMP_SCRIPT=$OUT_DIR/add_algorithms
LOG_DIR={{ smartgears_user_home }}/wps_algorithms_install_log/
LOG_FILE=${LOG_DIR}/algorithms_updater.log
ALGORITHMS_INSTALLED_FILE=${LOG_DIR}/already_installed_algorithms.txt
LOCK_FILE=${LOG_DIR}/.algorithms_updater.lock
ALGO_DIR={{ smartgears_user_home }}/wps_algorithms/algorithms
RUNNING_JOB=
@ -60,12 +61,49 @@ function update_svn_repo() {
function algorithms_updater() {
logger 'algorithms-updater: scan the algorithms list and build the algorithms script. Reference infra is {{ dataminer_infra_reference }}'
echo "#!/bin/bash" > $ALGORITHMS_TEMP_SCRIPT
echo "cd $ADD_ALGORITHM_DIR" >> $ALGORITHMS_TEMP_SCRIPT
echo "" >> $ALGORITHMS_TEMP_SCRIPT
cat $ALGORITHMS_FILE | awk -F \| '{ print $6 }' >> $ALGORITHMS_TEMP_SCRIPT
sed -i -e 's/<notextile>//g' $ALGORITHMS_TEMP_SCRIPT
sed -i -e 's/<\/notextile>//g' $ALGORITHMS_TEMP_SCRIPT
echo "#!/bin/bash" > $ALGORITHMS_TEMP_SCRIPT.head
echo "cd $ADD_ALGORITHM_DIR" >> $ALGORITHMS_TEMP_SCRIPT.head
echo "" >> $ALGORITHMS_TEMP_SCRIPT.head
awk -F \| '{ print $2 "|" $6 }' $ALGORITHMS_FILE > $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/<notextile>//g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
sed -i -e 's/<\/notextile>//g' $ALGORITHMS_TEMP_SCRIPT.algorithmslist
if [ ! -f $ALGORITHMS_INSTALLED_FILE ] ; then
touch $ALGORITHMS_INSTALLED_FILE
fi
set +o pipefail
set +e
while read algo ; do
ALGO_PRESENT=
ALGO_NAME=$( echo "$algo" | awk -F \| '{ print $1 }' )
ALGO_BODY=$( echo "$algo" | awk -F \| '{ print $2 }' )
ALGO_LINE=$( grep $ALGO_NAME $ALGORITHMS_INSTALLED_FILE )
ALGO_PRESENT=$?
if [ $ALGO_PRESENT -ne 0 ] ; then
echo "logger 'algorithms-updater: running the add command of algorithm $ALGO_NAME'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "logger 'algorithms-updater: the add command string is $ALGO_BODY'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "RETVAL=" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo '-------------------------------------------'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'Adding algorithm $ALGO_NAME'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'With command $ALGO_BODY'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo ''" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "$ALGO_BODY" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo 'RETVAL=$?' >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "echo 'Done.'"
echo "echo ''"
echo 'if [ $RETVAL -ne 0 ] ; then' >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " logger 'algorithms-updater: the adding of algorithm $ALGO_NAME failed'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "else" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " echo '$ALGO_NAME' >> $ALGORITHMS_INSTALLED_FILE" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo " logger 'algorithms-updater: the adding of algorithm $ALGO_NAME succeeded'" >> $ALGORITHMS_TEMP_SCRIPT.body_
echo "fi" >> $ALGORITHMS_TEMP_SCRIPT.body_
fi
done < ${ALGORITHMS_TEMP_SCRIPT}.algorithmslist
set -o pipefail
set -e
mv $ALGORITHMS_TEMP_SCRIPT.body_ $ALGORITHMS_TEMP_SCRIPT.body
cat $ALGORITHMS_TEMP_SCRIPT.head $ALGORITHMS_TEMP_SCRIPT.body > $ALGORITHMS_TEMP_SCRIPT
chmod 755 $ALGORITHMS_TEMP_SCRIPT
if [ -x $ADD_ALGORITHM_PATH ] ; then
logger 'algorithms-updater: add the algorithms configurations. Reference infra is {{ dataminer_infra_reference }}'