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

Side by Side 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: 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 # Library for setting up remote access and running remote commands. 5 # Library for setting up remote access and running remote commands.
6 6
7 DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\ 7 DEFAULT_PRIVATE_KEY="${GCLIENT_ROOT}/src/scripts/mod_for_test_scripts/\
8 ssh_keys/testing_rsa" 8 ssh_keys/testing_rsa"
9 9
10 DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance" 10 DEFINE_string remote "" "remote hostname/IP of running Chromium OS instance"
(...skipping 16 matching lines...) Expand all
27 UserKnownHostsFile=$TMP_KNOWN_HOSTS" --no-R \ 27 UserKnownHostsFile=$TMP_KNOWN_HOSTS" --no-R \
28 --files-from=$1 root@${FLAGS_remote}:/ $2 28 --files-from=$1 root@${FLAGS_remote}:/ $2
29 } 29 }
30 30
31 function remote_sh() { 31 function remote_sh() {
32 REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \ 32 REMOTE_OUT=$(ssh -p ${FLAGS_ssh_port} -o StrictHostKeyChecking=no -o \
33 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@") 33 UserKnownHostsFile=$TMP_KNOWN_HOSTS root@$FLAGS_remote "$@")
34 return ${PIPESTATUS[0]} 34 return ${PIPESTATUS[0]}
35 } 35 }
36 36
37 # Robust ping that will monitor ssh and not hang even if ssh hangs.
38 # This method attempts to run true on the remote device. We check to see
39 # if ssh is still running after a timeout (is hanging). If so, we retry
40 # 3 times before giving up. We wait up to 5 seconds for true to return each
41 # time.
42 function ping_ssh() {
43 local timeout=5
44 local timeout_inc=.5
45 local retries=3
46 while [ ${retries} -gt 0 ]; do
47 nohup -- remote_sh "true" 2> /dev/null &
48 local ssh_pid=$!
49 local current_timeout=0
petkov 2011/01/12 18:38:52 this site shows an interesting way to implement a
50 while ps -p ${ssh_pid} > /dev/null && \
petkov 2011/01/12 18:38:52 no need for trailing \ I think
51 [ ${current_timeout} -gt ${timeout} ]; do
petkov 2011/01/12 18:38:52 current_timeout is 0, timeout is 5 -- this evaluat
52 sleep ${timeout}
53 echo "blah"
petkov 2011/01/12 18:38:52 blah? :)
54 current_timeout=$((current_timeout+timeout_inc))
petkov 2011/01/12 18:38:52 add spaces around +
55 done
56 # If pid has been killed, kill will return 0.
57 if ! kill ${ssh_pid} &> /dev/null; then
58 break
59 else
petkov 2011/01/12 18:38:52 s/else/fi/, or better: kill ... || break are you
60 retries=$((retries-1))
61 fi
62 done
63 }
64
37 function remote_sh_allow_changed_host_key() { 65 function remote_sh_allow_changed_host_key() {
38 rm -f $TMP_KNOWN_HOSTS 66 rm -f $TMP_KNOWN_HOSTS
67 # Often on first boot we can have a race condition where the initial ssh
68 # can hang. Pinging first mitigates this.
69 ping_ssh
39 remote_sh "$@" 70 remote_sh "$@"
40 } 71 }
41 72
42 function set_up_remote_access() { 73 function set_up_remote_access() {
43 if [ -z "$SSH_AGENT_PID" ]; then 74 if [ -z "$SSH_AGENT_PID" ]; then
44 eval $(ssh-agent) 75 eval $(ssh-agent)
45 OWN_SSH_AGENT=1 76 OWN_SSH_AGENT=1
46 else 77 else
47 OWN_SSH_AGENT=0 78 OWN_SSH_AGENT=0
48 fi 79 fi
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 137
107 function remote_access_init() { 138 function remote_access_init() {
108 TMP_PRIVATE_KEY=$TMP/private_key 139 TMP_PRIVATE_KEY=$TMP/private_key
109 TMP_KNOWN_HOSTS=$TMP/known_hosts 140 TMP_KNOWN_HOSTS=$TMP/known_hosts
110 if [ -z "$FLAGS_remote" ]; then 141 if [ -z "$FLAGS_remote" ]; then
111 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance" 142 echo "Please specify --remote=<IP-or-hostname> of the Chromium OS instance"
112 exit 1 143 exit 1
113 fi 144 fi
114 set_up_remote_access 145 set_up_remote_access
115 } 146 }
OLDNEW
« 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