From eabbd795c7915c8609e556b0afa564cdfb165eb2 Mon Sep 17 00:00:00 2001 From: Henrik Bengtsson Date: Wed, 17 Jan 2024 22:08:50 -0800 Subject: [PATCH 1/5] `rsc config` now also reports on RStudio User Configuration, e.g. the user preferences `rstudio-prefs.json` file. `rsc config` now reports on file sizes and modification timestamps. --- NEWS.md | 10 ++++++++ bin/incl/files.sh | 15 +++++++++++ bin/rsc | 63 ++++++++++++++++++++++++++++++++--------------- 3 files changed, 68 insertions(+), 20 deletions(-) diff --git a/NEWS.md b/NEWS.md index 0d812ab..eb58a27 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,13 @@ +## Version (development version) + +### New Features + + * `rsc config` now also reports on RStudio User Configuration, + e.g. the user preferences `rstudio-prefs.json` file. + + * `rsc config` now reports on file sizes and modification timestamps. + + ## Version 0.15.0 [2024-01-16] ### New Features diff --git a/bin/incl/files.sh b/bin/incl/files.sh index 9a3da5c..5cd2543 100644 --- a/bin/incl/files.sh +++ b/bin/incl/files.sh @@ -42,3 +42,18 @@ function wait_for_file { done [[ -f "${file}" ]] || error "Waited for file ${file}, but gave up after ${maxseconds} seconds" } + +function file_info { + local file=${1:?} + local -i size + local timestamp + + if [[ -f "${file}" ]]; then + size=$(stat --format="%s" "${file}") + timestamp=$(stat --format="%Y" "${file}") + timestamp=$(date -d "@${timestamp}" "+%F %T") + echo "${size} bytes; ${timestamp})" + else + echo "" + fi +} diff --git a/bin/rsc b/bin/rsc index 4ac6de6..f1e7c5b 100755 --- a/bin/rsc +++ b/bin/rsc @@ -63,7 +63,7 @@ ### rsc config --full ### rsc log ### -### Version: 0.15.0 +### Version: 0.15.0-9001 ### Copyright: Henrik Bengtsson (2022-2024) and Harry Putnam (2022) ### License: ISC @@ -248,8 +248,17 @@ function make_config_dir { # ------------------------------------------------------------------------- # RStudio Server configuration file # ------------------------------------------------------------------------- +function rstudio_config_home { + local path + path=${RSTUDIO_CONFIG_HOME} + if [[ -z ${path} ]]; then + path=${XDG_CONFIG_HOME:-$HOME/.config}/rstudio + fi + echo "${path}" +} + # Source: https://docs.rstudio.com/ide/server-pro/r_sessions/workspace_management.html#storage-location-customization -function rstudio_config_dir { +function rstudio_data_home { local path path=${RSTUDIO_DATA_HOME} if [[ -z ${path} ]]; then @@ -1593,41 +1602,42 @@ if [[ "${action}" == "config" ]]; then echo echo "RStudio Server Controller Storage:" - echo "XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-}" + echo "XDG_CONFIG_HOME: ${XDG_CONFIG_HOME:-}" workdir=$(config_dir) - echo "config-dir=${workdir}" + echo "config-dir: ${workdir}" - echo "lockfile=${workdir}/pid.lock" + file=${workdir}/pid.lock + echo "lockfile: ${file} [$(file_info "${file}")]" file=${workdir}/rserver.conf - echo "config-file=${file}" + echo "config-file: ${file} [$(file_info "${file}")]" files+=("${file}") file=${workdir}/rsession.conf - echo "config-file=${file}" + echo "config-file: ${file} [$(file_info "${file}")]" files+=("${file}") file=${workdir}/rsession.sh - echo "rsession-sh-file=${file}" + echo "rsession-sh-file: ${file} [$(file_info "${file}")]" files+=("${file}") file=${workdir}/rserver.sh - echo "rserver-sh-file=${file}" + echo "rserver-sh-file: ${file} [$(file_info "${file}")]" files+=("${file}") file=${workdir}/rserver.hostname - echo "rserver-sh-file=${file}" + echo "rserver-sh-file: ${file} [$(file_info "${file}")]" files+=("${file}") file=${workdir}/rserver.port - echo "rserver-sh-file=${file}" + echo "rserver-sh-file: ${file} [$(file_info "${file}")]" files+=("${file}") - echo "rserver-pid-file=$(rserver_pid_file)" - echo "rsession-pid-file=$(rsession_pid_file)" - echo "rsession-log-file=${workdir}/rsession.log" - echo "rserver-monitor-pid-file=$(rserver_monitor_pid_file)" + echo "rserver-pid-file: $(rserver_pid_file) [$(file_info "${file}")]" + echo "rsession-pid-file: $(rsession_pid_file) [$(file_info "${file}")]" + echo "rsession-log-file: ${workdir}/rsession.log [$(file_info "${file}")]" + echo "rserver-monitor-pid-file: $(rserver_monitor_pid_file) [$(file_info "${file}")]" if $full; then echo @@ -1641,12 +1651,25 @@ if [[ "${action}" == "config" ]]; then done fi + echo + echo "RStudio User Configuration:" + echo "XDG_CONFIG_HOME: ${XDG_CONFIG_HOME:-}" + echo "RSTUDIO_CONFIG_HOME: ${RSTUDIO_CONFIG_HOME:-}" + workdir=$(rstudio_config_home) + echo "RStudio config home: ${workdir}" + file=${workdir}/rstudio-prefs.json + echo "RStudio user preferences: ${file} [$(file_info "${file}")]" + if $full && [[ -f "${file}" ]]; then + cat "${file}" + echo + fi + echo echo "RStudio User State Storage:" - echo "XDG_DATA_HOME=${XDG_DATA_HOME:-}" - echo "RSTUDIO_DATA_HOME=${RSTUDIO_DATA_HOME:-}" - workdir=$(rstudio_config_dir) - echo "RStudio config folder=${workdir}" + echo "XDG_DATA_HOME: ${XDG_DATA_HOME:-}" + echo "RSTUDIO_DATA_HOME: ${RSTUDIO_DATA_HOME:-}" + workdir=$(rstudio_data_home) + echo "RStudio data home: ${workdir}" if $full && [[ -d "${workdir}" ]]; then du --human-readable --si --summarize "${workdir}"/* if [[ -d "${workdir}"/sessions/active/ ]]; then @@ -1685,7 +1708,7 @@ elif [[ "${action}" == "status" ]]; then workdir=$(config_dir) lockfile=${workdir}/pid.lock if [[ -f "${lockfile}" ]]; then - echo "lock file: exists (${lockfile})" + echo "lock file: exists (${lockfile} [$(file_info "${file}")])" else echo "lock file: does not exist" fi From 74ec0549ecab6e5575e92da721d509730f8de22a Mon Sep 17 00:00:00 2001 From: Henrik Bengtsson Date: Thu, 18 Jan 2024 09:53:44 -0800 Subject: [PATCH 2/5] Updated 'rsc status' did not report on the lock file meta data --- bin/rsc | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/bin/rsc b/bin/rsc index f1e7c5b..892b8c1 100755 --- a/bin/rsc +++ b/bin/rsc @@ -63,7 +63,7 @@ ### rsc config --full ### rsc log ### -### Version: 0.15.0-9001 +### Version: 0.15.0-9002 ### Copyright: Henrik Bengtsson (2022-2024) and Harry Putnam (2022) ### License: ISC @@ -305,12 +305,24 @@ function remove_stray_lockfile { lockfile=${workdir}/pid.lock mdebug "remove_stray_lockfile() ..." + mdebug "- file: ${lockfile} [$(file_info "${lockfile}")]" ## Nothing to do? - [[ ! -f "${lockfile}" ]] || [[ -n "$(rserver_pid true)" ]] || [[ -n "$(rsession_pid true)" ]] || [[ -n "$(ssh_revtunnel_pid true)" ]] && { mdebug "remove_stray_lockfile() ... done"; return 0; } + if [[ ! -f "${lockfile}" ]]; then + mdebug "remove_stray_lockfile() ... done" + return 0 + fi + + ## Is 'rserver', 'rsession', or an SSH reverse tunnel running? + if [[ -n "$(rserver_pid true)" ]] || [[ -n "$(rsession_pid true)" ]] || [[ -n "$(ssh_revtunnel_pid true)" ]]; then + mdebug "- skipping: detected an 'rserver', 'rsession', or an SSH reverse tunnel process running" + mdebug "remove_stray_lockfile() ... done" + return 0 + fi ## Here we know that there's neither a rserver PID nor a rsession PID rm "${lockfile}" + warn "Detected a stray lock file (${lockfile}). This file was removed, because there was no evidence that another instance was running on this system (no PID files for neither 'rserver' nor 'rsession' were found)." mdebug "remove_stray_lockfile() ... done" @@ -1571,6 +1583,7 @@ mdebug "args: [n=${#args[@]}] ${args[*]}" ## Enable terminal colors, if supported term_colors enable + ## Remove any stray files if ! ${force}; then mdebug "Removing stray files ..." @@ -1708,7 +1721,7 @@ elif [[ "${action}" == "status" ]]; then workdir=$(config_dir) lockfile=${workdir}/pid.lock if [[ -f "${lockfile}" ]]; then - echo "lock file: exists (${lockfile} [$(file_info "${file}")])" + echo "lock file: exists (${lockfile} [$(file_info "${lockfile}")])" else echo "lock file: does not exist" fi From a8b481d6e0fd844ff820aed5a0fa531d0da468ea Mon Sep 17 00:00:00 2001 From: Henrik Bengtsson Date: Thu, 25 Jan 2024 08:01:07 -0800 Subject: [PATCH 3/5] NEWS: Mention also 'rsc status' and file info (fix #99) --- NEWS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index eb58a27..79fe9fd 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,7 +5,8 @@ * `rsc config` now also reports on RStudio User Configuration, e.g. the user preferences `rstudio-prefs.json` file. - * `rsc config` now reports on file sizes and modification timestamps. + * `rsc config` and `rsc status` now report on file sizes and + modification timestamps. ## Version 0.15.0 [2024-01-16] From 4d0bb3b06a2c9ef403540efa987401ede37be288 Mon Sep 17 00:00:00 2001 From: Henrik Bengtsson Date: Thu, 25 Jan 2024 08:06:08 -0800 Subject: [PATCH 4/5] TEST: Adjust tests to recent tweaks in the 'rsc config' output format --- tests/rsc.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/rsc.bats b/tests/rsc.bats index 0a2b38c..afed0df 100644 --- a/tests/rsc.bats +++ b/tests/rsc.bats @@ -86,8 +86,8 @@ teardown() { assert_success assert_output --partial "RStudio Server Controller Storage:" assert_output --partial "RStudio User State Storage:" - assert_output --partial "XDG_CONFIG_HOME=$(dirname "$(mktemp -d)")" - assert_output --partial "XDG_DATA_HOME=$(dirname "$(mktemp -d)")" + assert_output --partial "XDG_CONFIG_HOME: $(dirname "$(mktemp -d)")" + assert_output --partial "XDG_DATA_HOME: $(dirname "$(mktemp -d)")" } @test "rsc config --full works" { From af7f91101751b7fda0b17dd51a6bb82769e85565 Mon Sep 17 00:00:00 2001 From: Henrik Bengtsson Date: Thu, 25 Jan 2024 08:06:54 -0800 Subject: [PATCH 5/5] rsc 0.15.1 --- NEWS.md | 2 +- README.md | 10 +++++----- bin/rsc | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/NEWS.md b/NEWS.md index 79fe9fd..5510786 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,4 @@ -## Version (development version) +## Version 0.15.1 [2024-01-25] ### New Features diff --git a/README.md b/README.md index 450cba3..a0543d9 100644 --- a/README.md +++ b/README.md @@ -333,12 +333,12 @@ As before, the RStudio Server is available at ```sh $ cd /path/to/software -$ curl -L -O https://github.com/UCSF-CBI/rstudio-server-controller/archive/refs/tags/0.15.0.tar.gz -$ tar xf 0.15.0.tar.gz -$ PATH=/path/to/softwarerstudio-server-controller-0.15.0/bin:$PATH +$ curl -L -O https://github.com/UCSF-CBI/rstudio-server-controller/archive/refs/tags/0.15.1.tar.gz +$ tar xf 0.15.1.tar.gz +$ PATH=/path/to/softwarerstudio-server-controller-0.15.1/bin:$PATH $ export PATH $ rsc --version -0.15.0 +0.15.1 ``` To verify that the tool can find R and the RStudio Server executables, @@ -346,7 +346,7 @@ call: ```sh $ rsc --version --full -rsc: 0.15.0 +rsc: 0.15.1 RStudio Server: 2023.06.2+561 (Mountain Hydrangea) for Linux [/path/to/rstudio-server/bin/rstudio-server] R: 4.3.1 (2023-06-16) -- "Shortstop Beagle" [/path/to/R/bin/R] ``` diff --git a/bin/rsc b/bin/rsc index 892b8c1..f6a6e68 100755 --- a/bin/rsc +++ b/bin/rsc @@ -63,7 +63,7 @@ ### rsc config --full ### rsc log ### -### Version: 0.15.0-9002 +### Version: 0.15.1 ### Copyright: Henrik Bengtsson (2022-2024) and Harry Putnam (2022) ### License: ISC