Skip to content

Commit

Permalink
Merge pull request #5977 from Vincent-lau/private/shul2/gc-hooks
Browse files Browse the repository at this point in the history
 CA-397788: Execute pre shutdown hook for xapi
  • Loading branch information
robhoes authored Sep 10, 2024
2 parents 101d1a8 + c13b8da commit 88a47be
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
22 changes: 17 additions & 5 deletions ocaml/xapi/xapi_hooks.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ let scriptname__host_pre_declare_dead = "host-pre-declare-dead"

let scriptname__host_post_declare_dead = "host-post-declare-dead"

let scriptname__xapi_pre_shutdown = "xapi-pre-shutdown"

(* Host Script hook reason codes *)
let reason__fenced = "fenced"

Expand Down Expand Up @@ -71,11 +73,15 @@ let execute_hook ~__context ~script_name ~args ~reason =
try
debug "Executing hook '%s/%s' with args [ %s ]" script_name script
(String.concat "; " args) ;
ignore
(Forkhelpers.execute_command_get_output
(Filename.concat script_dir script)
args
)
let os, es =
Forkhelpers.execute_command_get_output
(Filename.concat script_dir script)
args
in
debug
"%s: Output of executing hook '%s/%s' with args [ %s ] is %s, err is \
%s"
__FUNCTION__ script_name script (String.concat "; " args) os es
with
| Forkhelpers.Spawn_internal_error (_, stdout, Unix.WEXITED i)
(* i<>0 since that case does not generate exn *)
Expand Down Expand Up @@ -123,6 +129,12 @@ let host_pre_declare_dead ~__context ~host ~reason =
()
)

let xapi_pre_shutdown ~__context ~host ~reason =
info "%s Running xapi pre shutdown hooks for %s" __FUNCTION__
(Ref.string_of host) ;
execute_host_hook ~__context ~script_name:scriptname__xapi_pre_shutdown
~reason ~host

(* Called when host died -- !! hook code in here to abort outstanding forwarded ops *)
let internal_host_dead_hook __context host =
info "Running host dead hook for %s" (Ref.string_of host) ;
Expand Down
3 changes: 3 additions & 0 deletions ocaml/xapi/xapi_host.ml
Original file line number Diff line number Diff line change
Expand Up @@ -778,6 +778,9 @@ let restart_agent ~__context ~host:_ =

let shutdown_agent ~__context =
debug "Host.restart_agent: Host agent will shutdown in 1s!!!!" ;
let localhost = Helpers.get_localhost ~__context in
Xapi_hooks.xapi_pre_shutdown ~__context ~host:localhost
~reason:Xapi_hooks.reason__clean_shutdown ;
Xapi_fuse.light_fuse_and_dont_restart ~fuse_length:1. ()

let disable ~__context ~host =
Expand Down
2 changes: 1 addition & 1 deletion ocaml/xapi/xapi_host.mli
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ val retrieve_wlb_evacuate_recommendations :

val restart_agent : __context:'a -> host:'b -> unit

val shutdown_agent : __context:'a -> unit
val shutdown_agent : __context:Context.t -> unit

val disable : __context:Context.t -> host:[`host] Ref.t -> unit

Expand Down

0 comments on commit 88a47be

Please sign in to comment.