I finally have success preventing my computer from entering sleep/suspend while the Plex Media Server is streaming on Arch with KDE-Plasma.
I know absolutely nothing about shell scripts.
Within Plasma Energy Saving there is an option to run a script. I point it to a simple script to check if the port is open.
I borrowed the command heavily from collindelker.com/wp/2015/07/plex-linux-prevent-sleep/http://
Don’t forget to make the script executable.
Here it is:
s=$(curl localhost:32400/status/sessions | sed -n "s/.*MediaContainer size=\"\(.*\)\".*/\1/p")
if [ $s -gt 0 ]
then
echo "[$(date +"%Y.%m.%d-%T")] Number of streamers = $s Plex session active, cancel suspend" >> /home/[user]/plex_sleep_log
exit 0
fi
if [ $s -eq 0 ]
then
echo "[$(date +"%Y.%m.%d-%T")] Number of streamers = $s Plex session -IN-active, going to sleep now zzzzzzzz........" >> /home/[user]/plex_sleep_log
qdbus org.kde.Solid.PowerManagement /org/freedesktop/PowerManagement Suspend
exit 0
fi
That’s it.
I’m sure there are more elegant solutions.
I’ve only tried this a couple of times so we’ll see how it works in the wild.
-i_o_i