Thank you for your donation!


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


Problem: Spotify connect keeps dropping
#26
(12-06-2018, 02:18 PM)Tim Curtis Wrote: The librespot project is actively being worked on so eventually the bug will be fixed which is why at the moment I'm not planning to invest time to code some sort of watchdog for it into moOde.

But if someone wants to give it a try then here is some useful information.

librespot is started by moOde in /var/www/inc/playerlib.php function startSpotify(). This function reads the values in the sql table cfg_spotify and then composes the command string. A "restart" script would need to be written in PHP and include playerlib.php. Then it just calls startSpotify().

The watchdog part would be added to the existing /var/www/command/watchdog.sh script. The code block would be similar to the MPD restart block.

Thanks for this! Combining the information in here ^^ and in some other thread, I've got myself a nice watchdog/restart for the librespot issues. You can use this procedure:

1. login as user pi

2. Create a file in /home/pi called restartspotify.php

Code:
sudo nano /home/pi/restartspotify.php

with this contents:

PHP Code:
#!/usr/bin/php
<?php


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

playerSession('open''' ,'');
session_write_close();

sysCmd('killall librespot');
sysCmd('/var/www/vol.sh -restore'); // r44d
// reset to inactive
playerSession('write''spotactive''0');
$GLOBALS['spotactive'] = '0';
sendEngCmd('spotactive0');
startSpotify();

?>


3. set the script as executable:

Code:
sudo chmod +x /home/pi/restartspotify.php

4. replace the already existing file /var/www/command/watchdog.sh

Code:
sudo nano /var/www/command/watchdog.sh

with this version (which adds a check for the existence of the librespot process and calls the script above to start it again)

PHP 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/>.
#
# 2018-01-26 TC moOde 4.0
#

FPMLIMIT=40
FPMCNT
=$(pgrep --"php-fpm: pool www")
MPDACTIVE=$(pgrep --x mpd)
LIBRESPOTACTIVE=$(pgrep --x librespot)

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

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

        
#LIBRESPOT

        if [[ $LIBRESPOTACTIVE ]]; then
                TIMESTAMP
=$(date +'%Y%m%d %H%M%S')
                LOGMSG=" watchdog: LIBRESPOT restart (check syslog for MPD errors)"
                echo $TIMESTAMP$LOGMSG >> /var/log/moode.log
                
/home/pi/restartspotify.php
        fi


        sleep 6
        FPMCNT
=$(pgrep --"php-fpm: pool www")
        MPDACTIVE=$(pgrep --x mpd)
        LIBRESPOTACTIVE=$(pgrep --x librespot)

done > /dev/null 2>&
 

(for reference, compared with the original I have added these lines: 28, 47-54, 60)
 

5. Reboot and that's it!

(note: so far I only tested it by killall librespot and the process was respawned few seconds after - the watchdog checks every 6 seconds).
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 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: