From e8243b8ecd5f5da4352481486cc73973e7a9b64e Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Tue, 18 Jul 2017 10:36:00 +0200 Subject: [PATCH] crowbar: do a graceful shutdown/reboot when invoked via crowbar (bsc#1047636) Currently there is a hard reboot executed which is interrupting a currently pending chef-client run. Normally that shouldn't be a problem but in the HA cluster case it can cause significant harm. --- .../templates/default/crowbar_join.suse.sh.erb | 17 +++++++++++++++++ crowbar_framework/app/models/node.rb | 2 +- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb b/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb index c96fdad08a..a474c89ccf 100644 --- a/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb +++ b/chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb @@ -124,6 +124,18 @@ wait_for_admin_server() { return 0 } +wait_for_chef_run_finish() { + + local tries_left=300 + while [[ $tries_left > 0 ]] ; do + if [ ! -r /var/log/chef/client.log ] || grep -q "Chef Run complete" /var/log/chef/client.log; then + break + fi + tries_left=$(($tries_left-1)) + sleep 1 + done +} + sync_time() { if [ -z "$VALID_NTP_SERVERS" ]; then echo_verbose "Skipping time synchronization..." @@ -508,6 +520,11 @@ elif [ "$MODE" == "stop" ]; then final_state="shutdown" [ "$RUNLEVEL" == "6" ] && final_state="reboot" + # Be graceful to a running chef-client run + wait_for_chef_run_finish + + systemctl stop chef-client.service + echo_debug "Stopping with state=$final_state (runlevel $RUNLEVEL)" HOSTNAME=$(hostname -f) diff --git a/crowbar_framework/app/models/node.rb b/crowbar_framework/app/models/node.rb index eac54693c9..93e00b0571 100644 --- a/crowbar_framework/app/models/node.rb +++ b/crowbar_framework/app/models/node.rb @@ -1058,7 +1058,7 @@ def set_state(state) if @node[:platform_family] == "windows" net_rpc_cmd(:power_cycle) else - ssh_cmd("/sbin/reboot") + ssh_cmd("/usr/sbin/crowbar_join --stop || /sbin/reboot") end end result