Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Unified Diff: remote_access.sh

Issue 6115009: Add more robust ssh ping to be run on reboot for updates. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: use local -r Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: remote_access.sh
diff --git a/remote_access.sh b/remote_access.sh
index 794deff8e755ed0a98a35513016e86c3239cdbad..8b8abf7a4e2ecf790663b6431039684dc32fd263 100644
--- a/remote_access.sh
+++ b/remote_access.sh
@@ -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 "$@"
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698