I use this script, which checks if Plex has started transcoding and stops Trex if that is true.
It starts Trex after Plex has finished transcoding.
It is for Nvidia cards only. Feel free to use it and modify it to your needs.
#!/bin/bash
# Check if nvidia-smi daemon is running and start it if not.
if [[ `ps ax | grep nvidia-smi | grep daemon` == "" ]]; then
/usr/bin/nvidia-smi daemon
fi
sleep 300 # Wait until array is online and all dockers are started. Comment this out if you are testing the script.
TREX=`docker container ls -q --filter name=trex*`
while true; do
if [[ `/usr/bin/nvidia-smi | grep Plex` == "" ]]; then
# If Plex is not transcoding, start the trex-miner container if it is not running.
if [[ `docker ps | grep $TREX` == "" ]]; then
echo "No Plex, starting Trex."
docker start $TREX
fi
else
# If Plex is transcoding, stop the trex-miner container if it is running.
if [[ `docker ps | grep $TREX` != "" ]]; then
echo "Plex running, stopping Trex."
docker stop $TREX
fi
fi
sleep 1
done