From 29bb822f5c97890f977881f1f94b3130b8ad17a9 Mon Sep 17 00:00:00 2001 From: Kris Lamoureux Date: Wed, 11 Sep 2024 23:41:17 -0400 Subject: [PATCH] testing --- Dockerfile | 5 +++-- entrypoint.sh | 22 ++++++++++++++++++---- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index e92eec3..6899059 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,7 +22,6 @@ RUN apt-get update && \ RUN curl -s -o "/tmp/libtorrent-${LIBTORRENT_VERSION}.tar.gz" -L "$LIBTORRENT_URL" && \ FILE_HASH="$(sha256sum /tmp/libtorrent-${LIBTORRENT_VERSION}.tar.gz | cut -d' ' -f1)" && \ - echo hey; \ du -sh "/tmp/libtorrent-${LIBTORRENT_VERSION}.tar.gz"; \ if [ ! "$LIBTORRENT_HASH" = "$FILE_HASH" ]; then \ echo "SHA256 verification failed!" && \ @@ -69,7 +68,9 @@ COPY --from=build /tmp/rtorrent.rc.template /tmp/rtorrent.rc.template RUN apt-get update && \ apt-get install -y \ libcurl4 \ - libncursesw6 && \ + libncursesw6 \ + procps \ + screen && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* diff --git a/entrypoint.sh b/entrypoint.sh index 9c77626..04b88c1 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -1,5 +1,5 @@ #!/bin/bash -set -eu +set -eux # GID/UID USER_ID=${GUID:-1000} @@ -12,7 +12,7 @@ id -u rtorrent &>/dev/null || \ # Update group/user IDs groupmod -o -g "$GROUP_ID" rtorrent -usermod -o -u "$USER_ID" rtorrent 2>/dev/null +usermod -o -u "$USER_ID" rtorrent &>/dev/null # Copy default config if [ ! -e /home/rtorrent/.rtorrent.rc ]; then @@ -20,5 +20,19 @@ if [ ! -e /home/rtorrent/.rtorrent.rc ]; then chown rtorrent:rtorrent /home/rtorrent/.rtorrent.rc fi -# Execute as the rtorrent user -su - rtorrent -c "rtorrent" +# Trap for graceful shutdown +trap 'su - rtorrent -c "screen -S rtorrent -X stuff \"^Q\015\""; wait $SCREEN_PID' SIGTERM + +# Start rtorrent in a detached screen session +su - rtorrent -c "screen -dmS rtorrent rtorrent" & + +# Wait for the su process to finish +wait $! + +# Find screen PID and monitor it +SCREEN_PID=$(pgrep -f "SCREEN -dmS rtorrent") + +# Keep the script running until the screen session ends +tail --pid="$SCREEN_PID" -f /dev/null + +exit 0 \ No newline at end of file