From b8cfeef09a2b4b30330aad4a336f240aa35ce7a4 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Tue, 13 Feb 2018 20:14:03 +0100 Subject: [PATCH 1/3] stanford-corenlp: Add a playbook that installs the startup script. Add that role to the core-nlp playbook. --- stanford-corenlp/defaults/main.yml | 23 +++++++++++++++++++ stanford-corenlp/tasks/main.yml | 18 +++++++++++++++ .../templates/stanford-corenlp.upstart.j2 | 12 ++++++++++ stanford-corenlp/templates/tint.upstart.j2 | 12 ++++++++++ 4 files changed, 65 insertions(+) create mode 100644 stanford-corenlp/defaults/main.yml create mode 100644 stanford-corenlp/tasks/main.yml create mode 100644 stanford-corenlp/templates/stanford-corenlp.upstart.j2 create mode 100644 stanford-corenlp/templates/tint.upstart.j2 diff --git a/stanford-corenlp/defaults/main.yml b/stanford-corenlp/defaults/main.yml new file mode 100644 index 00000000..14d6ef44 --- /dev/null +++ b/stanford-corenlp/defaults/main.yml @@ -0,0 +1,23 @@ +--- +# https://stanfordnlp.github.io/CoreNLP/ +stanford_corenlp_version: latest +stanford_corenlp_name: stanford-corenlp +stanford_corenlp_extension: war +stanford_corenlp_file: '{{ stanford_corenlp_name }}-{{ stanford_corenlp_version }}.{{ stanford_corenlp_extension }}' +stanford_corenlp_group_id: edu.stanford.nlp +stanford_corenlp_languages: + - arabic + - chinese + - english + - english_kbp + - french + - german + - spanish + +stanford_corenlp_user: corenlp +stanford_corenlp_base_dir: /opt/corenlp +stanford_corenlp_dist_dir: '{{ stanford_corenlp_base_dir }}/stanford-corenlp' +stanford_corenlp_log_dir: '{{ stanford_corenlp_base_dir }}/logs' +stanford_corenlp_cmd: 'java -cp "*" -mx4g edu.stanford.nlp.pipeline.StanfordCoreNLPServer -props StanfordCoreNLP-english.properties -port 9000 -timeout 60000' + +tint_service_cmd: './tint-server.sh -p 9001' diff --git a/stanford-corenlp/tasks/main.yml b/stanford-corenlp/tasks/main.yml new file mode 100644 index 00000000..08b592b6 --- /dev/null +++ b/stanford-corenlp/tasks/main.yml @@ -0,0 +1,18 @@ +--- +- block: + - name: Create the CoreNLP logs directory + file: dest={{ stanford_corenlp_log_dir }} state=directory owner={{ stanford_corenlp_user }} + + - name: Install the CoreNLP startup script + template: src=stanford-corenlp.upstart.j2 dest=/etc/init/stanford-corenlp.conf owner=root group=root mode=0644 + + - name: Ensure that CoreNLP is enabled and running + service: name=stanford-corenlp state=started enabled=yes + + - name: Install the tint service startup script + template: src=tint.upstart.j2 dest=/etc/init/tint.conf owner=root group=root mode=0644 + + - name: Ensure that the tint service is enabled and running + service: name=tint state=started enabled=yes + + tags: [ 'corenlp', 'stanford_corenlp' ] diff --git a/stanford-corenlp/templates/stanford-corenlp.upstart.j2 b/stanford-corenlp/templates/stanford-corenlp.upstart.j2 new file mode 100644 index 00000000..f2f34aac --- /dev/null +++ b/stanford-corenlp/templates/stanford-corenlp.upstart.j2 @@ -0,0 +1,12 @@ +description "Stanford CoreNLP" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [016] + +respawn +respawn limit 10 5 +setuid {{ stanford_corenlp_user }} +setgid {{ stanford_corenlp_user }} + +script + exec cd {{ stanford_corenlp_dist_dir }} {{ stanford_corenlp_cmd }} > {{ stanford_corenlp_log_dir }}/corenlp.log 2>&1 +end script diff --git a/stanford-corenlp/templates/tint.upstart.j2 b/stanford-corenlp/templates/tint.upstart.j2 new file mode 100644 index 00000000..48798252 --- /dev/null +++ b/stanford-corenlp/templates/tint.upstart.j2 @@ -0,0 +1,12 @@ +description "TINT service" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [016] + +respawn +respawn limit 10 5 +setuid {{ stanford_corenlp_user }} +setgid {{ stanford_corenlp_user }} + +script + exec cd {{ stanford_corenlp_dist_dir }}/tint {{ tint_service_cmd }} > {{ stanford_corenlp_log_dir }}/tint.log 2>&1 +end script From 86fe9f876fc53c8b4df628d1af884659ca70759c Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 14 Feb 2018 10:54:44 +0100 Subject: [PATCH 2/3] library/roles/stanford-corenlp: Fixes to the startup scripts. We have to rely on the upstart 'chdir' directive to change the working directory. --- stanford-corenlp/templates/stanford-corenlp.upstart.j2 | 3 ++- stanford-corenlp/templates/tint.upstart.j2 | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/stanford-corenlp/templates/stanford-corenlp.upstart.j2 b/stanford-corenlp/templates/stanford-corenlp.upstart.j2 index f2f34aac..15dd1495 100644 --- a/stanford-corenlp/templates/stanford-corenlp.upstart.j2 +++ b/stanford-corenlp/templates/stanford-corenlp.upstart.j2 @@ -6,7 +6,8 @@ respawn respawn limit 10 5 setuid {{ stanford_corenlp_user }} setgid {{ stanford_corenlp_user }} +chdir {{ stanford_corenlp_dist_dir }} script - exec cd {{ stanford_corenlp_dist_dir }} {{ stanford_corenlp_cmd }} > {{ stanford_corenlp_log_dir }}/corenlp.log 2>&1 + exec {{ stanford_corenlp_cmd }} > {{ stanford_corenlp_log_dir }}/corenlp.log 2>&1 end script diff --git a/stanford-corenlp/templates/tint.upstart.j2 b/stanford-corenlp/templates/tint.upstart.j2 index 48798252..2c21ae55 100644 --- a/stanford-corenlp/templates/tint.upstart.j2 +++ b/stanford-corenlp/templates/tint.upstart.j2 @@ -6,7 +6,8 @@ respawn respawn limit 10 5 setuid {{ stanford_corenlp_user }} setgid {{ stanford_corenlp_user }} +chdir {{ stanford_corenlp_dist_dir }}/tint script - exec cd {{ stanford_corenlp_dist_dir }}/tint {{ tint_service_cmd }} > {{ stanford_corenlp_log_dir }}/tint.log 2>&1 + exec {{ tint_service_cmd }} > {{ stanford_corenlp_log_dir }}/tint.log 2>&1 end script From 0115c852e3eda6824238b0c2eb7fa52dfab30956 Mon Sep 17 00:00:00 2001 From: Andrea Dell'Amico Date: Wed, 14 Feb 2018 12:48:24 +0100 Subject: [PATCH 3/3] library/roles/smartgears/dataminer_app/templates/algorithms-updater.j2: Fix the check of the lock file logic. See https://support.d4science.org/issues/11182 --- R/templates/update_r_packages.sh.j2 | 4 ++- .../templates/algorithms-updater.j2 | 28 ++++++++++++++----- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/R/templates/update_r_packages.sh.j2 b/R/templates/update_r_packages.sh.j2 index bed888dc..207707e3 100644 --- a/R/templates/update_r_packages.sh.j2 +++ b/R/templates/update_r_packages.sh.j2 @@ -77,7 +77,7 @@ function init_env() { OLDPROC=$( cat $LOCK_FILE ) OLDPROC_RUNNING=$( ps auwwx | grep -v grep | grep $OLDPROC | awk '{ print $2 }' ) RETVAL=$? - if [ $RETVAL -eq 0 ] ; then + if [ ! -z "$OLDPROC_RUNNING" ] ; then logger "update_r_packages: pid of the already running process: $OLDPROC_RUNNING" OLDPROC_RUNNING_TIME=$( ps -o etimes= -p ${OLDPROC_RUNNING} ) if [ $OLDPROC_RUNNING_TIME -gt $UPDATER_PROCESS_MAX_RUNTIME ] ; then @@ -92,6 +92,8 @@ function init_env() { logger "update_r_packages: lock file exist but the process not. Continuing." rm -fr $TMP_FILES_DIR fi + else + logger 'update_r_packages: no other jobs running, proceeding.' fi RETVAL= echo "$PROCNUM" > $LOCK_FILE diff --git a/smartgears/dataminer_app/templates/algorithms-updater.j2 b/smartgears/dataminer_app/templates/algorithms-updater.j2 index 866cfd54..bdaaa08d 100644 --- a/smartgears/dataminer_app/templates/algorithms-updater.j2 +++ b/smartgears/dataminer_app/templates/algorithms-updater.j2 @@ -3,6 +3,7 @@ set -e set -o pipefail +PROCNUM=$$ INFRA_REFERENCE={{ dataminer_infra_reference }} ADD_ALGORITHM_DIR={{ smartgears_user_home }}/algorithmInstaller ADD_ALGORITHM_PATH={{ smartgears_user_home }}/algorithmInstaller/addAlgorithm.sh @@ -15,7 +16,10 @@ ALGORITHMS_INSTALLED_FILE=${LOG_DIR}/already_installed_algorithms.txt ALGORITHMS_INSTALLED_SORTED_FILE=${LOG_DIR}/already_installed_algorithms_sorted.txt LOCK_FILE=${LOG_DIR}/.algorithms_updater.lock ALGO_DIR={{ dataminer_wps_algorithms_dest }}/${INFRA_REFERENCE} -RUNNING_JOB= +# In seconds. 60*60*6=21600s (6h) +UPDATER_PROCESS_MAX_RUNTIME=21600 +OLDPROC= +OLDPROC_RUNNING= RUNNING_JOB_RETVAL= trap "logger 'algorithms-updater: trap intercepted, exiting.' ; cleanup 1" SIGHUP SIGINT SIGTERM @@ -38,13 +42,23 @@ function check_lock_file() { if [ -f $LOCK_FILE ] ; then set +o pipefail set +e - RUNNING_JOB=$( /bin/pidof -s -x /usr/local/bin/algorithms-updater ) + OLDPROC=$( cat $LOCK_FILE ) + OLDPROC_RUNNING=$( ps auwwx | grep -v grep | grep $OLDPROC | awk '{ print $2 }' ) RUNNING_JOB_RETVAL=$? - if [ $RUNNING_JOB_RETVAL -eq 0 ] ; then - logger 'algorithms-updater: another job still running, exiting.' - rm -fr $OUT_DIR - exit 0 + if [ ! -z "$OLDPROC_RUNNING" ] ; then + logger "algorithms_updater: pid of the already running process: $OLDPROC_RUNNING" + OLDPROC_RUNNING_TIME=$( ps -o etimes= -p ${OLDPROC_RUNNING} ) + if [ $OLDPROC_RUNNING_TIME -gt $UPDATER_PROCESS_MAX_RUNTIME ] ; then + logger "algorithms_updater: process $OLDPROC_RUNNING was running for $OLDPROC_RUNNING_TIME seconds. Got stuck, killing it" + kill -9 $OLDPROC_RUNNING + rm -f $LOCK_FILE + else + logger "algorithms_updater: another process is running, exiting." + rm -fr $OUT_DIR + exit 0 + fi else + logger "algorithms_updater: lock file exist but the process not. Continuing." rm -f $LOCK_FILE fi else @@ -52,7 +66,7 @@ function check_lock_file() { fi set -o pipefail set -e - echo "$$" > $LOCK_FILE + echo "$PROCNUM" > $LOCK_FILE } function update_svn_repo() {