2012-03-07 18:23:41 +00:00
|
|
|
(* Copyright 2012 Tony Garnock-Jones <tonygarnockjones@gmail.com>. *)
|
|
|
|
|
2012-05-01 21:36:38 +00:00
|
|
|
(* This file is part of Hop. *)
|
2012-03-07 18:23:41 +00:00
|
|
|
|
2012-05-01 21:36:38 +00:00
|
|
|
(* Hop is free software: you can redistribute it and/or modify it *)
|
2012-03-07 18:23:41 +00:00
|
|
|
(* under the terms of the GNU General Public License as published by the *)
|
|
|
|
(* Free Software Foundation, either version 3 of the License, or (at your *)
|
|
|
|
(* option) any later version. *)
|
|
|
|
|
2012-05-01 21:36:38 +00:00
|
|
|
(* Hop is distributed in the hope that it will be useful, but *)
|
2012-03-07 18:23:41 +00:00
|
|
|
(* WITHOUT ANY WARRANTY; without even the implied warranty of *)
|
|
|
|
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *)
|
|
|
|
(* General Public License for more details. *)
|
|
|
|
|
|
|
|
(* You should have received a copy of the GNU General Public License *)
|
2012-05-01 21:36:38 +00:00
|
|
|
(* along with Hop. If not, see <http://www.gnu.org/licenses/>. *)
|
2012-03-07 18:23:41 +00:00
|
|
|
|
2012-05-05 22:18:23 +00:00
|
|
|
open Lwt
|
|
|
|
|
2012-05-05 15:46:48 +00:00
|
|
|
let n_system_log = Node.name_of_string "system.log"
|
|
|
|
|
2012-01-08 19:48:07 +00:00
|
|
|
let hook_log () =
|
|
|
|
let old_hook = !Log.hook in
|
|
|
|
let new_hook label body =
|
2012-05-05 15:46:48 +00:00
|
|
|
ignore (Node.post n_system_log (Sexp.Str label) body (Sexp.Str ""));
|
2012-01-08 19:48:07 +00:00
|
|
|
old_hook label body
|
|
|
|
in
|
|
|
|
Log.hook := new_hook
|
|
|
|
|
2012-05-01 19:37:39 +00:00
|
|
|
let create_ready_file () =
|
|
|
|
match Config.get "ready-file" with
|
2012-05-05 22:18:23 +00:00
|
|
|
| Some ready_file_path ->
|
|
|
|
ignore (Log.info "Creating ready file" [Sexp.Str ready_file_path]);
|
|
|
|
return (close_out (open_out ready_file_path))
|
|
|
|
| None ->
|
|
|
|
return ()
|
2012-05-01 19:37:39 +00:00
|
|
|
|
2012-05-05 22:18:23 +00:00
|
|
|
lwt _ =
|
2012-03-07 18:23:41 +00:00
|
|
|
Printf.printf "%s %s, %s\n%s\n%!"
|
|
|
|
App_info.product App_info.version App_info.copyright App_info.licence_blurb;
|
2012-01-08 19:02:18 +00:00
|
|
|
Sys.set_signal Sys.sigpipe Sys.Signal_ignore;
|
2012-01-08 17:41:04 +00:00
|
|
|
Uuid.init ();
|
2012-05-01 19:37:39 +00:00
|
|
|
Config.init ();
|
2012-05-05 22:18:23 +00:00
|
|
|
lwt () = Factory.init () in
|
|
|
|
lwt () = Queuenode.init () in
|
|
|
|
lwt () = Fanoutnode.init () in
|
|
|
|
lwt () = Directnode.init () in
|
|
|
|
lwt () = Meta.init () in
|
2012-01-08 19:48:07 +00:00
|
|
|
hook_log ();
|
2012-05-06 01:11:54 +00:00
|
|
|
ignore (Amqp_relay.init ());
|
2012-05-07 10:31:59 +00:00
|
|
|
ignore (Ui_main.init ());
|
|
|
|
ignore (Ui_relay.init ());
|
2012-05-06 01:11:54 +00:00
|
|
|
ignore (Relay.init ());
|
|
|
|
lwt () = Server_control.run_until "AMQP ready" in
|
2012-05-07 10:31:59 +00:00
|
|
|
lwt () = Server_control.run_until "HTTP ready" in
|
2012-05-05 22:18:23 +00:00
|
|
|
lwt () = Server_control.run_until "Hop ready" in
|
2012-05-01 19:37:39 +00:00
|
|
|
if Server_control.is_running ()
|
2012-05-05 22:18:23 +00:00
|
|
|
then (lwt () = create_ready_file () in
|
2012-05-02 15:11:38 +00:00
|
|
|
Server_control.milestone "Server initialized";
|
2012-05-01 19:37:39 +00:00
|
|
|
Server_control.run_forever ())
|
2012-05-05 22:18:23 +00:00
|
|
|
else return ()
|