Previous thread, now closed:
On my network I have two different ISPs and depending on whatever, one is the route taken, and one is not. When that switches over, users attempting to access my PMS get yellow triangles because my “server is offline.” “Eventually” the new external IP is populated so Plex knows how to get to my PMS on the “new” IP…
The script below is my first cut at resolving this, having been unable to find anyone doing it before. I sure wish Plex would allow setting a register handshake timeout of something short like 120 seconds, but that’s not my call.
Ehud
Tucson, Arizona, US
cat /usr/local/bin/pms_extip_chg.sh
#!/bin/sh
#!
#! pms_extip_chg.sh 20230904 Watch for changes in external IP and restart PMS
#!
#! We store the old IPv4 address in $OLDIP. We get the current IPv4 address into
#! $CUREXTIP. If it’s different than the previous one (in $PREVIP) we update the
#! file AND retart the Plex Media Server. Log everything.
#!
#! Run every three minutes via crontab entry for user htpc:
#! */3 * * * * /usr/local/bin/pms_extip_chg.sh
EXIT_FAILURE=1
EXIT_SUCCESS=0
##CUREXTIP=“lwp-request -o text checkip.dyndns.org | awk '{ print $NF }'”
CUREXTIP=dig @resolver4.opendns.com myip.opendns.com +short
OLDIP=“/tmp/.oldpubip”
RESTARTCMD=“systemctl restart plexmediaserver”
if [ -f “$OLDIP” ]; then
PREVIP=tail -1 $OLDIP | awk -F\# '{print $1}'
else
echo “$CUREXTIP # date +%F-%T” > $OLDIP
PREVIP=$CUREXTIP
fi
echo “$CUREXTIP ## date +%F-%T” >> $OLDIP
logger “$0 starting with external IP $CUREXTIP”
if [ “$CUREXTIP” != “$PREVIP” ]; then
logger “$0 IP $PREVIP is now $GETEXIP. Restarting Plex Media Server.”
$RESTARTCMD
fi
exit $EXIT_SUCCESS