Generate systemd.socket files
This commit is contained in:
parent
f280892894
commit
f7a3c4fdac
|
@ -1,12 +0,0 @@
|
|||
[Unit]
|
||||
Description=Albatross console socket
|
||||
PartOf=albatross_console.service
|
||||
|
||||
[Socket]
|
||||
ListenStream=%t/albatross/util/console.sock
|
||||
SocketUser=albatross
|
||||
SocketMode=0600
|
||||
Accept=no
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
|
@ -1,11 +0,0 @@
|
|||
[Unit]
|
||||
Description=Albatross daemon socket
|
||||
PartOf=albatross_daemon.service
|
||||
|
||||
[Socket]
|
||||
ListenStream=%t/albatross/util/vmmd.sock
|
||||
SocketMode=0600
|
||||
Accept=no
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
|
@ -1,12 +0,0 @@
|
|||
[Unit]
|
||||
Description=Albatross log socket
|
||||
PartOf=albatross_log.service
|
||||
|
||||
[Socket]
|
||||
ListenStream=%t/albatross/util/log.sock
|
||||
SocketUser=albatross
|
||||
SocketMode=0600
|
||||
Accept=no
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
|
@ -1,12 +0,0 @@
|
|||
[Unit]
|
||||
Description=Albatross stats socket
|
||||
PartOf=albatross_stats.service
|
||||
|
||||
[Socket]
|
||||
ListenStream=%t/albatross/util/stat.sock
|
||||
SocketUser=albatross
|
||||
SocketMode=0600
|
||||
Accept=no
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
3
packaging/Linux/dune
Normal file
3
packaging/Linux/dune
Normal file
|
@ -0,0 +1,3 @@
|
|||
(executable
|
||||
(name gen_socket)
|
||||
(libraries albatross))
|
51
packaging/Linux/gen_socket.ml
Normal file
51
packaging/Linux/gen_socket.ml
Normal file
|
@ -0,0 +1,51 @@
|
|||
let pp_service ppf = function
|
||||
| `Console -> Fmt.pf ppf "console"
|
||||
| `Vmmd -> Fmt.pf ppf "daemon"
|
||||
| `Stats -> Fmt.pf ppf "stats"
|
||||
| `Log -> Fmt.pf ppf "log"
|
||||
|
||||
let unprivileged_services = [ `Console; `Log; `Stats ]
|
||||
let privileged_services = [ `Vmmd ]
|
||||
|
||||
let unprivileged_format : _ format= {|[Unit]
|
||||
Description=Albatross %s socket
|
||||
PartOf=%s
|
||||
|
||||
[Socket]
|
||||
ListenStream=%s
|
||||
SocketUser=albatross
|
||||
SocketMode=0600
|
||||
Accept=no
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
|}
|
||||
|
||||
let privileged_format : _ format = {|[Unit]
|
||||
Description=Albatross %s socket
|
||||
PartOf=%s
|
||||
|
||||
[Socket]
|
||||
ListenStream=%s
|
||||
SocketMode=0600
|
||||
Accept=no
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
||||
|}
|
||||
|
||||
let write_socket privileged service =
|
||||
let out_file = Fmt.str "albatross_%a.socket" pp_service service in
|
||||
let systemd_service = Fmt.str "albatross_%a.service" pp_service service in
|
||||
let service_name = Fmt.str "%a" pp_service service in
|
||||
let socket_path = Vmm_core.socket_path (service :> Vmm_core.service) in
|
||||
let oc = open_out out_file in
|
||||
let ppf = Format.formatter_of_out_channel oc in
|
||||
Fmt.pf ppf (if privileged then privileged_format else unprivileged_format)
|
||||
service_name systemd_service socket_path
|
||||
|
||||
let () =
|
||||
let tmpdir = Fpath.(v "%t" / "albatross") in
|
||||
let () = Vmm_core.set_tmpdir tmpdir in
|
||||
List.iter (write_socket false) unprivileged_services;
|
||||
List.iter (write_socket true) privileged_services
|
Loading…
Reference in a new issue