Thank you for your donation!


Cloudsmith graciously provides open-source package management and distribution for our project.


Problem: Spotify connect keeps dropping
#30
Hi,

I see. That sounds like a bug in librespot. It shouldn't crash or exit due to interruption in connection, rather it should print a message and periodically try to reconnect.

I can compensate for that by implementing the watchdog code from earlier post but it needs to be modified to work correctly. See below.

/var/www/command/restart-spot.php
Code:
#!/usr/bin/php
<?php
/**
* moOde audio player (C) 2014 Tim Curtis
* http://moodeaudio.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
* 2019-MM-DD TC moOde 5.0
*
*/

set_include_path('/var/www/inc');
require_once 'playerlib.php';

// clear active state
session_id(playerSession('getsessionid'));
session_start();
playerSession('write', 'spotactive', '0');
session_write_close();

// dismiss active screen
sendEngCmd('spotactive0');
$GLOBALS['spotactive'] = '0';

// restore MPD volume and start librespot
sysCmd('/var/www/vol.sh -restore');
startSpotify();

/var/www/command/watchdog.sh
Code:
#!/bin/bash
#
# moOde audio player (C) 2014 Tim Curtis
# http://moodeaudio.org
#
# tsunamp player ui (C) 2013 Andrea Coiutti & Simone De Gregori
# http://www.tsunamp.com
#
# This Program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# This Program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# 2019-MM-DD TC moOde 5.0
#

FPMLIMIT=40
FPMCNT=$(pgrep -c -f "php-fpm: pool www")
MPDACTIVE=$(pgrep -c -x mpd)
SPOTACTIVE=$(pgrep -c -x librespot)
SQLDB=/var/local/www/db/moode-sqlite3.db

while true; do

    # PHP
    if (( FPMCNT > FPMLIMIT )); then
        TIMESTAMP=$(date +'%Y%m%d %H%M%S')
        LOGMSG=" watchdog: PHP restarted (fpm child limit > "$FPMLIMIT")"
        echo $TIMESTAMP$LOGMSG >> /var/log/moode.log
        systemctl restart php7.0-fpm
    fi

    # MPD
    if [[ $MPDACTIVE = 0 ]]; then
        TIMESTAMP=$(date +'%Y%m%d %H%M%S')
        LOGMSG=" watchdog: MPD restarted (check syslog for errors)"
        echo $TIMESTAMP$LOGMSG >> /var/log/moode.log
        systemctl start mpd
    fi

    # LIBRESPOT
    RESULT=$(sqlite3 $SQLDB "select value from cfg_system where param='spotifysvc'")
    if [[ $RESULT = "1" ]]; then
        if [[ $SPOTACTIVE = 0 ]]; then
            TIMESTAMP=$(date +'%Y%m%d %H%M%S')
            LOGMSG=" watchdog: LIBRESPOT restarted (check syslog for errors)"
            echo $TIMESTAMP$LOGMSG >> /var/log/moode.log
            /var/www/command/restart-spot.php
        fi
    fi
        
    sleep 6
    FPMCNT=$(pgrep -c -f "php-fpm: pool www")
    MPDACTIVE=$(pgrep -c -x mpd)
    SPOTACTIVE=$(pgrep -c -x librespot)

done > /dev/null 2>&1 &

-Tim
Enjoy the Music!
moodeaudio.org | Mastodon Feed | GitHub
Reply


Messages In This Thread
Spotify connect keeps dropping - by PhotonHerder - 11-24-2018, 10:12 PM
RE: Spotify connect keeps dropping - by jonners - 11-25-2018, 09:40 PM
RE: Spotify connect keeps dropping - by zaqqq - 11-25-2018, 01:13 PM
RE: Spotify connect keeps dropping - by zaqqq - 11-25-2018, 02:07 PM
RE: Spotify connect keeps dropping - by ksone - 11-28-2018, 08:42 AM
RE: Spotify connect keeps dropping - by ksone - 12-05-2018, 09:28 PM
RE: Spotify connect keeps dropping - by ksone - 12-06-2018, 07:55 AM
RE: Spotify connect keeps dropping - by ksone - 12-06-2018, 01:43 PM
RE: Spotify connect keeps dropping - by adixor - 03-22-2019, 08:11 PM
RE: Spotify connect keeps dropping - by Edward - 03-31-2019, 06:25 PM
RE: Spotify connect keeps dropping - by ksone - 04-01-2019, 12:10 PM
RE: Spotify connect keeps dropping - by Tim Curtis - 04-01-2019, 02:17 PM
RE: Spotify connect keeps dropping - by deafnut - 04-13-2019, 08:55 PM
RE: Spotify connect keeps dropping - by deafnut - 04-17-2019, 08:49 PM
RE: Spotify connect keeps dropping - by deafnut - 04-19-2019, 12:01 AM
RE: Spotify connect keeps dropping - by ksone - 04-22-2019, 08:32 AM
RE: Spotify connect keeps dropping - by oboote - 12-03-2019, 11:47 PM
RE: Spotify connect keeps dropping - by oboote - 12-06-2019, 03:04 AM

Forum Jump: