diff options
author | Alban Gruin | 2020-12-30 16:36:23 +0100 |
---|---|---|
committer | Alban Gruin | 2020-12-30 16:36:23 +0100 |
commit | f6ee00c1b33b35f6adcd8c27cc4013636fd202a4 (patch) | |
tree | 5ed3960bd93e55b1d88ac7b1aa7003b8a35f4279 /src/ucs.ml | |
parent | 7a3cd6d029e73a28e1229ac24edb4c5bd87162b9 (diff) |
ucs: properly remove the unix socket when a signal is received
When using a unix socket to serve µCS, the file would not be removed
when the server was shut down. Teach µCS to catch sigints and sigterms,
and call unlink on the socket if it exists.
Signed-off-by: Alban Gruin <alban at pa1ch dot fr>
Diffstat (limited to 'src/ucs.ml')
-rw-r--r-- | src/ucs.ml | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -49,7 +49,17 @@ let () = mode = match socket with | Some s -> `Unix_domain_socket (`File s) | None -> `TCP (`Port port) in - Lwt_main.run (Server.serve base_url celcat_uri mode) in + let stop, r = Lwt.wait () in + Lwt_unix.on_signal Sys.sigint + (fun _ -> Lwt.wakeup r ()) |> ignore; + Lwt_unix.on_signal Sys.sigterm + (fun _ -> Lwt.wakeup r ()) |> ignore; + Lwt_main.run ( + Lwt.finalize + (fun () -> Server.serve base_url celcat_uri mode stop) + (fun () -> match socket with + | Some s -> Lwt_unix.unlink s + | None -> Lwt.return_unit)) in let cmd = let doc = "micro celcatsanitizer: convert celcat \ calendar to ICS files, on the fly." and |