Experimental systemd socket activation
This commit is contained in:
parent
7030b1a3fa
commit
0c29e2b90d
|
@ -32,6 +32,7 @@ depends: [
|
||||||
"metrics" {>= "0.2.0"}
|
"metrics" {>= "0.2.0"}
|
||||||
"metrics-lwt" {>= "0.2.0"}
|
"metrics-lwt" {>= "0.2.0"}
|
||||||
"metrics-influx" {>= "0.2.0"}
|
"metrics-influx" {>= "0.2.0"}
|
||||||
|
"ocaml-systemd"
|
||||||
]
|
]
|
||||||
build: [
|
build: [
|
||||||
["dune" "subst"] {pinned}
|
["dune" "subst"] {pinned}
|
||||||
|
|
|
@ -148,7 +148,15 @@ let handle mvar ring s addr =
|
||||||
|
|
||||||
let m = Vmm_core.conn_metrics "unix"
|
let m = Vmm_core.conn_metrics "unix"
|
||||||
|
|
||||||
let jump _ file read_only influx tmpdir =
|
let server_socket systemd =
|
||||||
|
if systemd then
|
||||||
|
match Daemon.listen_fds () with
|
||||||
|
| [fd] -> Lwt.return (Lwt_unix.of_unix_file_descr fd)
|
||||||
|
| _ -> failwith "Unexpected number of sockets"
|
||||||
|
else
|
||||||
|
Vmm_lwt.server_socket `Log
|
||||||
|
|
||||||
|
let jump _ systemd file read_only influx tmpdir =
|
||||||
Sys.(set_signal sigpipe Signal_ignore) ;
|
Sys.(set_signal sigpipe Signal_ignore) ;
|
||||||
Albatross_cli.set_tmpdir tmpdir;
|
Albatross_cli.set_tmpdir tmpdir;
|
||||||
Lwt_main.run
|
Lwt_main.run
|
||||||
|
@ -161,7 +169,7 @@ let jump _ file read_only influx tmpdir =
|
||||||
Lwt.return_unit
|
Lwt.return_unit
|
||||||
end else begin
|
end else begin
|
||||||
Albatross_cli.init_influx "albatross_log" influx;
|
Albatross_cli.init_influx "albatross_log" influx;
|
||||||
Vmm_lwt.server_socket `Log >>= fun s ->
|
server_socket systemd >>= fun s ->
|
||||||
let ring = Vmm_ring.create `Startup () in
|
let ring = Vmm_ring.create `Startup () in
|
||||||
List.iter (Vmm_ring.write ring) entries ;
|
List.iter (Vmm_ring.write ring) entries ;
|
||||||
let mvar = Lwt_mvar.create_empty () in
|
let mvar = Lwt_mvar.create_empty () in
|
||||||
|
@ -191,8 +199,12 @@ let read_only =
|
||||||
let doc = "Only read log file and present entries" in
|
let doc = "Only read log file and present entries" in
|
||||||
Arg.(value & flag & info [ "read-only" ] ~doc)
|
Arg.(value & flag & info [ "read-only" ] ~doc)
|
||||||
|
|
||||||
|
let systemd =
|
||||||
|
let doc = "Pass this flag when systemd socket activation is being used" in
|
||||||
|
Arg.(value & flag & info [ "systemd-socket-activation" ] ~doc)
|
||||||
|
|
||||||
let cmd =
|
let cmd =
|
||||||
Term.(const jump $ setup_log $ file $ read_only $ influx $ tmpdir),
|
Term.(const jump $ setup_log $ systemd $ file $ read_only $ influx $ tmpdir),
|
||||||
Term.info "albatross_log" ~version
|
Term.info "albatross_log" ~version
|
||||||
|
|
||||||
let () = match Term.eval cmd with `Ok () -> exit 0 | _ -> exit 1
|
let () = match Term.eval cmd with `Ok () -> exit 0 | _ -> exit 1
|
||||||
|
|
|
@ -24,4 +24,4 @@
|
||||||
(public_name albatross-log)
|
(public_name albatross-log)
|
||||||
(package albatross)
|
(package albatross)
|
||||||
(modules albatross_log)
|
(modules albatross_log)
|
||||||
(libraries albatross.cli albatross))
|
(libraries albatross.cli albatross systemd))
|
||||||
|
|
|
@ -17,4 +17,5 @@ PIDFile=%t/albatross/log.pid
|
||||||
RestrictAddressFamilies=AF_UNIX
|
RestrictAddressFamilies=AF_UNIX
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
|
Also=albatross_log.socket
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|
12
packaging/Linux/albatross_log.socket
Normal file
12
packaging/Linux/albatross_log.socket
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
[Unit]
|
||||||
|
Description=Albatross log socket
|
||||||
|
PartOf=albatross_log.service
|
||||||
|
|
||||||
|
[Socket]
|
||||||
|
ListenStream=%t/albatross/util/log.sock
|
||||||
|
SocketUser=albatross
|
||||||
|
#SocketMode= # FIXME: permissions
|
||||||
|
Accept=no
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=sockets.target
|
Loading…
Reference in a new issue