albatross_log: a read-only mode to read a log file
This commit is contained in:
parent
47fef438e0
commit
537c113a8a
|
@ -161,29 +161,36 @@ let handle mvar ring s addr =
|
||||||
|
|
||||||
let m = Vmm_core.conn_metrics "unix"
|
let m = Vmm_core.conn_metrics "unix"
|
||||||
|
|
||||||
let jump _ file influx =
|
let jump _ file read_only influx =
|
||||||
Sys.(set_signal sigpipe Signal_ignore) ;
|
Sys.(set_signal sigpipe Signal_ignore) ;
|
||||||
Lwt_main.run
|
Lwt_main.run
|
||||||
(Albatross_cli.init_influx "albatross_log" influx;
|
(read_from_file file >>= fun entries ->
|
||||||
Vmm_lwt.server_socket `Log >>= fun s ->
|
|
||||||
let ring = Vmm_ring.create `Startup () in
|
|
||||||
read_from_file file >>= fun entries ->
|
|
||||||
Logs.app (fun m -> m "read %d entries from disk" (List.length entries)) ;
|
Logs.app (fun m -> m "read %d entries from disk" (List.length entries)) ;
|
||||||
List.iter (Vmm_ring.write ring) entries ;
|
if read_only then begin
|
||||||
let mvar = Lwt_mvar.create_empty () in
|
List.iteri (fun i e ->
|
||||||
Sys.(set_signal sighup (Signal_handle (fun _ ->
|
Logs.app (fun m -> m "entry %d: %a" i Vmm_core.Log.pp e))
|
||||||
Lwt.async (fun () -> Lwt_mvar.put mvar `Hup)))) ;
|
entries;
|
||||||
Lwt.async (fun () -> write_to_file mvar file) ;
|
Lwt.return_unit
|
||||||
let start = Ptime_clock.now (), `Startup in
|
end else begin
|
||||||
Lwt_mvar.put mvar (`Entry start) >>= fun () ->
|
Albatross_cli.init_influx "albatross_log" influx;
|
||||||
Vmm_ring.write ring start ;
|
Vmm_lwt.server_socket `Log >>= fun s ->
|
||||||
let rec loop () =
|
let ring = Vmm_ring.create `Startup () in
|
||||||
Lwt_unix.accept s >>= fun (cs, addr) ->
|
List.iter (Vmm_ring.write ring) entries ;
|
||||||
m `Open;
|
let mvar = Lwt_mvar.create_empty () in
|
||||||
Lwt.async (fun () -> handle mvar ring cs addr >|= fun () -> m `Close) ;
|
Sys.(set_signal sighup (Signal_handle (fun _ ->
|
||||||
|
Lwt.async (fun () -> Lwt_mvar.put mvar `Hup)))) ;
|
||||||
|
Lwt.async (fun () -> write_to_file mvar file) ;
|
||||||
|
let start = Ptime_clock.now (), `Startup in
|
||||||
|
Lwt_mvar.put mvar (`Entry start) >>= fun () ->
|
||||||
|
Vmm_ring.write ring start ;
|
||||||
|
let rec loop () =
|
||||||
|
Lwt_unix.accept s >>= fun (cs, addr) ->
|
||||||
|
m `Open;
|
||||||
|
Lwt.async (fun () -> handle mvar ring cs addr >|= fun () -> m `Close) ;
|
||||||
|
loop ()
|
||||||
|
in
|
||||||
loop ()
|
loop ()
|
||||||
in
|
end)
|
||||||
loop ())
|
|
||||||
|
|
||||||
open Cmdliner
|
open Cmdliner
|
||||||
open Albatross_cli
|
open Albatross_cli
|
||||||
|
@ -192,8 +199,12 @@ let file =
|
||||||
let doc = "File to write the log to" in
|
let doc = "File to write the log to" in
|
||||||
Arg.(value & opt string "/var/log/albatross" & info [ "logfile" ] ~doc)
|
Arg.(value & opt string "/var/log/albatross" & info [ "logfile" ] ~doc)
|
||||||
|
|
||||||
|
let read_only =
|
||||||
|
let doc = "Only read log file and present entries" in
|
||||||
|
Arg.(value & flag & info [ "read-only" ] ~doc)
|
||||||
|
|
||||||
let cmd =
|
let cmd =
|
||||||
Term.(term_result (const jump $ setup_log $ file $ influx)),
|
Term.(const jump $ setup_log $ file $ read_only $ influx),
|
||||||
Term.info "albatross_log" ~version:"%%VERSION_NUM%%"
|
Term.info "albatross_log" ~version:"%%VERSION_NUM%%"
|
||||||
|
|
||||||
let () = match Term.eval cmd with `Ok () -> exit 0 | _ -> exit 1
|
let () = match Term.eval cmd with `Ok () -> exit 0 | _ -> exit 1
|
||||||
|
|
Loading…
Reference in a new issue