diff options
author | iilyak <iilyak@ca.ibm.com> | 2018-08-16 09:56:18 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-16 09:56:18 -0700 |
commit | b847adb8450d2095e5a6e52139cd51694612ea03 (patch) | |
tree | 039ca2824fe8696e1cd07b0f98e442ae0293d6d7 | |
parent | 28ba48da5877a5d471253c1b587af7e3b3121fd9 (diff) | |
parent | 9be121334f2eb8d8f4c796eb5e355689d3758129 (diff) | |
download | couchdb-b847adb8450d2095e5a6e52139cd51694612ea03.tar.gz |
Merge pull request #1543 from cloudant/implement-node-restart
Add `POST /_node/$node/_restart` endpoint
-rw-r--r-- | rel/overlay/etc/default.ini | 1 | ||||
-rw-r--r-- | src/chttpd/src/chttpd_misc.erl | 8 | ||||
-rw-r--r-- | src/couch/src/couch_app.erl | 11 | ||||
-rw-r--r-- | src/couch/src/couch_httpd_misc_handlers.erl | 23 | ||||
-rwxr-xr-x | test/javascript/run | 6 | ||||
-rw-r--r-- | test/javascript/test_setup.js | 11 |
6 files changed, 29 insertions, 31 deletions
diff --git a/rel/overlay/etc/default.ini b/rel/overlay/etc/default.ini index 45025e780..dc2e51cc0 100644 --- a/rel/overlay/etc/default.ini +++ b/rel/overlay/etc/default.ini @@ -313,7 +313,6 @@ _active_tasks = {couch_httpd_misc_handlers, handle_task_status_req} _config = {couch_httpd_misc_handlers, handle_config_req} _replicate = {couch_replicator_httpd, handle_req} _uuids = {couch_httpd_misc_handlers, handle_uuids_req} -_restart = {couch_httpd_misc_handlers, handle_restart_req} _stats = {couch_stats_httpd, handle_stats_req} _session = {couch_httpd_auth, handle_session_req} _plugins = {couch_plugins_httpd, handle_req} diff --git a/src/chttpd/src/chttpd_misc.erl b/src/chttpd/src/chttpd_misc.erl index 596e0142b..c72ef7cd4 100644 --- a/src/chttpd/src/chttpd_misc.erl +++ b/src/chttpd/src/chttpd_misc.erl @@ -344,6 +344,12 @@ handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_system">>]}=Req) - send_json(Req, EJSON); handle_node_req(#httpd{path_parts=[_, _Node, <<"_system">>]}=Req) -> send_method_not_allowed(Req, "GET"); +% POST /_node/$node/_restart +handle_node_req(#httpd{method='POST', path_parts=[_, Node, <<"_restart">>]}=Req) -> + call_node(Node, init, restart, []), + send_json(Req, 200, {[{ok, true}]}); +handle_node_req(#httpd{path_parts=[_, _Node, <<"_restart">>]}=Req) -> + send_method_not_allowed(Req, "POST"); handle_node_req(#httpd{path_parts=[_]}=Req) -> chttpd:send_error(Req, {bad_request, <<"Incomplete path to _node request">>}); handle_node_req(#httpd{path_parts=[_, _Node]}=Req) -> @@ -395,7 +401,7 @@ get_stats() -> MessageQueues0 = [{couch_file, {CF}}, {couch_db_updater, {CDU}}], MessageQueues = MessageQueues0 ++ message_queues(registered()), [ - {uptime, element(1,statistics(wall_clock)) div 1000}, + {uptime, couch_app:uptime() div 1000}, {memory, {Memory}}, {run_queue, statistics(run_queue)}, {ets_table_count, length(ets:all())}, diff --git a/src/couch/src/couch_app.erl b/src/couch/src/couch_app.erl index d284c2bfd..8acc71d51 100644 --- a/src/couch/src/couch_app.erl +++ b/src/couch/src/couch_app.erl @@ -16,11 +16,17 @@ -include_lib("couch/include/couch_db.hrl"). --export([start/2, stop/1]). +-export([ + start/2, + stop/1, + uptime/0 +]). start(_Type, _) -> case couch_sup:start_link() of {ok, _} = Resp -> + {Time, _} = statistics(wall_clock), + application:set_env(couch, start_time, Time), Resp; Else -> throw(Else) @@ -29,3 +35,6 @@ start(_Type, _) -> stop(_) -> ok. +uptime() -> + {Time, _} = statistics(wall_clock), + Time - application:get_env(couch, start_time, Time). diff --git a/src/couch/src/couch_httpd_misc_handlers.erl b/src/couch/src/couch_httpd_misc_handlers.erl index 0c70bcb8a..3d25f5853 100644 --- a/src/couch/src/couch_httpd_misc_handlers.erl +++ b/src/couch/src/couch_httpd_misc_handlers.erl @@ -13,7 +13,7 @@ -module(couch_httpd_misc_handlers). -export([handle_welcome_req/2,handle_favicon_req/2,handle_utils_dir_req/2, - handle_all_dbs_req/1,handle_restart_req/1, + handle_all_dbs_req/1, handle_uuids_req/1,handle_config_req/1, handle_task_status_req/1, handle_file_req/2]). @@ -81,27 +81,6 @@ handle_task_status_req(Req) -> send_method_not_allowed(Req, "GET,HEAD"). -handle_restart_req(#httpd{method='GET', path_parts=[_, <<"token">>]}=Req) -> - ok = couch_httpd:verify_is_server_admin(Req), - Token = case application:get_env(couch, instance_token) of - {ok, Tok} -> - Tok; - _ -> - Tok = erlang:phash2(make_ref()), - application:set_env(couch, instance_token, Tok), - Tok - end, - send_json(Req, 200, {[{token, Token}]}); -handle_restart_req(#httpd{method='POST'}=Req) -> - couch_httpd:validate_ctype(Req, "application/json"), - ok = couch_httpd:verify_is_server_admin(Req), - Result = send_json(Req, 202, {[{ok, true}]}), - couch:restart(), - Result; -handle_restart_req(Req) -> - send_method_not_allowed(Req, "POST"). - - handle_uuids_req(#httpd{method='GET'}=Req) -> Max = list_to_integer(config:get("uuids","max_count","1000")), Count = try list_to_integer(couch_httpd:qs_value(Req, "count", "1")) of diff --git a/test/javascript/run b/test/javascript/run index ca69e1ff2..a3b3ab704 100755 --- a/test/javascript/run +++ b/test/javascript/run @@ -85,11 +85,7 @@ def run_couchjs(test, fmt): if not line: break line = line.decode() - if line.strip() == "restart": - sys.stdout.write("reboot_nodes(ctx)" + os.linesep) - sys.stdout.flush() - else: - sys.stderr.write(line) + sys.stderr.write(line) p.wait() fmt(p.returncode == 0) return p.returncode diff --git a/test/javascript/test_setup.js b/test/javascript/test_setup.js index a6109b4d7..9e49cf15c 100644 --- a/test/javascript/test_setup.js +++ b/test/javascript/test_setup.js @@ -76,6 +76,14 @@ function getUptime() { return stats['uptime']; } +function restartNodeRequest(node) { + var url = "/_node/" + node +"/_restart" + var result = JSON.parse(CouchDB.request("POST", url).responseText); + if (result.ok != true) { + throw(Error('FAILED to restart: ' + node)); + } +} + function restartServer() { var olduptime = getUptime(); if (olduptime < 15) { @@ -83,7 +91,8 @@ function restartServer() { sleep(15000); olduptime = getUptime(); } - print('restart'); + + restartNodeRequest('node1@127.0.0.1'); /* Wait up to 15s for server to restart */ var start = new Date().getTime(); |