mirror of
https://github.com/mynodebtc/mynode.git
synced 2024-12-28 15:31:37 +00:00
Detect reboot if uptime decreases
This commit is contained in:
parent
7836eab70f
commit
53af9aafd8
|
@ -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()
|
||||
|
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue
Block a user