Skip to content

Commit 04139c1

Browse files
Merge branch 'release/0.14.2' into main
2 parents ba9cd93 + e346f6a commit 04139c1

File tree

4 files changed

+90
-29
lines changed

4 files changed

+90
-29
lines changed

NEWS.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
## Version 0.14.2 [2023-10-23]
2+
3+
### Miscellaneous
4+
5+
* `rsc start`, `rsc stop`, `rsc status`, `rsc reset`, etc. give more
6+
informative error messages when the machine where RStudio Server
7+
was most recently running on is not longer available.
8+
9+
* `rsc start --force` suggests calling `rsc reset --force` as a last
10+
resort if the machine, where RStudio Server was most recently
11+
running on, is not longer available.
12+
13+
114
## Version 0.14.1 [2023-10-16]
215

316
### Miscellaneous

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -333,20 +333,20 @@ As before, the RStudio Server is available at
333333
334334
```sh
335335
$ cd /path/to/software
336-
$ curl -L -O https://github.com/UCSF-CBI/rstudio-server-controller/archive/refs/tags/0.14.1.tar.gz
337-
$ tar xf 0.14.1.tar.gz
338-
$ PATH=/path/to/softwarerstudio-server-controller-0.14.1/bin:$PATH
336+
$ curl -L -O https://github.com/UCSF-CBI/rstudio-server-controller/archive/refs/tags/0.14.2.tar.gz
337+
$ tar xf 0.14.2.tar.gz
338+
$ PATH=/path/to/softwarerstudio-server-controller-0.14.2/bin:$PATH
339339
$ export PATH
340340
$ rsc --version
341-
0.14.1
341+
0.14.2
342342
```
343343
344344
To verify that the tool can find R and the RStudio Server executables,
345345
call:
346346
347347
```sh
348348
$ rsc --version --full
349-
rsc: 0.14.1
349+
rsc: 0.14.2
350350
RStudio Server: 2023.06.2+561 (Mountain Hydrangea) for Linux [/path/to/rstudio-server/bin/rstudio-server]
351351
R: 4.3.1 (2023-06-16) -- "Shortstop Beagle" [/path/to/R/bin/R]
352352
```

bin/incl/conditions.sh

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ function error {
3333
echo -e "${msg}"
3434

3535
if ${TRACEBACK_ON_ERROR}; then
36-
echo -e "${gray}Traceback:"
37-
for ((ii = 1; ii < "${#BASH_LINENO[@]}"; ii++ )); do
38-
printf "%d: %s() on line #%s in %s\\n" "$ii" "${FUNCNAME[$ii]}" "${BASH_LINENO[$((ii-1))]}" "${BASH_SOURCE[$ii]}"
39-
done
36+
echo -e "${gray}Traceback:"
37+
for ((ii = 1; ii < "${#BASH_LINENO[@]}"; ii++ )); do
38+
printf "%d: %s() on line #%s in %s\\n" "$ii" "${FUNCNAME[$ii]}" "${BASH_LINENO[$((ii-1))]}" "${BASH_SOURCE[$ii]}"
39+
done
4040
fi
4141

4242
if [[ -n "${ON_ERROR}" ]]; then
@@ -104,7 +104,24 @@ function message {
104104

105105

106106
function relay_condition {
107-
grep -q -E "^ERROR: " <<< "${1}" && error "${1#ERROR: }"
108-
grep -q -E "^WARNING: " <<< "${1}" && warn "${1#WARNING: }"
107+
local bfr=${1}
108+
mdebug "relay_condition() ..."
109+
for cond in "WARNING" "ERROR"; do
110+
bfr=$(sed -n "/${cond}:/,\$p" <<< "${1}")
111+
if grep -q -E "${cond}: " <<< "${bfr}"; then
112+
# traceback=$(sed -n '/Traceback:/,$p' <<< "${bfr}")
113+
114+
## Drop traceback
115+
bfr=$(sed '/Traceback:/,$d' <<< "${bfr}")
116+
117+
[[ ${cond} == "WARNING" ]] && warn "${bfr#WARNING: }"
118+
[[ ${cond} == "ERROR" ]] && error "${bfr#ERROR: }"
119+
fi
120+
done
121+
mdebug "relay_condition() ... done"
109122
}
110123

124+
125+
function prune_debug {
126+
sed '/DEBUG:/,$d' <<< "${1}"
127+
}

bin/rsc

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
### rsc config --full
6464
### rsc log
6565
###
66-
### Version: 0.14.1
66+
### Version: 0.14.2
6767
### Copyright: Henrik Bengtsson (2022-2023) and Harry Putnam (2022)
6868
### License: ISC
6969

@@ -270,7 +270,9 @@ function acquire_lock_file {
270270

271271
lockfile=${workdir}/pid.lock
272272
if [[ -f "${lockfile}" ]]; then
273-
error "${USER}, another RStudio Server instance of yours is already running on $(rserver_hostname) on this system. Call '${blue}rsc status --full${undo}' for details on how to reconnect. If you want to start a new instance, please terminate the existing one first by calling '${blue}rsc stop${undo}' from that machine."
273+
msg="${USER}, another RStudio Server instance of yours is already running on $(rserver_hostname) on this system. Call '${blue}rsc status --full${undo}' for details on how to reconnect. If you want to start a new instance, please terminate the existing one first by calling '${blue}rsc stop${undo}' from that machine."
274+
msg="${msg} As a last resort, for instance, if that machine is no longer available or down for maintenance, try ${blue}rsc reset --force${undo}."
275+
error "${msg}"
274276
fi
275277
echo "${PPID}" > "${lockfile}"
276278
}
@@ -313,6 +315,8 @@ function remove_stray_pid_file {
313315
local -i pid
314316
local rserver_hostname
315317
local what
318+
local res
319+
local -i okay
316320

317321
what=${1:?}
318322

@@ -360,8 +364,13 @@ function remove_stray_pid_file {
360364
mdebug " - hostname=$(hostname)"
361365

362366
## If this process is not running, remove the PID file
363-
pid=$(check_pid "${pid}" "${rserver_hostname}")
364-
relay_condition "${pid}"
367+
warn_if_check_pid_needs_ssh "${rserver_hostname}"
368+
res=$(check_pid "${pid}" "${rserver_hostname}" 2>&1)
369+
okay=$?
370+
mdebug " - checkpid() exit code: ${okay}"
371+
relay_condition "${res}"
372+
res=$(prune_debug "${res}")
373+
pid=${res}
365374
if [[ -z ${pid} ]]; then
366375
rm "${pid_file}"
367376
warn "Detected a stray PID file (${pid_file}). This file was removed, because it referred to a ${what} process (PID ${pid} on ${rserver_hostname}) which is no longer running."
@@ -473,12 +482,22 @@ function parse_revtunnel {
473482
echo "${port}"
474483
}
475484

485+
function warn_if_check_pid_needs_ssh {
486+
local hostname
487+
hostname=${1:-?}
488+
if ${ssh} && [[ "${hostname}" != "$(hostname)" ]]; then
489+
mwarn "Needs to SSH to ${hostname} to check whether process ${pid} is still alive. If you don't have SSH key authentication set up, you will be asked to enter your account password below."
490+
fi
491+
}
492+
476493
function check_pid {
477494
local -i pid
478495
local hostname
479496
local pid_exists
480497
local asterisk
481498
local timeout
499+
local res
500+
local -i okay
482501

483502
## If 'pid' is assigned an empty value, then it becomes pid=0,
484503
## because we declared it as an integer above.
@@ -497,9 +516,16 @@ function check_pid {
497516
[[ -d "/proc/${pid}" ]] && pid_exists=true
498517
elif ${ssh}; then
499518
mdebug "- Checking /proc/${pid} on ${hostname} over SSH ($(ssh_timeout)-second timeout)"
500-
mwarn "Needs to SSH to ${hostname} to check whether process ${pid} is still alive. If you don't have SSH key authentication set up, you will be asked to enter your account password below."
501519
#shellcheck disable=SC2029
502-
res=$(ssh -o ConnectTimeout="$(ssh_timeout)" "${hostname}" "[[ -d '/proc/${pid}' ]] && echo true || echo false" 2>&1) || error "Failed to check process PID ${pid} on ${hostname} over SSH. Reason was: ${res}"
520+
res=$(ssh -o ConnectTimeout="$(ssh_timeout)" "${hostname}" "[[ -d '/proc/${pid}' ]] && echo true || echo false" 2>&1)
521+
okay=$?
522+
mdebug "- Result: ${res}"
523+
mdebug "- Exit code: ${okay}"
524+
if [[ ${okay} -ne 0 ]]; then
525+
## Remove empty leading lines
526+
res=$(sed -e '/./,$!d' <<< "${res}")
527+
error "Failed to check process PID ${pid} on ${hostname} over SSH. Reason was: ${res}"
528+
fi
503529
[[ "${res}" == "true" ]] && pid_exists=true
504530
else
505531
mdebug "- Skipping check of /proc/${pid} on ${hostname}, because --no-ssh"
@@ -566,10 +592,10 @@ function find_login_host_via_who {
566592
bfr=$(echo "${bfr}" | sed -E 's/(.*[[:space:]]+[(]|[)][[:space:]]*)//g')
567593
mdebug "4. ${bfr}"
568594
## If hostname is an IP number, try to identify hostname
569-
if grep -q -E "^[[:digit:]]+[.][[:digit:]]+[.][[:digit:]]+[.][[:digit:]]+$" <<< "${bfr}"; then
570-
if [[ -f /etc/hosts ]] && grep -q -E "\b${bfr}\b" /etc/hosts; then
571-
bfr=$(grep -E "\b${bfr}\b" /etc/hosts | sed -E "s/\b${bfr}\b//g" | sed -E 's/[[:space:]]+/ /g' | sed -E 's/(^ | $)//g' | cut -d ' ' -f 1)
572-
fi
595+
if grep -q -E "^[[:digit:]]+[.][[:digit:]]+[.][[:digit:]]+[.][[:digit:]]+$" <<< "${bfr}"; then
596+
if [[ -f /etc/hosts ]] && grep -q -E "\b${bfr}\b" /etc/hosts; then
597+
bfr=$(grep -E "\b${bfr}\b" /etc/hosts | sed -E "s/\b${bfr}\b//g" | sed -E 's/[[:space:]]+/ /g' | sed -E 's/(^ | $)//g' | cut -d ' ' -f 1)
598+
fi
573599
mdebug "5. ${bfr}"
574600
fi
575601
fi
@@ -608,15 +634,20 @@ function rs_process_status {
608634
local pid_info
609635
local pid_stats
610636
local tmp
637+
local res
611638
pid=${1}
612639
hostname=${2}
613640

614641
mdebug "rs_process_status(pid=${pid}, hostname=${hostname}):"
615-
642+
616643
## Check if PID is still active?
617644
if [[ ${pid} -ne 0 ]]; then
618-
pid=$(check_pid "${pid}" "${hostname}")
619-
relay_condition "${pid}"
645+
warn_if_check_pid_needs_ssh "${hostname}"
646+
res=$(check_pid "${pid}" "${rserver_hostname}" 2>&1)
647+
okay=$?
648+
relay_condition "${res}"
649+
res=$(prune_debug "${res}")
650+
pid=${res}
620651
fi
621652

622653

@@ -1321,17 +1352,17 @@ function display_access_instructions {
13211352
msg="${msg} <${blue}http://$(ssh_revtunnel_hostname):$(ssh_revtunnel_port)${undo}>\n"
13221353
elif on_local_machine; then
13231354
msg="${msg} <${blue}http://127.0.0.1:$(rserver_port)${undo}>\n"
1324-
fi
1355+
fi
13251356
else
13261357
hostname=$(rserver_hostname)
13271358
port=$(rserver_port)
13281359
if [[ ${localport} == "port" ]]; then
1329-
localport=$port
1330-
fi
1360+
localport=$port
1361+
fi
13311362
msg="${msg} <${blue}http://127.0.0.1:${port}${undo}>\n"
13321363

1333-
if [[ -n ${SSH_CLIENT} ]] || [[ -n ${SSH_CONNECTION} ]] || [[ -n ${SSH_TTY} ]]; then
1334-
msg="${msg}\nImportantly, if you are running from a remote machine without direct access to ${hostname}, you need to set up SSH port forwarding first, which you can do by running:\n\\n ${blue}ssh -L ${localport}:${hostname}:${port} ${USER}@$(find_login_host)${undo}\n\nin a second terminal from your local computer.\n"
1364+
if [[ -n ${SSH_CLIENT} ]] || [[ -n ${SSH_CONNECTION} ]] || [[ -n ${SSH_TTY} ]]; then
1365+
msg="${msg}\nImportantly, if you are running from a remote machine without direct access to ${hostname}, you need to set up SSH port forwarding first, which you can do by running:\n\\n ${blue}ssh -L ${localport}:${hostname}:${port} ${USER}@$(find_login_host)${undo}\n\nin a second terminal from your local computer.\n"
13351366
fi
13361367
fi
13371368

0 commit comments

Comments
 (0)