Allow a server to be rebooted when a reboot is required

This commit is contained in:
Michael Kroes 2016-02-25 21:56:27 +01:00
parent d880f088be
commit 8ea2f5a766
2 changed files with 49 additions and 3 deletions

View File

@ -391,7 +391,6 @@ def ssl_provision_certs():
def web_get_domains():
from web_update import get_web_domains_info
return json_response(get_web_domains_info(env))
@app.route('/web/update', methods=['POST'])
@authorized_personnel_only
def web_update():
@ -456,6 +455,23 @@ def do_updates():
"DEBIAN_FRONTEND": "noninteractive"
})
@app.route('/system/reboot', methods=["GET"])
@authorized_personnel_only
def needs_reboot():
if os.path.isfile("/var/run/reboot-required"):
return json_response(True)
else:
return json_response(False)
@app.route('/system/reboot', methods=["POST"])
@authorized_personnel_only
def do_reboot():
if os.path.isfile("/var/run/reboot-required"):
return utils.shell("check_output", ["/sbin/shutdown", "-r", "now"], capture_stderr=True)
else:
return "No reboot is required"
@app.route('/system/backup/status')
@authorized_personnel_only
def backup_status():

View File

@ -1,5 +1,9 @@
<h2>System Status Checks</h2>
<div id="system-reboot-required" style="display: none">
<button type="button" class="btn btn-danger" onclick="confirm_reboot(); return false;">Reboot required</button>
</div>
<style>
#system-checks .heading td {
font-weight: bold;
@ -34,7 +38,10 @@
font-family: monospace;
white-space: pre-wrap;
}
#system-reboot-required {
max-width: 20em;
margin-bottom: 1em;
}
#system-privacy-setting {
float: right;
max-width: 20em;
@ -47,7 +54,6 @@
<p style="line-height: 125%"><small>(When enabled, status checks phone-home to check for a new release of Mail-in-a-Box.)</small></p>
</div>
<table id="system-checks" class="table" style="max-width: 60em">
<thead>
</thead>
@ -70,6 +76,14 @@ function show_system_status() {
$('#system-privacy-setting p').toggle(r);
});
api(
"/system/reboot",
"GET",
{ },
function(r) {
$('#system-reboot-required').toggle(r);
});
api(
"/system/status",
"POST",
@ -122,4 +136,20 @@ function enable_privacy(status) {
});
return false; // disable link
}
function confirm_reboot() {
show_modal_confirm(
"Reboot server",
$("<p>This will reboot your server, until the server is fully restarted your users will not be able to send and receive email. The reboot can't be cancelled</p>"),
"Reboot now",
function() {
api(
"/system/reboot",
"POST",
{ },
function(r) {
show_modal_error("Reboot", "Please refresh the page after a minute or so." + r);
});
});
}
</script>