########################################################################### ## Copyright (C) Wizardry and Steamworks 2017 - License: GNU GPLv3 ## ########################################################################### check program rTorrent with path "/etc/monit/templates/rtorrent.sh" start program "/bin/systemctl start rtorrent" stop program "/bin/systemctl stop rtorrent" if status != 0 then restart
#!/bin/bash ########################################################################### ## Copyright (C) Wizardry and Steamworks 2023 - License: GNU GPLv3 ## ########################################################################### # This script connects to rTorrent via SCGI, checks the hostname and the # # current PID of the rTorrent process and then returns 0 if the hostname # # and PID match the results from the system tools or 1 otherwise. # # # # Requirements: # # * sed # # * tr # # * netcat # # * grep # # * xmlstarlet # # # ########################################################################### ########################################################################### # CONFIGURATION # ########################################################################### # These settings correspond to the rTorrent setting: # network.scgi.open_port = "0.0.0.0:5000" # that enables the SCGI remote access functionality. RTORRENT_HOST="localhost" RTORRENT_PORT=5000 ########################################################################### # INTERNALS # ########################################################################### SESSION=$(cat <<EOF | \ sed -E 's/[ ]{2,}//g' | \ tr ' ' \\0 | \ tr -d '\n' | \ netcat "$RTORRENT_HOST" "$RTORRENT_PORT" | \ grep -Pzo "(?s)<methodResponse>.+?<\/methodResponse>" | \ xmlstarlet select -t -v /methodResponse/params/param[1]/value/string 63: CONTENT_LENGTH 62 SCGI 1 REQUEST_METHOD POST REQUEST_URI /RPC2 , <methodCall> <methodName>session.name</methodName> </methodCall> EOF ) HOST=`echo $SESSION | awk -F':' '{ print $1 }'` PID=`echo $SESSION | awk -F':' '{ print $2 }'` [ "$HOST" == `hostname` ] || exit 1 [ "$PID" == `pgrep -f /usr/bin/rtorrent` ] || exit 1 exit 0
For the contact, copyright, license, warranty and privacy terms for the usage of this website please see the contact, license, privacy, copyright.