Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

XSI-1773 improve logging if service file unexpectedly exists #6190

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading