diff --git a/ocaml/forkexecd/lib/dune b/ocaml/forkexecd/lib/dune index 749f173b97..e8dd8c8312 100644 --- a/ocaml/forkexecd/lib/dune +++ b/ocaml/forkexecd/lib/dune @@ -13,6 +13,7 @@ xapi-log xapi-stdext-pervasives xapi-stdext-unix + xapi-stdext-date xapi-tracing ) (preprocess (per_module ((pps ppx_deriving_rpc) Fe)))) diff --git a/ocaml/forkexecd/lib/fe_systemctl.ml b/ocaml/forkexecd/lib/fe_systemctl.ml index b36ee6674a..046396002c 100644 --- a/ocaml/forkexecd/lib/fe_systemctl.ml +++ b/ocaml/forkexecd/lib/fe_systemctl.ml @@ -130,14 +130,28 @@ let is_active ~service = in Unix.WEXITED 0 = status -let exists ~service = - Sys.file_exists (Filename.concat run_path (service ^ ".service")) +(** path to service file *) +let path service = Filename.concat run_path (service ^ ".service") + +(** does [service] file exist *) +let exists ~service = Sys.file_exists (path service) + +(** creation time of [path] as a string *) +let ctime path = + let ctime = Unix.((stat path).st_ctime) in + Xapi_stdext_date.Date.(of_unix_time ctime |> to_rfc3339) let start_transient ?env ?properties ?(exec_ty = Type.Simple) ~service cmd args = - if exists ~service then - (* this can only happen if there is a bug in the caller *) - invalid_arg (Printf.sprintf "Tried to start %s twice" service) ; + ( match exists ~service with + | true -> + (* this can only happen if there is a bug in the caller *) + let path = path service in + let invalid fmt = Printf.ksprintf invalid_arg fmt in + invalid "Tried to start %s twice: %s exists (%s)" service path (ctime path) + | false -> + () + ) ; try start_transient ?env ?properties ~exec_ty ~service cmd args with e -> Backtrace.is_important e ;