Detect reboot if uptime decreases

This commit is contained in:
Taylor Helsper 2022-06-21 00:23:48 -05:00
parent 7836eab70f
commit 53af9aafd8
2 changed files with 30 additions and 3 deletions

View File

@ -25,6 +25,15 @@ mynode_api = Blueprint('mynode_api',__name__)
### Page functions
@mynode_api.route("/api/ping")
def api_ping():
check_logged_in()
data = {}
data["status"] = get_mynode_status()
data["uptime_seconds"] = get_system_uptime_in_seconds()
return jsonify(data)
@mynode_api.route("/api/get_bitcoin_info")
def api_get_bitcoin_info():
check_logged_in()

View File

@ -3,27 +3,45 @@
<title>{{ title }}</title>
{% include 'includes/head.html' %}
<meta http-equiv="refresh" content="43200; URL=/" /> <!-- Backup: reload home page after 12 hours if JS didn't detect reboot -->
<!-- Backup: reload home page after 12 hours if JS didn't detect reboot -->
<meta http-equiv="refresh" content="43200; URL=/" />
<script>
$(document).ready(function() {
hasShutdown = 0
uptime = null
function redirectHome() {
window.location.replace("/");
}
function checkStatus() {
var jqxhr = $.get("/settings/ping", function() {
var jqxhr = $.getJSON("/api/ping", function(data) {
if (hasShutdown) {
// Redirect to home
setTimeout(redirectHome, 2500)
} else {
if ("uptime_seconds" in data) {
if (uptime == null || data["uptime_seconds"] > uptime) {
uptime = data["uptime_seconds"]
} else if (data["uptime_seconds"] < uptime) {
setTimeout(redirectHome, 2500)
}
}
}
})
.done(function() {
.done(function(data) {
if (hasShutdown) {
// Redirect to home
setTimeout(redirectHome, 2500)
} else {
if ("uptime_seconds" in data) {
if (uptime == null || data["uptime_seconds"] > uptime) {
uptime = data["uptime_seconds"]
} else if (data["uptime_seconds"] < uptime) {
setTimeout(redirectHome, 2500)
}
}
}
})
.fail(function() {