Skip to content

Commit 90b0faf

Browse files
authored
XSI-1773 improve logging if service file unexpectedly exists (#6190)
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.
2 parents 4cbacdb + ac2255b commit 90b0faf

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

ocaml/forkexecd/lib/dune

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
xapi-log
1414
xapi-stdext-pervasives
1515
xapi-stdext-unix
16+
xapi-stdext-date
1617
xapi-tracing
1718
)
1819
(preprocess (per_module ((pps ppx_deriving_rpc) Fe))))

ocaml/forkexecd/lib/fe_systemctl.ml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,14 +130,28 @@ let is_active ~service =
130130
in
131131
Unix.WEXITED 0 = status
132132

133-
let exists ~service =
134-
Sys.file_exists (Filename.concat run_path (service ^ ".service"))
133+
(** path to service file *)
134+
let path service = Filename.concat run_path (service ^ ".service")
135+
136+
(** does [service] file exist *)
137+
let exists ~service = Sys.file_exists (path service)
138+
139+
(** creation time of [path] as a string *)
140+
let ctime path =
141+
let ctime = Unix.((stat path).st_ctime) in
142+
Xapi_stdext_date.Date.(of_unix_time ctime |> to_rfc3339)
135143

136144
let start_transient ?env ?properties ?(exec_ty = Type.Simple) ~service cmd args
137145
=
138-
if exists ~service then
139-
(* this can only happen if there is a bug in the caller *)
140-
invalid_arg (Printf.sprintf "Tried to start %s twice" service) ;
146+
( match exists ~service with
147+
| true ->
148+
(* this can only happen if there is a bug in the caller *)
149+
let path = path service in
150+
let invalid fmt = Printf.ksprintf invalid_arg fmt in
151+
invalid "Tried to start %s twice: %s exists (%s)" service path (ctime path)
152+
| false ->
153+
()
154+
) ;
141155
try start_transient ?env ?properties ~exec_ty ~service cmd args
142156
with e ->
143157
Backtrace.is_important e ;

0 commit comments

Comments
 (0)