Skip to content

Commit 1f92403

Browse files
Add support for rsc reset --user-state-dir (fix #110)
1 parent 168e943 commit 1f92403

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

NEWS.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
### New Features
44

5+
* Add support for `rsc reset --user-state-dir`, which will backup
6+
the user's RStudio state storage folder
7+
(e.g. `~/.local/share/rstudio`) to a dated tar file, and then
8+
remove that folder. This can be used as a last resort when the
9+
RStudio Server gets stuck at "R is taking longer to start than
10+
usual" after logging in.
11+
512
* Add environment variable `RSC_RSESSION_TIMEOUT_SUSPEND` to control
613
whether a timed out R session should be suspended to disk. If `1`
714
(default), it will be suspended to disk, otherwise not.

bin/rsc

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
### stop Stop the RStudio Server and any R and SSH sessions
1111
### status Check whether the RStudio Server is running or not
1212
### config Output configuration details
13-
### reset Wipe all configuration
13+
### reset Wipe configuration or storage
1414
### log Output rsession log
1515
###
1616
### Options:
@@ -29,7 +29,7 @@
2929
### should be exposed. (Default: local host and --port)
3030
### --random-password Generate a random password assigned to 'RSC_PASSWORD'
3131
### --force Force an action
32-
### --full Output more information
32+
### --full More of the same, e.g. output or file removal
3333
### --no-ssh Skip anything involving SSH
3434
###
3535
### --env-pattern=<re> Regular expression matching environment variables to be
@@ -43,6 +43,8 @@
4343
### argument is only for the instructions on how to set up
4444
### SSH port forwarding, in case RStudio Server runs on a
4545
### remote machine
46+
### --user-state-data Causes 'reset' to backup user's RStudio State Storage
47+
### folder to a tar file and the remove the folder
4648
### ---
4749
###
4850
### Example:
@@ -63,7 +65,11 @@
6365
### rsc config --full
6466
### rsc log
6567
###
66-
### Version: 0.16.2-9002
68+
### rsc reset
69+
### rsc reset --user-state-data
70+
### rsc reset --force
71+
###
72+
### Version: 0.16.2-9003
6773
### Copyright: Henrik Bengtsson (2022-2024) and Harry Putnam (2022)
6874
### License: ISC
6975

@@ -1535,6 +1541,11 @@ while [[ $# -gt 0 ]]; do
15351541
full=true
15361542
elif [[ "$1" == "--no-ssh" ]]; then
15371543
ssh=false
1544+
elif [[ "$1" == "--user-state-dir" ]]; then
1545+
if [[ ${action} != "reset" ]]; then
1546+
error "Option '$1' only works with the 'reset' command"
1547+
fi
1548+
action="reset-user-state-dir"
15381549
elif [[ "$1" == "--random-password" ]]; then
15391550
RSC_PASSWORD="random"
15401551
## Options (--key=value):
@@ -1843,6 +1854,7 @@ elif [[ "${action}" == "stop" ]]; then
18431854

18441855
message "RStudio Server stopped"
18451856
elif [[ "${action}" == "reset" ]]; then
1857+
## Reset the RStudio Server Controller Configuration?
18461858
workdir=$(config_dir)
18471859
if [[ -d "${workdir}" ]]; then
18481860
files=("$(rsession_pid_file)" "${workdir}/rserver.pid" "${workdir}/rserver_monitor.pid" "${workdir}/rserver.hostname" "${workdir}/rserver.port" "${workdir}/pid.lock")
@@ -1860,6 +1872,19 @@ elif [[ "${action}" == "reset" ]]; then
18601872
fi
18611873
rm -rf "${workdir}"
18621874
fi
1875+
elif [[ "${action}" == "reset-user-state-dir" ]]; then
1876+
## Reset the RStudio User State Storage?
1877+
workdir=$(rstudio_data_home)
1878+
if [[ -d "${workdir}" ]]; then
1879+
now=$(date +"%Y%m%dT%H%M%S")
1880+
dest="rstudio-config_${now}.tar"
1881+
tar -c -f "${dest}" "${workdir}"
1882+
if [[ -f "${dest}" ]]; then
1883+
message "Backed up your personal RStudio User State Storage: ${PWD}/${dest} [$(file_info "${dest}")]"
1884+
rm -r -f "${workdir}"
1885+
message "Removed your personal RStudio User State Storage: ${workdir}"
1886+
fi
1887+
fi
18631888
elif [[ "${action}" == "wait" ]]; then
18641889
wait_for_rserver
18651890
rserver_hostname

0 commit comments

Comments
 (0)