Skip to content

Commit

Permalink
Some cleanup of multisync, don't force restarts as often.
Browse files Browse the repository at this point in the history
  • Loading branch information
dkulp committed Jul 1, 2021
1 parent aee003c commit 9e89ae3
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 63 deletions.
7 changes: 5 additions & 2 deletions src/MultiSync.cpp
Expand Up @@ -2095,7 +2095,7 @@ void MultiSync::ProcessControlPacket(bool pingOnly)
}
break;
case CTRL_PKT_PING:
ProcessPingPacket(pkt, len, stats);
ProcessPingPacket(pkt, len, sourceIP, stats);
break;
case CTRL_PKT_PLUGIN:
ProcessPluginPacket(pkt, len, stats);
Expand Down Expand Up @@ -2347,7 +2347,7 @@ void MultiSync::ProcessCommandPacket(ControlPkt *pkt, int len, MultiSyncStats *s
/*
*
*/
void MultiSync::ProcessPingPacket(ControlPkt *pkt, int len, MultiSyncStats *stats)
void MultiSync::ProcessPingPacket(ControlPkt *pkt, int len, const std::string &srcIp, MultiSyncStats *stats)
{
LogDebug(VB_SYNC, "ProcessPingPacket()\n");

Expand Down Expand Up @@ -2446,6 +2446,9 @@ void MultiSync::ProcessPingPacket(ControlPkt *pkt, int len, MultiSyncStats *stat
rand = std::rand() % 1000;
std::this_thread::sleep_for(std::chrono::microseconds(rand));
multiSync->PingSingleRemote(addrStr, 0);
if (address != srcIp) {
multiSync->PingSingleRemote(srcIp.c_str(), 0);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/MultiSync.h
Expand Up @@ -311,7 +311,7 @@ class MultiSync {

void ProcessSyncPacket(ControlPkt *pkt, int len, MultiSyncStats *stats);
void ProcessCommandPacket(ControlPkt *pkt, int len, MultiSyncStats *stats);
void ProcessPingPacket(ControlPkt *pkt, int len, MultiSyncStats *stats);
void ProcessPingPacket(ControlPkt *pkt, int len, const std::string &src, MultiSyncStats *stats);
void ProcessPluginPacket(ControlPkt *pkt, int len, MultiSyncStats *stats);
void ProcessFPPCommandPacket(ControlPkt *pkt, int len, MultiSyncStats *stats);

Expand Down
113 changes: 61 additions & 52 deletions www/multisync.php
Expand Up @@ -76,7 +76,7 @@ function updateMultiSyncRemotes(verbose = false) {
}

//Mark FPPD as needing restart
$.put('api/settings/restart', '2');
SetRestartFlag(2);
settings['restartFlag'] = 2;
//Get the resart banner showing
CheckRestartRebootFlags();
Expand Down Expand Up @@ -201,16 +201,16 @@ function getFPPSystemStatus(ipAddresses, refreshing = false) {
} else {
ips = "&ip[]=" + ipAddresses;
}
$.get("api/system/status?ip=" + ips + '&advancedView=true')
.done(function(alldata) {
jQuery.each(alldata, function(ip, data) {
$.get("api/system/status?ip=" + ips + '&advancedView=true')
.done(function(alldata) {
jQuery.each(alldata, function(ip, data) {
var status = 'Idle';
var statusInfo = "";
var elapsed = "";
var files = "";
if (data == null || data == "" || data == "null") {
return;
}
if (data == null || data == "" || data == "null") {
return;
}

if (data.status_name == 'playing') {
status = 'Playing';
Expand Down Expand Up @@ -241,11 +241,7 @@ function getFPPSystemStatus(ipAddresses, refreshing = false) {
status = 'Testing';
} else if (data.status_name == 'unreachable') {
unavailables[ip]++;
if (unavailables[ip] > 3) {
status = '<font color="red">Unreachable</font>';
} else {
status = "";
}
status = "unreachable";
} else if (data.status_name == 'password') {
status = '<font color="red">Protected</font>';
} else if (data.status_name == 'unknown') {
Expand Down Expand Up @@ -288,33 +284,33 @@ function getFPPSystemStatus(ipAddresses, refreshing = false) {
(!refreshing)) {
// Don't replace an existing status via a different IP
return;
}

if (status != "") {
$('#' + rowID + '_status').html(status);
}

if (status == 'unreachable')
return;

$('#' + rowID + '_mode').html(modeToString(data.mode));


if (data.hasOwnProperty('wifi')) {
var wifi_html = [];
data.wifi.forEach(function(w) {
wifi_html.push('<span title="');
wifi_html.push(w.level);
wifi_html.push('dBm" class="wifi-icon wifi-');
wifi_html.push(w.desc);
wifi_html.push('"></span>');
});
if (wifi_html.length > 0) {
$('#' + rowID + "_ip").find(".wifi-icon").remove();
//$(wifi_html.join('')).appendTo($('#' + rowID + "_ip > a[ip='" + ip + "']"));
$(wifi_html.join('')).appendTo('td[ip="' + ip + '"]');
}
}
}
if (status == 'unreachable') {
if (unavailables[ip] < 4) {
return;
}
$('#' + rowID + '_mode').html("<font color='red'>Unreachable</font>");
} else if (status != "") {
$('#' + rowID + '_status').html(status);
$('#' + rowID + '_mode').html(modeToString(data.mode));
} else {
$('#' + rowID + '_mode').html(modeToString(data.mode));
}
if (data.hasOwnProperty('wifi')) {
var wifi_html = [];
data.wifi.forEach(function(w) {
wifi_html.push('<span title="');
wifi_html.push(w.level);
wifi_html.push('dBm" class="wifi-icon wifi-');
wifi_html.push(w.desc);
wifi_html.push('"></span>');
});
if (wifi_html.length > 0) {
$('#' + rowID + "_ip").find(".wifi-icon").remove();
//$(wifi_html.join('')).appendTo($('#' + rowID + "_ip > a[ip='" + ip + "']"));
$(wifi_html.join('')).appendTo('td[ip="' + ip + '"]');
}
}

if ($('#' + rowID).attr('ip') != ip)
$('#' + rowID).attr('ip', ip);
Expand Down Expand Up @@ -621,23 +617,36 @@ function parseFPPSystems(data) {
}
getFPPSystemStatus(fppIpAddresses, false);

var extras = "";


var extraRemotes = [];
var origExtra = "";
if (typeof settings['MultiSyncExtraRemotes'] === 'string') {
origExtra = settings['MultiSyncExtraRemotes'];
extraRemotes = origExtra.split(',');
}
for (var x in remotes) {
if (extras != "") {
extras += ",";
if (!extraRemotes.includes(x)) {
extraRemotes.push(x);
}
extras += x;
}
<?php
if ($uiLevel >= 1) {
?>
var inp = document.getElementById("MultiSyncExtraRemotes");
if (extras != '' && inp && inp.value != extras) {
$('#MultiSyncExtraRemotes').val(extras).trigger('change');
extraRemotes.sort();
var extras = extraRemotes.join(',');
settings['MultiSyncExtraRemotes'] = extras;

if (extras != '' && origExtra != extras) {
<?php
if ($uiLevel >= 1) {
?>
var inp = document.getElementById("MultiSyncExtraRemotes");
if (inp) {
$('#MultiSyncExtraRemotes').val(extras);
}
<?
}
?>
SetSetting("MultiSyncExtraRemotes", extras, 0, 0);
}
<?
}
?>

$('#fppSystems').trigger('update', true);
}
Expand Down
7 changes: 5 additions & 2 deletions www/rebootRemoteFPP.php
Expand Up @@ -21,10 +21,11 @@
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 200);
$request_content = curl_exec($curl);
$rc = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);

// If 5.0+ method failed, try old method.
if (! $request_content || curl_getinfo($curl, CURLINFO_RESPONSE_CODE) != 200 ) {
if (! $request_content || $rc != 200 ) {
$curl = curl_init('http://' . $ip . '/fppxml.php?command=rebootPi');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
Expand Down Expand Up @@ -55,7 +56,9 @@
$request_content = curl_exec($curl);
curl_close($curl);

sleep(1);
if ($request_content === FALSE) {
sleep(1);
}
}

if ($request_content === FALSE) {
Expand Down
24 changes: 20 additions & 4 deletions www/restartRemoteFPPD.php
Expand Up @@ -27,14 +27,28 @@

echo "Restarting FPPD @ ".htmlspecialchars($ip)."\n";

$curl = curl_init('http://' . $ip . '/fppxml.php?command=restartFPPD' . $postfix);
curl_setopt($curl, CURLOPT_FAILONERROR, true);
// FPP 5.0+
$curl = curl_init('http://' . $ip . '/api/system/fppd/restart?quick=true');
curl_setopt($curl, CURLOPT_FAILONERROR, false); // don't fail hard if not 5.0+
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 300);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 200);
$request_content = curl_exec($curl);
$rc = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);

// If 5.0+ method failed, try old method.
if (! $request_content || $rc != 200 ) {
$curl = curl_init('http://' . $ip . '/fppxml.php?command=restartFPPD');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 200);
$request_content = curl_exec($curl);
$rc = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);
}

echo "Waiting for fppd to come back up:\n";

$request_content = FALSE;
Expand All @@ -51,7 +65,9 @@
$request_content = curl_exec($curl);
curl_close($curl);

sleep(1);
if ($request_content === FALSE) {
sleep(1);
}
}

if ($request_content === FALSE) {
Expand Down
19 changes: 17 additions & 2 deletions www/shutdownRemoteFPP.php
Expand Up @@ -20,14 +20,29 @@

echo "Shutting down FPP system @ $ip\n";

$curl = curl_init('http://' . $ip . '/fppxml.php?command=shutdownPi');
curl_setopt($curl, CURLOPT_FAILONERROR, true);

// FPP 5.0+
$curl = curl_init('http://' . $ip . '/api/system/shutdown');
curl_setopt($curl, CURLOPT_FAILONERROR, false); // don't fail hard if not 5.0+
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 200);
$request_content = curl_exec($curl);
$rc = curl_getinfo($curl, CURLINFO_RESPONSE_CODE);
curl_close($curl);

// If 5.0+ method failed, try old method.
if (! $request_content || $rc != 200 ) {
$curl = curl_init('http://' . $ip . '/fppxml.php?command=shutdownPi');
curl_setopt($curl, CURLOPT_FAILONERROR, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT_MS, 200);
$request_content = curl_exec($curl);
curl_close($curl);
}


echo "\nSystem Shutdown";

?>

0 comments on commit 9e89ae3

Please sign in to comment.