Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
29bb822f5c |
@ -1,8 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -eu
|
set -eux
|
||||||
|
|
||||||
# Polling interval
|
|
||||||
SLEEP_INTERVAL=${SLEEP_INTERVAL:-2}
|
|
||||||
|
|
||||||
# GID/UID
|
# GID/UID
|
||||||
USER_ID=${GUID:-1000}
|
USER_ID=${GUID:-1000}
|
||||||
@ -23,18 +20,19 @@ if [ ! -e /home/rtorrent/.rtorrent.rc ]; then
|
|||||||
chown rtorrent:rtorrent /home/rtorrent/.rtorrent.rc
|
chown rtorrent:rtorrent /home/rtorrent/.rtorrent.rc
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# 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
|
# Start rtorrent in a detached screen session
|
||||||
su - rtorrent -c "screen -dmS rtorrent rtorrent" &
|
su - rtorrent -c "screen -dmS rtorrent rtorrent" &
|
||||||
|
|
||||||
# Wait for the su process to finish
|
# Wait for the su process to finish
|
||||||
wait $!
|
wait $!
|
||||||
|
|
||||||
# Find rtorrent PID and monitor it
|
# Find screen PID and monitor it
|
||||||
RTORRENT_PID="$(pgrep -f "^rtorrent$")"
|
SCREEN_PID=$(pgrep -f "SCREEN -dmS rtorrent")
|
||||||
|
|
||||||
# Trap for graceful shutdown
|
# Keep the script running until the screen session ends
|
||||||
trap 'su - rtorrent -c "kill -15 $RTORRENT_PID"' SIGTERM SIGINT
|
tail --pid="$SCREEN_PID" -f /dev/null
|
||||||
|
|
||||||
# Wait for PID
|
|
||||||
while kill -0 "$RTORRENT_PID" 2>/dev/null; do sleep "$SLEEP_INTERVAL"; done
|
|
||||||
exit 0
|
exit 0
|
Loading…
Reference in New Issue
Block a user