arm-autonomy/xenguest-manager: Make stop by default a blocking action
PATCH 1/1 arm-autonomy/xenguest-manager: Make stop by default a blocking action
From: Nathan Dunne <[email protected]>
Added -w parameter to xl shutdown to force it not to return until the action is completed, and modified logging to reflect this
Stop operation can be configured to return immediately using --nowait parameter, or to force destroy the guest if the graceful shutdown fails using --kill. Both are now documented in usage().
Issue-Id: SCM-1861
--- .../xenguest/files/xenguest-init | 2 +- .../xenguest/files/xenguest-manager | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-)
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-init +1 -1
@@ -68,7 +68,7 @@ case "$1" in # update guest list guestlist=$(xenguest-manager status | grep Running | cut -d ":" -f1) for f in ${guestlist}; do - xl shutdown -w ${f} || xl destroy ${f} + xenguest-manager shutdown ${f} --kill done ;; reload)
meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-manager +31 -5
@@ -200,6 +200,12 @@ with ACTION being one of: stop|shutdown GUESTNAME Stop guest GUESTNAME (send stop signal and let it shutdown normally) + Pass 'stop|shutdown GUESTNAME --nowait' to return immediately, rather + than waiting for success or failure to return. + Pass 'stop|shutdown GUESTNAME --kill' to force kill the guest if + signalling the graceful shutdown fails for any reason + + These two parameters are incompatible, so only one should be passed kill|destroy GUESTNAME Kill guest GUESTNAME (stop directly the guest without signaling it)
@@ -871,17 +877,36 @@ function xenguest_guest_start() # Private function xenguest_guest_stop() { + local guestname + local extra_arg + guestname="${1}" + extra_arg="${2}" + + shutdown_args="" + log info "Attempting to stop guest '${guestname}'" + if [[ ${extra_arg} != "--nowait" ]]; then + shutdown_args+=" -w" + fi + check_private - log_command "xl shutdown ${guestname}" + log_command "xl shutdown ${shutdown_args} ${guestname}" if [ $? -ne 0 ]; then - log fatal "Stopping guest '${guestname}' failed." + if [[ ${extra_arg} == "--kill" ]]; then + log info "Stopping '${guestname}' failed, calling kill..." + xenguest_guest_kill "${guestname}" + else + log fatal "Stopping guest '${guestname}' failed." + fi + fi + if [[ "${extra_arg}" != "--nowait" ]]; then + log info "Guest '${guestname}' stopped successfully" + else + log info "xl shutdown exited successfully for guest '${guestname}'." fi - - echo "Guest '${guestname}' may not have stopped yet. Use 'status' to check" } # Private
@@ -1066,10 +1091,11 @@ case ${cmd} in ;; stop|shutdown) guestname="${arg1:-}" + extra_arg="${arg2:-}" check_guest_arg ${cmd} ${guestname} check_guest_exist ${guestname} check_guest_running ${guestname} - xenguest_guest_stop ${guestname} + xenguest_guest_stop "${guestname}" "${extra_arg}" ;; kill|destroy) guestname="${arg1:-}"
Signature · 1 line
2.17.1
Quoted 5 lines · Nathan Dunne
From: Nathan Dunne <[email protected]>
Added -w parameter to xl shutdown to force it not to return until the action is completed, and modified logging to reflect this
Quoted 8 lines
Stop operation can be configured to return immediately using --nowait parameter, or to force destroy the guest if the graceful shutdown fails using --kill. Both are now documented in
usage().Issue-Id: SCM-1861
Signed-off-by Nathan Dunne <[email protected]>Change-Id I664acc8a6a1eb17619fa2fd9b372ea661e537923---
Patch included in master branch
Thanks,
Jon
Quoted 95 lines
.../xenguest/files/xenguest-init | 2 +- .../xenguest/files/xenguest-manager | 36 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-)meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-init +1
-1@@ -68,7 +68,7 @@ case "$1" in # update guest list guestlist=$(xenguest-manager status | grep Running | cut -d ":" -f1) for f in ${guestlist}; do - xl shutdown -w ${f} || xl destroy ${f} + xenguest-manager shutdown ${f} --kill done ;; reload)meta-arm-autonomy/recipes-extended/xenguest/files/xenguest-manager +31
-5@@ -200,6 +200,12 @@ with ACTION being one of: stop|shutdown GUESTNAME Stop guest GUESTNAME (send stop signal and let it shutdown normally) + Pass 'stop|shutdown GUESTNAME --nowait' to return immediately, rather + than waiting for success or failure to return. + Pass 'stop|shutdown GUESTNAME --kill' to force kill the guest if + signalling the graceful shutdown fails for any reason + + These two parameters are incompatible, so only one should be passed kill|destroy GUESTNAME Kill guest GUESTNAME (stop directly the guest without signaling it)@@ -871,17 +877,36 @@ function xenguest_guest_start() # Private function xenguest_guest_stop() { + local guestname + local extra_arg + guestname="${1}" + extra_arg="${2}" + + shutdown_args="" + log info "Attempting to stop guest '${guestname}'" + if [[ ${extra_arg} != "--nowait" ]]; then + shutdown_args+=" -w" + fi + check_private - log_command "xl shutdown ${guestname}" + log_command "xl shutdown ${shutdown_args} ${guestname}" if [ $? -ne 0 ]; then - log fatal "Stopping guest '${guestname}' failed." + if [[ ${extra_arg} == "--kill" ]]; then + log info "Stopping '${guestname}' failed, calling kill..." + xenguest_guest_kill "${guestname}" + else + log fatal "Stopping guest '${guestname}' failed." + fi + fi + if [[ "${extra_arg}" != "--nowait" ]]; then + log info "Guest '${guestname}' stopped successfully" + else + log info "xl shutdown exited successfully for guest '${guestname}'." fi - - echo "Guest '${guestname}' may not have stopped yet. Use 'status' to check" } # Private@@ -1066,10 +1091,11 @@ case ${cmd} in ;; stop|shutdown) guestname="${arg1:-}" + extra_arg="${arg2:-}" check_guest_arg ${cmd} ${guestname} check_guest_exist ${guestname} check_guest_running ${guestname} - xenguest_guest_stop ${guestname} + xenguest_guest_stop "${guestname}" "${extra_arg}" ;; kill|destroy) guestname="${arg1:-}"Signature · 1 line
2.17.1