Skip to content

Commit

Permalink
rsession monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rongxin-liu committed Jul 9, 2024
1 parent 6ddd51e commit 97f41a0
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
8 changes: 8 additions & 0 deletions opt/cs50/bin/rstudio
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,19 @@ jq ".initial_working_directory = \"/workspaces/$RepositoryName\"" /opt/cs50/lib/
# Copy files into container
docker cp --quiet /opt/cs50/lib/rstudio/_icons.css rstudio:/tmp
docker cp --quiet /opt/cs50/lib/rstudio/rstudio-server.json rstudio:/etc/rstudio/
docker cp --quiet /opt/cs50/lib/rstudio/rsession.conf rstudio:/etc/rstudio/
docker cp --quiet /tmp/rstudio-prefs.json rstudio:/etc/rstudio/

# Copy monitoring script into container
sudo chmod +x /opt/cs50/lib/rstudio/monitor_rsession.sh
docker cp --quiet /opt/cs50/lib/rstudio/monitor_rsession.sh rstudio:/usr/local/bin/monitor_rsession.sh

# Start container
docker start "$NAME" > /dev/null

# Run the monitoring script in the background
docker exec -d "$NAME" sh -c "/usr/local/bin/monitor_rsession.sh"

# Inject CSS
docker exec "$NAME" sh -c "cat /tmp/_icons.css >> /usr/lib/rstudio-server/www/css/icons.css"

Expand Down
24 changes: 24 additions & 0 deletions opt/cs50/lib/rstudio/monitor_rsession.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/bash

cleanup() {
kill -TERM 1
}

# Wait for the rsession process to start
while ! pgrep -x "rsession" > /dev/null; do
sleep 1
done

# Monitor the rsession process
while true; do
if pgrep -x "rsession" > /dev/null; then
sleep 1
else
# If the rsession process is not running for more than 10 seconds, terminate the container
# Restarting R session shouldn't take more than 10 seconds
sleep 10
if ! pgrep -x "rsession" > /dev/null; then
cleanup
fi
fi
done
1 change: 1 addition & 0 deletions opt/cs50/lib/rstudio/rsession.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
session-timeout-minutes=30

0 comments on commit 97f41a0

Please sign in to comment.