Mpd-watchdog not working good enough

I installed v0.7.0 RC6 on a new Raspberry Pi 3 B+. It is working great except for a bug in the watchdog. If I deconnect the WAN cable on my router to test the watchdog, I get the following error after a while:

2019-01-07 11:53:09,897 - WARNING Download of ‘http://icecast.vrtcdn.be/mnm_hits-high.mp3’ failed: HTTPConnectionPool(host=‘icecast.vrtcdn.be’, port=80): Max retries exceeded with url: /mnm_hits-high.mp3 (Caused by NewConnectionError(‘<urllib3.connection.HTTPConnection object at 0x332f150>: Failed to establish a new connection: [Errno 101] Network is unreachable’,))

I made a quick and dirty fix by disabling the watchdog feature and replacing it with the following script and a line in /etc/rc.local:

/usr/local/bin/network-monitor.sh:

#!/bin/bash

##################################################################
# Settings
# Which address do you want to ping to see if the internet connection is alive?
pingip='8.8.8.8'
MPDHOST=localhost
MPDPORT=6600
INTERVAL=15
##################################################################

mpc_status() {
    $MPC status 2>/dev/null | grep -B1 '^\[playing\]' | tr '\n' ' '
}

MPC="mpc -h $MPDHOST -p $MPDPORT"

prev_status=$(mpc_status)

while sleep $INTERVAL; do
    status=$(mpc_status)

    if [ -n "$status" ]; then
        if [ "$prev_status" = "$status" ]; then
            echo "Performing Network check"
            /bin/ping -c 1 $pingip > /dev/null 2> /dev/null
            if [ $? -ge 1 ] ; then
                echo "Network connection down! Try again in $INTERVAL seconds"
            else
                echo "Network is Okay, restart playing"
                $MPC stop && $MPC play
            fi
        fi
    else
        echo "mpd not running/playing"
    fi

    prev_status="$status"
done

Fair enough, this is more robust for when the connection goes down. I’m not sure if mpd-watchdog was originally written for this purpose. I shall look to update our fork with your version (or create a PR if you want). Thanks.

No, it was not, so I wouldn’t call this a “bug” :wink:
But this is a useful feature, of course!

@tkem your repo is archived, would you be interesting in transferring ownership to the pimusicbox org and we’ll update (and maintain) it?

Sure, would be glad to do that; however when I tried transferring ownership, it said

pimusicbox/mpd-watchdog already exists and You don’t have the permission to create repositories on pimusicbox

I guess I could also add a note to the archived repo’s README, pointing to the pimusicbox fork as the “officially” maintained version. Or I could transfer it to you, personally, and let you sort things out :grinning:

Yep transfer to me (if it lets you). Or I can delete the pimusicbox fork and presumably give you write access.

Thanks @tkem. mpd-watchdog now lives at https://github.com/pimusicbox/mpd-watchdog

1 Like