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

Side by Side Diff: lib/cros_vm_lib.sh

Issue 5757001: Wait for child to exit after killing it. (Closed) Base URL: http://git.chromium.org/git/crosutils.git@master
Patch Set: doc Created 10 years 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) 2010 The Chromium OS Authors. All rights reserved. 1 # Copyright (c) 2010 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 # Common vm functions for use in crosutils. 5 # Common vm functions for use in crosutils.
6 6
7 DEFINE_string kvm_pid "" \ 7 DEFINE_string kvm_pid "" \
8 "Use this pid file. If it exists and is set, use the vm specified by pid." 8 "Use this pid file. If it exists and is set, use the vm specified by pid."
9 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." 9 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently."
10 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." 10 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm."
11 DEFINE_boolean snapshot ${FLAGS_FALSE} "Don't commit changes to image." 11 DEFINE_boolean snapshot ${FLAGS_FALSE} "Don't commit changes to image."
12 DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over." 12 DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over."
13 DEFINE_string vnc "" "VNC Server to display to instead of SDL." 13 DEFINE_string vnc "" "VNC Server to display to instead of SDL."
14 14
15 KVM_PID_FILE=/tmp/kvm.$$.pid 15 KVM_PID_FILE=/tmp/kvm.$$.pid
16 LIVE_VM_IMAGE= 16 LIVE_VM_IMAGE=
17 17
18 function get_pid() { 18 function get_pid() {
19 sudo cat "${KVM_PID_FILE}" 19 sudo cat "${KVM_PID_FILE}"
20 } 20 }
21 21
22 # General purpose wait for process to terminate.
23 # Incrementally backs off timeouts until it is waiting for 30 seconds and then
petkov 2010/12/09 23:01:28 by 30 you mean 31 -- 1+2+4+8+16? with the exponent
24 # tries to kill -9 before returning.
25 # $1 the process id.
26 function wait_on_pid() {
27 local timeout=1
28 while ps -p ${1} > /dev/null && [ ${timeout} -le 30 ]; do
29 warn "Process still running, sleeping for ${timeout}"
30 sleep ${timeout}
31 timeout=$((timeout*2))
32 done
33 if ps -p ${1}; then
34 sudo kill -9 ${1}
petkov 2010/12/09 23:01:28 the bonus kill here seems to contradict with the f
35 fi
36 }
37
22 # TODO(rtc): These flags assume that we'll be using KVM on Lucid and won't work 38 # TODO(rtc): These flags assume that we'll be using KVM on Lucid and won't work
23 # on Hardy. 39 # on Hardy.
24 # $1: Path to the virtual image to start. 40 # $1: Path to the virtual image to start.
25 function start_kvm() { 41 function start_kvm() {
26 # Override default pid file. 42 # Override default pid file.
27 [ -n "${FLAGS_kvm_pid}" ] && KVM_PID_FILE=${FLAGS_kvm_pid} 43 [ -n "${FLAGS_kvm_pid}" ] && KVM_PID_FILE=${FLAGS_kvm_pid}
28 if [ -e "${KVM_PID_FILE}" ]; then 44 if [ -e "${KVM_PID_FILE}" ]; then
29 local pid=$(get_pid) 45 local pid=$(get_pid)
30 # Check if the process exists. 46 # Check if the process exists.
31 if ps -p ${pid} > /dev/null ; then 47 if ps -p ${pid} > /dev/null ; then
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 function stop_kvm() { 108 function stop_kvm() {
93 if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then 109 if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then
94 echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \ 110 echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \
95 "--kvm_pid ${KVM_PID_FILE} to re-connect to it." >&2 111 "--kvm_pid ${KVM_PID_FILE} to re-connect to it." >&2
96 else 112 else
97 echo "Stopping the KVM instance" >&2 113 echo "Stopping the KVM instance" >&2
98 local pid=$(get_pid) 114 local pid=$(get_pid)
99 if [ -n "${pid}" ]; then 115 if [ -n "${pid}" ]; then
100 echo "Killing ${pid}" >&2 116 echo "Killing ${pid}" >&2
101 sudo kill ${pid} 117 sudo kill ${pid}
118 wait_on_pid ${pid}
102 sudo rm "${KVM_PID_FILE}" 119 sudo rm "${KVM_PID_FILE}"
103 else 120 else
104 echo "No kvm pid found to stop." >&2 121 echo "No kvm pid found to stop." >&2
105 return 1 122 return 1
106 fi 123 fi
107 fi 124 fi
108 } 125 }
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