Experimental systemd socket activation

This commit is contained in:
Reynir Björnsson 2020-11-11 11:41:07 +01:00
parent 7030b1a3fa
commit 0c29e2b90d
5 changed files with 30 additions and 4 deletions

View File

@ -32,6 +32,7 @@ depends: [
"metrics" {>= "0.2.0"}
"metrics-lwt" {>= "0.2.0"}
"metrics-influx" {>= "0.2.0"}
"ocaml-systemd"
]
build: [
["dune" "subst"] {pinned}

View File

@ -148,7 +148,15 @@ let handle mvar ring s addr =
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) ;
Albatross_cli.set_tmpdir tmpdir;
Lwt_main.run
@ -161,7 +169,7 @@ let jump _ file read_only influx tmpdir =
Lwt.return_unit
end else begin
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
List.iter (Vmm_ring.write ring) entries ;
let mvar = Lwt_mvar.create_empty () in
@ -191,8 +199,12 @@ let read_only =
let doc = "Only read log file and present entries" in
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 =
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
let () = match Term.eval cmd with `Ok () -> exit 0 | _ -> exit 1

View File

@ -24,4 +24,4 @@
(public_name albatross-log)
(package albatross)
(modules albatross_log)
(libraries albatross.cli albatross))
(libraries albatross.cli albatross systemd))

View File

@ -17,4 +17,5 @@ PIDFile=%t/albatross/log.pid
RestrictAddressFamilies=AF_UNIX
[Install]
Also=albatross_log.socket
WantedBy=multi-user.target

View 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