mirror of
https://github.com/flatcar/scripts.git
synced 2025-09-25 07:31:01 +02:00
Put wait around remote_reboot core code itself rather than around the ping.
The last CL had a race condition where we could ping but not run the reboot_check code. This CL moves to watch the reboot_check code rather than a ping. Change-Id: I8bdda97850ac085be9cf5dfb0b80fb7e1c8dd212 BUG=chromium-os:10867 TEST=Ran it 100 times without error. Review URL: http://codereview.chromium.org/6287001
This commit is contained in:
parent
78476aba5f
commit
bb4661dee7
@ -36,37 +36,8 @@ function remote_sh() {
|
|||||||
return ${PIPESTATUS[0]}
|
return ${PIPESTATUS[0]}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Checks to see if pid $1 is running.
|
|
||||||
function is_pid_running() {
|
|
||||||
ps -p ${1} 2>&1 > /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
# Wait function given an additional timeout argument.
|
|
||||||
# $1 - pid to wait on.
|
|
||||||
# $2 - timeout to wait for.
|
|
||||||
function wait_with_timeout() {
|
|
||||||
local pid=$1
|
|
||||||
local timeout=$2
|
|
||||||
local -r TIMEOUT_INC=1
|
|
||||||
local current_timeout=0
|
|
||||||
while is_pid_running ${pid} && [ ${current_timeout} -lt ${timeout} ]; do
|
|
||||||
sleep ${TIMEOUT_INC}
|
|
||||||
current_timeout=$((current_timeout + TIMEOUT_INC))
|
|
||||||
done
|
|
||||||
is_pid_running ${pid}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Robust ping that will monitor ssh and not hang even if ssh hangs.
|
|
||||||
function ping_ssh() {
|
|
||||||
remote_sh "true" &
|
|
||||||
local pid=$!
|
|
||||||
wait_with_timeout ${pid} 5
|
|
||||||
! kill -9 ${pid} 2> /dev/null
|
|
||||||
}
|
|
||||||
|
|
||||||
function remote_sh_allow_changed_host_key() {
|
function remote_sh_allow_changed_host_key() {
|
||||||
rm -f $TMP_KNOWN_HOSTS
|
rm -f $TMP_KNOWN_HOSTS
|
||||||
ping_ssh
|
|
||||||
remote_sh "$@"
|
remote_sh "$@"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,12 +63,29 @@ function learn_board() {
|
|||||||
info "Target reports board is ${FLAGS_board}"
|
info "Target reports board is ${FLAGS_board}"
|
||||||
}
|
}
|
||||||
|
|
||||||
function remote_reboot {
|
# Checks to see if pid $1 is running.
|
||||||
info "Rebooting."
|
function is_pid_running() {
|
||||||
remote_sh "touch /tmp/awaiting_reboot; reboot"
|
ps -p ${1} 2>&1 > /dev/null
|
||||||
local output_file
|
}
|
||||||
output_file="${TMP}/output"
|
|
||||||
|
|
||||||
|
# Wait function given an additional timeout argument.
|
||||||
|
# $1 - pid to wait on.
|
||||||
|
# $2 - timeout to wait for.
|
||||||
|
function wait_with_timeout() {
|
||||||
|
local pid=$1
|
||||||
|
local timeout=$2
|
||||||
|
local -r TIMEOUT_INC=1
|
||||||
|
local current_timeout=0
|
||||||
|
while is_pid_running ${pid} && [ ${current_timeout} -lt ${timeout} ]; do
|
||||||
|
sleep ${TIMEOUT_INC}
|
||||||
|
current_timeout=$((current_timeout + TIMEOUT_INC))
|
||||||
|
done
|
||||||
|
! is_pid_running ${pid}
|
||||||
|
}
|
||||||
|
|
||||||
|
# Checks to see if a machine has rebooted using the presence of a tmp file.
|
||||||
|
function check_if_rebooted() {
|
||||||
|
local output_file="${TMP}/output"
|
||||||
while true; do
|
while true; do
|
||||||
REMOTE_OUT=""
|
REMOTE_OUT=""
|
||||||
# This may fail while the machine is down so generate output and a
|
# This may fail while the machine is down so generate output and a
|
||||||
@ -108,12 +96,23 @@ function remote_reboot {
|
|||||||
if grep -q "0" "${output_file}"; then
|
if grep -q "0" "${output_file}"; then
|
||||||
if grep -q "1" "${output_file}"; then
|
if grep -q "1" "${output_file}"; then
|
||||||
info "Not yet rebooted"
|
info "Not yet rebooted"
|
||||||
|
sleep .5
|
||||||
else
|
else
|
||||||
info "Rebooted and responding"
|
info "Rebooted and responding"
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
sleep .5
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
function remote_reboot() {
|
||||||
|
info "Rebooting."
|
||||||
|
remote_sh "touch /tmp/awaiting_reboot; reboot"
|
||||||
|
while true; do
|
||||||
|
check_if_rebooted &
|
||||||
|
local pid=$!
|
||||||
|
wait_with_timeout ${pid} 30 && break
|
||||||
|
! kill -9 ${pid} 2> /dev/null
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user