Skip to content

Commit

Permalink
XSI-1773 improve logging if service file unexpectedly exists
Browse files Browse the repository at this point in the history
We have seen failures where a service file unexpectedly exists. It could
have been left behind but a failed stop but we don't have evidence for
that. To help with this, provide more details of the file found.

Signed-off-by: Christian Lindig <[email protected]>
  • Loading branch information
Christian Lindig committed Dec 19, 2024
1 parent 8550769 commit ac2255b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions ocaml/forkexecd/lib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -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))))
24 changes: 19 additions & 5 deletions ocaml/forkexecd/lib/fe_systemctl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 ;
Expand Down

0 comments on commit ac2255b

Please sign in to comment.