Search code examples
bashupnp

Check status of GMediaRenderer


I use GMediaRenderer to send audio via UPNP from a Raspberry Pi. Occasionally, for reasons unknown, I have to SSH into my Pi and send the command sudo service gmediarenderer restart to get it to work properly. I'd like to add a command to crontab or similar that periodically checks whether the service is running properly. I already have a crontab entry that checks whether the service is running, and starts if it isn't. The trouble I'm having is that sometimes, even though the service is running, it doesn't appear to be communicating with UPNP control points. Executing the restart command brings it back, so I assume it is simply the case that the service has crashed but not closed down.

Does anyone know how to programmatically check (preferably using a bash script) whether the GMediaRenderer service is up and running?


Solution

  • I have found a solution to this. The command gssdp-discover returns a list of active renderers. I setup a sudo crontab job to run a bash script every minute that checks whether or not a particular renderer is running, and to restart gmediarenderer if it isn't found.

    The following command will list your active renderers:

    gssdp-discover -i wlan0  --timeout=3
    

    Change wlan0 above depending on your specific network connection. In my case, the renderer that I'm interested in is listed as urn:av-openhome-org:service:Info:1 (run the command with and without the renderer active, and look for the one that only appears when running). So, my bash script contains the following:

    gssdp-discover -i wlan0  --timeout=3 --target=urn:av-openhome-org:service:Info:1 | grep available &> /dev/null
    if [ $? == 0 ]; then
        echo "OpenHome renderer is already running"
    else
       echo "restarting gmediarenderer"
       /etc/init.d/gmediarenderer stop
       /etc/init.d/gmediarenderer start
    fi