mirror of
https://github.com/jupyterhub/jupyterhub.git
synced 2025-10-11 12:03:00 +00:00
add Shutdown Hub button to Admin page
with dialog and checkboxes for cleaning up servers and/or proxy
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
# Copyright (c) Jupyter Development Team.
|
||||
# Distributed under the terms of the Modified BSD License.
|
||||
|
||||
import json
|
||||
|
||||
from tornado import web
|
||||
from tornado.ioloop import IOLoop
|
||||
|
||||
@@ -15,31 +17,32 @@ class ShutdownAPIHandler(APIHandler):
|
||||
def post(self):
|
||||
"""POST /api/shutdown triggers a clean shutdown
|
||||
|
||||
URL parameters:
|
||||
POST (JSON) parameters:
|
||||
|
||||
- servers: specify whether single-user servers should be terminated
|
||||
- proxy: specify whether the proxy should be terminated
|
||||
"""
|
||||
from ..app import JupyterHub
|
||||
app = JupyterHub.instance()
|
||||
proxy = self.get_argument('proxy', '').lower()
|
||||
if proxy == 'false':
|
||||
app.cleanup_proxy = False
|
||||
elif proxy == 'true':
|
||||
app.cleanup_proxy = True
|
||||
elif proxy:
|
||||
|
||||
data = self.get_json_body()
|
||||
if data:
|
||||
if 'proxy' in data:
|
||||
proxy = data['proxy']
|
||||
if proxy not in {True, False}:
|
||||
raise web.HTTPError(400, "proxy must be true or false, got %r" % proxy)
|
||||
servers = self.get_argument('servers', '').lower()
|
||||
if servers == 'false':
|
||||
app.cleanup_servers = False
|
||||
elif servers == 'true':
|
||||
app.cleanup_servers = True
|
||||
elif servers:
|
||||
app.cleanup_proxy = proxy
|
||||
if 'servers' in data:
|
||||
servers = data['servers']
|
||||
if servers not in {True, False}:
|
||||
raise web.HTTPError(400, "servers must be true or false, got %r" % servers)
|
||||
app.cleanup_servers = servers
|
||||
|
||||
# finish the request
|
||||
self.set_status(202)
|
||||
self.finish()
|
||||
self.finish(json.dumps({
|
||||
"message": "Shutting down Hub"
|
||||
}))
|
||||
|
||||
# stop the eventloop, which will trigger cleanup
|
||||
loop = IOLoop.current()
|
||||
|
@@ -170,4 +170,20 @@ require(["jquery", "bootstrap", "moment", "jhapi", "utils"], function ($, bs, mo
|
||||
});
|
||||
});
|
||||
|
||||
$("#shutdown-hub").click(function () {
|
||||
var dialog = $("#shutdown-hub-dialog");
|
||||
dialog.find("input[type=checkbox]").prop("checked", true);
|
||||
dialog.modal();
|
||||
});
|
||||
|
||||
$("#shutdown-hub-dialog").find(".shutdown-button").click(function () {
|
||||
var dialog = $("#shutdown-hub-dialog");
|
||||
var servers = dialog.find(".shutdown-servers-checkbox").prop("checked");
|
||||
var proxy = dialog.find(".shutdown-proxy-checkbox").prop("checked");
|
||||
api.shutdown_hub({
|
||||
proxy: proxy,
|
||||
servers: servers,
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
@@ -10,7 +10,7 @@ define(['jquery', 'utils'], function ($, utils) {
|
||||
|
||||
var default_options = {
|
||||
type: 'GET',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
contentType: "application/json",
|
||||
cache: false,
|
||||
dataType : "json",
|
||||
processData: false,
|
||||
@@ -122,5 +122,14 @@ define(['jquery', 'utils'], function ($, utils) {
|
||||
);
|
||||
};
|
||||
|
||||
JHAPI.prototype.shutdown_hub = function (data, options) {
|
||||
options = options || {};
|
||||
options = update(options, {type: 'POST'});
|
||||
if (data) {
|
||||
options.data = JSON.stringify(data);
|
||||
}
|
||||
this.api_request('shutdown', options);
|
||||
};
|
||||
|
||||
return JHAPI;
|
||||
});
|
@@ -32,7 +32,8 @@
|
||||
<tbody>
|
||||
<tr class="user-row add-user-row">
|
||||
<td colspan="5">
|
||||
<a id="add-user" class="col-xs-12 btn btn-default">Add User</a>
|
||||
<a id="add-user" class="col-xs-5 btn btn-default">Add User</a>
|
||||
<a id="shutdown-hub" class="col-xs-4 col-xs-offset-3 btn btn-danger">Shutdown Hub</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% for u in users %}
|
||||
@@ -66,6 +67,21 @@
|
||||
This operation cannot be undone.
|
||||
{% endcall %}
|
||||
|
||||
{% call modal('Shutdown Hub', btn_label='Shutdown', btn_class='btn-danger shutdown-button') %}
|
||||
Are you sure you want to shutdown the Hub?
|
||||
You can chose to leave the proxy and/or single-user servers running by unchecking the boxes below:
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" class="shutdown-proxy-checkbox">Shutdown proxy
|
||||
</label>
|
||||
</div>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" class="shutdown-servers-checkbox">Shutdown single-user-servers
|
||||
</label>
|
||||
</div>
|
||||
{% endcall %}
|
||||
|
||||
{% macro user_modal(name) %}
|
||||
{% call modal(name, btn_class='btn-primary save-button') %}
|
||||
<div class="form-group">
|
||||
|
Reference in New Issue
Block a user