mirror of
https://github.com/flatcar/scripts.git
synced 2026-05-04 19:56:32 +02:00
Add more robust ssh ping to be run on reboot for updates.
Upon investigation it seems there's a race condition when ssh starts up the first time. This adds a much more robust way to ping a machine when it's up then the previous method. Change-Id: I092744b259c169975d1c4f283f01a556fce24723 BUG=chromium-os:10867 TEST=Ran it 30 times with image_to_live --noupdate --nostateful_update. Review URL: http://codereview.chromium.org/6115009
This commit is contained in:
parent
3866923b00
commit
60587527c1
@ -34,8 +34,37 @@ function remote_sh() {
|
||||
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() {
|
||||
rm -f $TMP_KNOWN_HOSTS
|
||||
ping_ssh
|
||||
remote_sh "$@"
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user