Rewrite restartServer() for robustness

This uses an instance wide token set in the application environment to
detect when the server has restarted.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch/commit/53c64388
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch/tree/53c64388
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch/diff/53c64388

Branch: refs/heads/import
Commit: 53c64388e3f0f60cbae0bba4a7b089f6c46e9cae
Parents: 0a0f7d2
Author: Paul J. Davis <[email protected]>
Authored: Wed Mar 13 14:08:43 2013 -0500
Committer: Paul J. Davis <[email protected]>
Committed: Fri Jan 17 16:44:32 2014 -0800

----------------------------------------------------------------------
 src/couch_httpd_misc_handlers.erl | 11 +++++++++++
 1 file changed, 11 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/53c64388/src/couch_httpd_misc_handlers.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_misc_handlers.erl 
b/src/couch_httpd_misc_handlers.erl
index d57ceeb..3b2bbeb 100644
--- a/src/couch_httpd_misc_handlers.erl
+++ b/src/couch_httpd_misc_handlers.erl
@@ -94,6 +94,17 @@ 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),

Reply via email to