diff --git a/smartgears/dataminer_app/defaults/main.yml b/smartgears/dataminer_app/defaults/main.yml index 66d8821..acf76ea 100644 --- a/smartgears/dataminer_app/defaults/main.yml +++ b/smartgears/dataminer_app/defaults/main.yml @@ -17,3 +17,6 @@ dataminer_wps_repository_url: 'http://maven.research-infrastructures.eu/nexus/co dataminer_wps_algorithms_svn: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/DataMinerConfiguration/algorithms/ dataminer_data_file_from_thredds: 'http://thredds.d4science.org/thredds/fileServer/public/netcdf/gebco_08_OCEANS_CLIMATOLOGY_METEOROLOGY_ATMOSPHERE_.nc' + +# dev, prod, preprod +dataminer_infra_reference: dev diff --git a/smartgears/dataminer_app/tasks/dataminer-app.yml b/smartgears/dataminer_app/tasks/dataminer-app.yml index 5816af0..1082ada 100644 --- a/smartgears/dataminer_app/tasks/dataminer-app.yml +++ b/smartgears/dataminer_app/tasks/dataminer-app.yml @@ -16,8 +16,14 @@ - name: Download the WPS algorithms from subversion subversion: repo={{ dataminer_wps_algorithms_svn }} dest={{ smartgears_user_home }}/wps_algorithms/algorithms checkout=yes force=yes update=yes - - name: Cron job that updates the algorithms repository - cron: name="SVN update the algorithms repository" minute="*/10" job="cd {{ smartgears_user_home }}/wps_algorithms/algorithms ; svn update > {{ smartgears_user_home }}/algorithms_updater.log 2>&1" user='{{ smartgears_user }}' state=present + - 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' ] + + - 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 + tags: [ 'tomcat', 'dataminer', 'wps', 'dataminer_algorithms' ] - name: Create a directory where to install the gebco_08.nc data file file: path={{ smartgears_user_home }}/data state=directory diff --git a/smartgears/dataminer_app/templates/algorithms-updater.j2 b/smartgears/dataminer_app/templates/algorithms-updater.j2 new file mode 100644 index 0000000..7f9671f --- /dev/null +++ b/smartgears/dataminer_app/templates/algorithms-updater.j2 @@ -0,0 +1,86 @@ +#!/bin/bash + +set -e +set -o pipefail + +INFRA_REFERENCE={{ dataminer_infra_reference }} +ADD_ALGORITHM_DIR={{ smartgears_user_home }}/algorithmInstaller +ADD_ALGORITHM_PATH={{ smartgears_user_home }}/algorithmInstaller/addAlgorithm.sh +ALGORITHMS_FILE={{ smartgears_user_home }}/wps_algorithms/algorithms/${INFRA_REFERENCE}/algorithms +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 +LOCK_FILE=${LOG_DIR}/.algorithms_updater.lock +ALGO_DIR={{ smartgears_user_home }}/wps_algorithms/algorithms +RUNNING_JOB= +RUNNING_JOB_RETVAL= + +trap "logger 'algorithms-updater: trap intercepted, exiting.' ; cleanup 1" SIGHUP SIGINT SIGTERM + +function cleanup() { + rm -fr $OUT_DIR + rm -f $LOCK_FILE + exit $1 +} + +function create_log_dir() { + if [ ! -d $LOG_DIR ] ; then + mkdir -p $LOG_DIR + fi +} + +function check_lock_file() { + # Create the lock file + if [ -f $LOCK_FILE ] ; then + set +o pipefail + set +e + RUNNING_JOB=$( ps auwwx | grep `cat /tmp/io` | grep -v grep ) + RUNNING_JOB_RETVAL=$? + if [ $RUNNING_JOB_RETVAL -eq 0 ] ; then + logger 'algorithms-updater: another job still running, exiting.' + rm -fr $OUT_DIR + exit 0 + else + rm -f $LOCK_FILE + fi + else + logger 'algorithms-updater: no other jobs running, proceeding.' + fi + set -o pipefail + set -e + echo "$$" > $LOCK_FILE +} + +function update_svn_repo() { + logger 'algorithms-updater: update the SVN repo' + cd $ALGO_DIR + svn update > $LOG_FILE 2>&1 +} + +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///g' $ALGORITHMS_TEMP_SCRIPT + sed -i -e 's/<\/notextile>//g' $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 }}' + $ALGORITHMS_TEMP_SCRIPT >> $LOG_FILE 2>&1 + else + logger 'algorithms-updater: {{ smartgears_user_home }}/algorithmInstaller/addAlgorithm.sh is not an executable, aborting' + cleanup 1 + fi +} + +# +# Main +# +create_log_dir +check_lock_file +update_svn_repo +algorithms_updater +cleanup 0