forked from ISTI-ansible-roles/ansible-roles
r_connector: add script and cron job that unmount stale sessions.
This commit is contained in:
parent
d27de1cf7c
commit
47f45b6d87
|
@ -10,6 +10,7 @@ r_connector_usershome: /home/
|
||||||
r_connector_userconfig: userconfig.csv
|
r_connector_userconfig: userconfig.csv
|
||||||
r_connector_adduserscript: /usr/local/bin/rusersadd
|
r_connector_adduserscript: /usr/local/bin/rusersadd
|
||||||
r_connector_workspace_unmount: /usr/local/bin/rconnector_unmount
|
r_connector_workspace_unmount: /usr/local/bin/rconnector_unmount
|
||||||
|
r_connector_check_stale_sessions: /usr/local/bin/rconnector_check_stale_sessions
|
||||||
r_connector_workspace_mountpoint: workspace
|
r_connector_workspace_mountpoint: workspace
|
||||||
r_connector_sleep_after_mount: 5
|
r_connector_sleep_after_mount: 5
|
||||||
r_connector_rstudio_cookie_key: /var/lib/rstudio-server/secure-cookie-key
|
r_connector_rstudio_cookie_key: /var/lib/rstudio-server/secure-cookie-key
|
||||||
|
@ -42,3 +43,6 @@ fuse_integration_name: sh-fuse-integration
|
||||||
fuse_integration_group_id: org.gcube.data-access
|
fuse_integration_group_id: org.gcube.data-access
|
||||||
fuse_integration_version: latest
|
fuse_integration_version: latest
|
||||||
fuse_integration_classifier: 'jar-with-dependencies'
|
fuse_integration_classifier: 'jar-with-dependencies'
|
||||||
|
r_connector_fuse_packages:
|
||||||
|
- fuse
|
||||||
|
- libfuse2
|
||||||
|
|
|
@ -69,29 +69,29 @@
|
||||||
become_user: root
|
become_user: root
|
||||||
template: src=rconnector_unmount dest={{ r_connector_workspace_unmount }} owner=root group=root mode=0555
|
template: src=rconnector_unmount dest={{ r_connector_workspace_unmount }} owner=root group=root mode=0555
|
||||||
|
|
||||||
|
- name: Install the script that checks for stale workspace mounts
|
||||||
|
become_user: root
|
||||||
|
template: src=rconnector_check_stale_sessions dest={{ r_connector_check_stale_sessions }} owner=root group=root mode=0555
|
||||||
|
|
||||||
|
- name: Install the cron job that regulary wipes out the stale workspace mounts
|
||||||
|
become: root
|
||||||
|
cron: name="Unmount the stale workspace sessions" special_time=hourly job="{{ r_connector_check_stale_sessions }} >/dev/null 2>&1"
|
||||||
|
|
||||||
- name: Crete the directory that will host the RConfiguration stuff
|
- name: Crete the directory that will host the RConfiguration stuff
|
||||||
become_user: root
|
become_user: root
|
||||||
file: dest={{ r_connector_rprofile_base_dir }} owner={{ d4science_user }} group={{ d4science_user }} state=directory
|
file: dest={{ r_connector_rprofile_base_dir }} owner={{ d4science_user }} group={{ d4science_user }} state=directory
|
||||||
|
|
||||||
- name: Download the fuse jar-with-dependencies
|
- name: Download the fuse jar-with-dependencies
|
||||||
become_user: root
|
become_user: root
|
||||||
get_url:
|
maven_artifact: artifact_id={{ fuse_integration_name }} version={{ fuse_integration_version }} group_id={{ fuse_integration_group_id }} extension={{ fuse_integration_extension }} repository_url={{ smartgears_global_base_url }} classifier={{ fuse_integration_classifier }} dest=/usr/local/lib/{{ fuse_integration_file }}
|
||||||
url: '{{ fuse_integration_jar_url }}'
|
|
||||||
dest: /usr/local/lib/{{ fuse_integration_file }}
|
|
||||||
force: yes
|
|
||||||
mode: 0555
|
|
||||||
|
|
||||||
- name: Download the fuse jar-with-dependencies
|
|
||||||
maven_artifact: artifact_id={{ fuse_integration_name }} version={{ fuse_integration_version | default(omit) }} group_id={{ fuse_integration_group_id }} extension={{ fuse_integration_extension | default('jar') }} repository_url={{ smartgears_global_base_url }} classifier={{ fuse_integration_classifier }} dest=/usr/local/lib/{{ fuse_integration_file }
|
|
||||||
|
|
||||||
# shell: cd /usr/local/lib/ ; wget http://maven.research-infrastructures.eu/nexus/content/repositories/gcube-snapshots/org/gcube/data-access/sh-fuse-integration/1.0.0-SNAPSHOT/sh-fuse-integration-1.0.0-20190312.161452-1-jar-with-dependencies.jar
|
|
||||||
# args:
|
|
||||||
# creates: /usr/local/lib/sh-fuse-integration-jar-with-dependencies.jar
|
|
||||||
|
|
||||||
|
|
||||||
- name: Get the svn repository that provides the .Rprofile
|
- name: Get the svn repository that provides the .Rprofile
|
||||||
subversion: repo={{ r_connector_rprofile_svn_url }} dest={{ r_connector_rprofile_path }}
|
subversion: repo={{ r_connector_rprofile_svn_url }} dest={{ r_connector_rprofile_path }}
|
||||||
|
|
||||||
|
- name: Install /etc/R/Rprofile.site as a symlink to the svn repository
|
||||||
|
become_user: root
|
||||||
|
file: src={{ r_connector_rprofile_path }}/.Rprofile dest=/etc/R/Rprofile.site state=link force=yes
|
||||||
|
|
||||||
- name: Install the cron job that regulary updates the Rprofile
|
- name: Install the cron job that regulary updates the Rprofile
|
||||||
cron: name="Update the RStudioConfiguration repo" special_time=daily job="cd {{ r_connector_rprofile_path }} ; svn update >/dev/null 2>&1"
|
cron: name="Update the RStudioConfiguration repo" special_time=daily job="cd {{ r_connector_rprofile_path }} ; svn update >/dev/null 2>&1"
|
||||||
|
|
||||||
|
@ -102,15 +102,15 @@
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
# Additional fuse packages
|
# Additional fuse packages
|
||||||
- name: Install the libfuse package
|
- name: Install the fuse required packages
|
||||||
apt: pkg=libfuse2 state=present update_cache=yes cache_valid_time=3600
|
apt: pkg={{ r_connector_fuse_packages }} state=present update_cache=yes cache_valid_time=3600
|
||||||
|
|
||||||
- name: Install the fuse package
|
when: r_connector_install
|
||||||
apt: pkg=fuse state=present update_cache=yes cache_valid_time=3600
|
tags: [ 'smartgears', 'r_connector', 'tomcat' ]
|
||||||
|
|
||||||
- block:
|
- block:
|
||||||
- name: Reconfigure the Java environment for R
|
- name: Reconfigure the Java environment for R
|
||||||
shell: export JAVA_HOME={{ jdk_java_home }} ; export J2SDKDIR={{ jdk_java_home ; export J2REDIR={{ jdk_java_home }}/jre ; R CMD javareconf
|
shell: export JAVA_HOME={{ jdk_java_home }} ; export J2SDKDIR={{ jdk_java_home }} ; export J2REDIR={{ jdk_java_home }}/jre ; R CMD javareconf
|
||||||
when: jdk_java_home is defined
|
when: jdk_java_home is defined
|
||||||
|
|
||||||
become: True
|
become: True
|
||||||
|
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/bin/bash
|
||||||
|
DEBUG=1
|
||||||
|
if [ $DEBUG -eq 0 ] ; then
|
||||||
|
set -x
|
||||||
|
exec 2>/var/tmp/rconnector_check_stale_sessions.log
|
||||||
|
fi
|
||||||
|
# We use logger to log directly to syslog
|
||||||
|
LOG_PREFIX="r-connector check_stale_sessions:"
|
||||||
|
|
||||||
|
UNMOUNT_SCRIPT="{{ r_connector_workspace_unmount }}"
|
||||||
|
RSTUDIO_BIN="/usr/sbin/rstudio-server"
|
||||||
|
ACTIVE_MOUNTS=
|
||||||
|
ACTIVE_MOUNTS_F=$( mktemp /tmp/active_mounts.XXXXX )
|
||||||
|
ACTIVE_SESSIONS_LIST=
|
||||||
|
ACTIVE_SESSIONS_LIST_F=$( mktemp /tmp/active_sessions.XXXXX )
|
||||||
|
STALE_SESSIONS_LIST=
|
||||||
|
|
||||||
|
list_mounts() {
|
||||||
|
ACTIVE_MOUNTS=$( /bin/ps auwwx | grep -i java | grep "fuse-integration" | grep sudo | grep -v grep | awk '{print $13}' | sort > "$ACTIVE_MOUNTS_F" )
|
||||||
|
if [ $DEBUG -eq 0 ] ; then
|
||||||
|
for m in $ACTIVE_MOUNTS ; do
|
||||||
|
logger "$LOG_PREFIX Active session: $m"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
check_running_sessions() {
|
||||||
|
ACTIVE_SESSIONS_LIST=$( $RSTUDIO_BIN active-sessions | grep rsession | grep -v grep | awk '{print $5 }' | sort > "$ACTIVE_SESSIONS_LIST_F" )
|
||||||
|
if [ $DEBUG -eq 0 ] ; then
|
||||||
|
for ses in $ACTIVE_SESSIONS_LIST ; do
|
||||||
|
logger "$LOG_PREFIX Active mount: $ses"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
umount_stale_sessions() {
|
||||||
|
STALE_SESSIONS_LIST=$( /usr/bin/comm -23 "$ACTIVE_MOUNTS_F" "$ACTIVE_SESSIONS_LIST_F" )
|
||||||
|
for stale_s in $STALE_SESSIONS_LIST ; do
|
||||||
|
if [ $DEBUG -eq 0 ] ; then
|
||||||
|
logger "$LOG_PREFIX Stale session: $stale_s"
|
||||||
|
fi
|
||||||
|
$UNMOUNT_SCRIPT "$stale_s"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
list_mounts
|
||||||
|
check_running_sessions
|
||||||
|
umount_stale_sessions
|
||||||
|
rm -f "$ACTIVE_MOUNTS_F" "$ACTIVE_SESSIONS_LIST_F"
|
||||||
|
exit 0
|
|
@ -30,13 +30,13 @@ WORKSPACE_MOUNT_DIR="$HDIR/{{ r_connector_workspace_mountpoint }}"
|
||||||
|
|
||||||
workspace_mount () {
|
workspace_mount () {
|
||||||
if [ $REMOTE_WORKSPACE_MOUNT -eq 0 ] ; then
|
if [ $REMOTE_WORKSPACE_MOUNT -eq 0 ] ; then
|
||||||
{{ r_connector_workspace_unmount }} "$USER"
|
"{{ r_connector_workspace_unmount }}" "$USER"
|
||||||
logger "$LOG_PREFIX: Trying to mount the remote workspace"
|
logger "$LOG_PREFIX: Trying to mount the remote workspace"
|
||||||
[ $DEBUG -eq 0 ] && logger "$LOG_PREFIX: Mount command is sudo -u $USER /usr/bin/java -jar $FUSE_INTEGRATION_JAR $GCUBE_TOKEN $GCUBE_SCOPES $WORKSPACE_MOUNT_DIR"
|
[ $DEBUG -eq 0 ] && logger "$LOG_PREFIX: Mount command is sudo -u $USER /usr/bin/java -jar $FUSE_INTEGRATION_JAR $GCUBE_TOKEN $GCUBE_SCOPES $WORKSPACE_MOUNT_DIR"
|
||||||
sudo /bin/mkdir -p "$WORKSPACE_MOUNT_DIR"
|
sudo /bin/mkdir -p "$WORKSPACE_MOUNT_DIR"
|
||||||
sudo /bin/chown "${USER}" "$WORKSPACE_MOUNT_DIR"
|
sudo /bin/chown "${USER}" "$WORKSPACE_MOUNT_DIR"
|
||||||
sudo -u "$USER" /usr/bin/java -jar $FUSE_INTEGRATION_JAR $GCUBE_TOKEN $GCUBE_SCOPES $WORKSPACE_MOUNT_DIR > "/var/tmp/workspace_${USER}.log" 2>&1 &
|
sudo -u "$USER" /usr/bin/java -jar $FUSE_INTEGRATION_JAR $GCUBE_TOKEN $GCUBE_SCOPES $WORKSPACE_MOUNT_DIR > "/var/tmp/workspace_${USER}.log" 2>&1 &
|
||||||
sleep $SLEEP_AFTER_MOUNT
|
sleep "$SLEEP_AFTER_MOUNT"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue