From 83804cdcda9b5005490b09f6b273be8ea4ef569d Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Mon, 24 Oct 2016 15:33:27 +0200 Subject: [PATCH] library/roles/R: Get the files that list the R packages from subversion. --- R/defaults/main.yml | 6 +++++- R/tasks/r-packages-updater.yml | 10 ++++++++-- R/templates/update_r_packages.sh.j2 | 31 ++++++++++++++++++++++++++--- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/R/defaults/main.yml b/R/defaults/main.yml index 957e2008..b03a4c40 100644 --- a/R/defaults/main.yml +++ b/R/defaults/main.yml @@ -21,8 +21,12 @@ r_packages_main_state: present r_packages_state: '{{ r_packages_main_state }}' r_plugins_from_deb: True r_packages_cleanup: False +# r_packages_updater: False -# They need to be flat text files available via http +r_package_updater_via_subversion: True +r_package_updater_subversion_repo: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-analysis/RConfiguration/RPackagesManagement/ +r_packages_svn_base_dir: /srv/r_updater +# They need to be flat text files # 1 package per line #r_debian_packages_list_url # package[:cran mirror] diff --git a/R/tasks/r-packages-updater.yml b/R/tasks/r-packages-updater.yml index 97a1f6f3..2f6ad684 100644 --- a/R/tasks/r-packages-updater.yml +++ b/R/tasks/r-packages-updater.yml @@ -3,6 +3,9 @@ - name: Install the R packages updater script template: src=update_r_packages.sh.j2 dest=/usr/local/bin/update_r_packages owner=root group=root mode=0755 + - name: Create the R packages updater SVN base directory + file: dest={{ r_packages_svn_base_dir }} state=directory + - name: Cron job that installs new R packages, if any cron: name="install new R packages" user=root cron_file=install-r-packages minute="*/10" job="/usr/local/bin/update_r_packages install" state=present @@ -10,13 +13,16 @@ cron: name="install new R packages" user=root cron_file=upgrade-r-packages hour="3" job="/usr/local/bin/update_r_packages upgrade" state=present when: r_packages_updater - tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs' ] + tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater' ] - block: - name: Remove the R packages updater script file: dest=/usr/local/bin/update_r_packages state=absent + - name: Remove the R packages updater SVN base directory + file: dest={{ r_packages_svn_base_dir }} state=absent + - name: Remove the cron job that installs new R packages cron: name="install new R packages" user=root minute="*/10" cron_file=install-r-packages job="/usr/local/bin/update_r_packages install" state=absent @@ -24,4 +30,4 @@ cron: name="install new R packages" user=root cron_file=upgrade-r-packages hour="3" job="/usr/local/bin/update_r_packages upgrade" state=absent when: not r_packages_updater - tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs' ] + tags: [ 'r_software', 'r_pkg', 'r_plugins', 'r_plugins_github', 'r_cran_pkgs', 'r_github_pkgs', 'r_packages_updater' ] diff --git a/R/templates/update_r_packages.sh.j2 b/R/templates/update_r_packages.sh.j2 index 029573eb..41074e6c 100644 --- a/R/templates/update_r_packages.sh.j2 +++ b/R/templates/update_r_packages.sh.j2 @@ -12,6 +12,10 @@ TMP_FILES_DIR=/var/tmp/r_pkgs_update # We cannot answer questions DEBIAN_FRONTEND=noninteractive R_CRAN_MIRROR={{ r_cran_mirror_site }} +R_PKGS_FROM_SVN={{ r_package_updater_via_subversion }} +R_PKGS_SVN_DIR=RPackagesManagement +R_PKGS_SVN_URL={{ r_package_updater_subversion_repo }} +R_PKGS_SVN_BASE_DIR={{ r_packages_svn_base_dir }} # - debian packages list format: # one package per line DEB_PKGS_SKIP=0 @@ -28,7 +32,7 @@ GITHUB_PKGS_SKIP=0 R_PKGS_FROM_GITHUB_LIST_URL={{ r_github_packages_list_url | default('') }} R_PKGS_GITHUB= -trap "{ logger 'update_r_packages: trap intercepted, exiting.' ; cleanup ; exit 15 }" SIGHUP SIGINT SIGTERM +trap "logger 'update_r_packages: trap intercepted, exiting.' ; cleanup" SIGHUP SIGINT SIGTERM function cleanup() { logger "update_r_packages: cleaning up" @@ -53,7 +57,7 @@ function get_args() { } function fail() { - logger "Something went wrong, exiting." + logger "update_r_packages: Something went wrong, exiting." cleanup exit 1 } @@ -79,6 +83,7 @@ function init_env() { } function get_data_files() { + logger "update_r_packages: get the single files from http." # Get the packages list if [ -z $DEBIAN_PKGS_LIST_URL ] ; then DEB_PKGS_SKIP=1 @@ -106,6 +111,22 @@ function get_data_files() { fi } +function get_data_files_from_svn() { + logger "update_r_packages: files from a SVN repo." + if [ -d $R_PKGS_SVN_BASE_DIR/$R_PKGS_SVN_DIR ] ; then + logger "update_r_packages: SVN update" + cd $R_PKGS_SVN_BASE_DIR/$R_PKGS_SVN_DIR + svn update >/dev/null 2>&1 + else + cd $R_PKGS_SVN_BASE_DIR + logger "update_r_packages: first SVN checkout." + svn co $R_PKGS_SVN_URL >/dev/null 2>&1 + fi + PKGS_LIST=$R_PKGS_SVN_BASE_DIR/$R_PKGS_SVN_DIR/r_deb_pkgs.txt + R_PKGS_LIST=$R_PKGS_SVN_BASE_DIR/$R_PKGS_SVN_DIR/r_cran_pkgs.txt + R_PKGS_GITHUB=$R_PKGS_SVN_BASE_DIR/$R_PKGS_SVN_DIR/r_github_pkgs.txt +} + function debian_pkgs() { if [ $DEB_PKGS_SKIP -eq 0 ] ; then # Update the apt cache and install the packages in non interactive mode @@ -169,7 +190,11 @@ function r_github_pkgs() { usage get_args init_env -get_data_files +if [ $R_PKGS_FROM_SVN == 'True' ] ; then + get_data_files_from_svn +else + get_data_files +fi debian_pkgs r_cran_pkgs r_github_pkgs