04-01-2019, 02:17 PM
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
/var/www/command/watchdog.sh
-Tim
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