let start ~configuration =
Log.(s "Start-Server: Checking status" @ verbose);
begin
status ~configuration
>>= function
| `Running -> fail (`Start_server_error "Server seems to be already running")
| `Wrong_response c ->
fail (`Start_server_error
(fmt "An unrecognized HTTPS Server seems to be already there; response: %s"
(Cohttp.Response.sexp_of_t c |> Sexplib.Sexp.to_string_hum)))
| `Not_responding _ ->
Log.(s "Status answers `Not_responding`" @ verbose);
return ()
end
>>= fun () ->
Log.(s "Start-Server: Loading the Engine" @ verbose);
Ketrew_engine.load (Ketrew_configuration.server_engine configuration)
>>= fun engine ->
Log.(s "Start-Server: Loading authentication config" @ verbose);
Authentication.load (Ketrew_configuration.authorized_tokens configuration)
>>= fun authentication ->
let server_state =
Server_state.create ~authentication ~state:engine configuration in
Log.(s "Start-Server: Starting the Engine loop" @ verbose);
start_engine_loop ~server_state;
Log.(s "Start-Server: Starting listening on command-pipe" @ verbose);
start_listening_on_command_pipe ~server_state
>>= fun () ->
Log.(s "Start-Server: Starting listening on connections" @ verbose);
start_listening_on_connections ~server_state