Skip to content

Commit 99fd9c2

Browse files
committed
crowbar: do a graceful shutdown/reboot when invoked via crowbar
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.
1 parent 765ef67 commit 99fd9c2

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

chef/cookbooks/provisioner/templates/default/crowbar_join.suse.sh.erb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,18 @@ wait_for_admin_server() {
124124
return 0
125125
}
126126

127+
wait_for_chef_run_finish() {
128+
129+
local tries_left=300
130+
while [[ $tries_left > 0 ]] ; do
131+
if [ ! -r /var/log/chef/client.log ] || grep -q "Chef Run complete" /var/log/chef/client.log; then
132+
break
133+
fi
134+
tries_left=$(($tries_left-1))
135+
sleep 1
136+
done
137+
}
138+
127139
sync_time() {
128140
if [ -z "$VALID_NTP_SERVERS" ]; then
129141
echo_verbose "Skipping time synchronization..."
@@ -508,6 +520,11 @@ elif [ "$MODE" == "stop" ]; then
508520
final_state="shutdown"
509521
[ "$RUNLEVEL" == "6" ] && final_state="reboot"
510522

523+
# Be graceful to a running chef-client run
524+
wait_for_chef_run_finish
525+
526+
systemctl stop chef-client.service
527+
511528
echo_debug "Stopping with state=$final_state (runlevel $RUNLEVEL)"
512529

513530
HOSTNAME=$(hostname -f)

crowbar_framework/app/models/node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ def set_state(state)
10581058
if @node[:platform_family] == "windows"
10591059
net_rpc_cmd(:power_cycle)
10601060
else
1061-
ssh_cmd("/sbin/reboot")
1061+
ssh_cmd("/usr/sbin/crowbar_join --stop || /sbin/reboot")
10621062
end
10631063
end
10641064
result

0 commit comments

Comments
 (0)