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.
|
# Copyright (c) Jupyter Development Team.
|
||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
|
|
||||||
|
import json
|
||||||
|
|
||||||
from tornado import web
|
from tornado import web
|
||||||
from tornado.ioloop import IOLoop
|
from tornado.ioloop import IOLoop
|
||||||
|
|
||||||
@@ -15,31 +17,32 @@ class ShutdownAPIHandler(APIHandler):
|
|||||||
def post(self):
|
def post(self):
|
||||||
"""POST /api/shutdown triggers a clean shutdown
|
"""POST /api/shutdown triggers a clean shutdown
|
||||||
|
|
||||||
URL parameters:
|
POST (JSON) parameters:
|
||||||
|
|
||||||
- servers: specify whether single-user servers should be terminated
|
- servers: specify whether single-user servers should be terminated
|
||||||
- proxy: specify whether the proxy should be terminated
|
- proxy: specify whether the proxy should be terminated
|
||||||
"""
|
"""
|
||||||
from ..app import JupyterHub
|
from ..app import JupyterHub
|
||||||
app = JupyterHub.instance()
|
app = JupyterHub.instance()
|
||||||
proxy = self.get_argument('proxy', '').lower()
|
|
||||||
if proxy == 'false':
|
data = self.get_json_body()
|
||||||
app.cleanup_proxy = False
|
if data:
|
||||||
elif proxy == 'true':
|
if 'proxy' in data:
|
||||||
app.cleanup_proxy = True
|
proxy = data['proxy']
|
||||||
elif proxy:
|
if proxy not in {True, False}:
|
||||||
raise web.HTTPError(400, "proxy must be true or false, got %r" % proxy)
|
raise web.HTTPError(400, "proxy must be true or false, got %r" % proxy)
|
||||||
servers = self.get_argument('servers', '').lower()
|
app.cleanup_proxy = proxy
|
||||||
if servers == 'false':
|
if 'servers' in data:
|
||||||
app.cleanup_servers = False
|
servers = data['servers']
|
||||||
elif servers == 'true':
|
if servers not in {True, False}:
|
||||||
app.cleanup_servers = True
|
raise web.HTTPError(400, "servers must be true or false, got %r" % servers)
|
||||||
elif servers:
|
app.cleanup_servers = servers
|
||||||
raise web.HTTPError(400, "servers must be true or false, got %r" % servers)
|
|
||||||
|
|
||||||
# finish the request
|
# finish the request
|
||||||
self.set_status(202)
|
self.set_status(202)
|
||||||
self.finish()
|
self.finish(json.dumps({
|
||||||
|
"message": "Shutting down Hub"
|
||||||
|
}))
|
||||||
|
|
||||||
# stop the eventloop, which will trigger cleanup
|
# stop the eventloop, which will trigger cleanup
|
||||||
loop = IOLoop.current()
|
loop = IOLoop.current()
|
||||||
|
@@ -169,5 +169,21 @@ 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 = {
|
var default_options = {
|
||||||
type: 'GET',
|
type: 'GET',
|
||||||
headers: {'Content-Type': 'application/json'},
|
contentType: "application/json",
|
||||||
cache: false,
|
cache: false,
|
||||||
dataType : "json",
|
dataType : "json",
|
||||||
processData: false,
|
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;
|
return JHAPI;
|
||||||
});
|
});
|
@@ -32,7 +32,8 @@
|
|||||||
<tbody>
|
<tbody>
|
||||||
<tr class="user-row add-user-row">
|
<tr class="user-row add-user-row">
|
||||||
<td colspan="5">
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for u in users %}
|
{% for u in users %}
|
||||||
@@ -66,6 +67,21 @@
|
|||||||
This operation cannot be undone.
|
This operation cannot be undone.
|
||||||
{% endcall %}
|
{% 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) %}
|
{% macro user_modal(name) %}
|
||||||
{% call modal(name, btn_class='btn-primary save-button') %}
|
{% call modal(name, btn_class='btn-primary save-button') %}
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
Reference in New Issue
Block a user