| OLD | NEW |
| 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 . "$(dirname "$0")/cros_vm_constants.sh" | |
| 8 | |
| 9 DEFINE_string kvm_pid "" \ | 7 DEFINE_string kvm_pid "" \ |
| 10 "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." |
| 11 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." | 9 DEFINE_boolean no_graphics ${FLAGS_FALSE} "Runs the KVM instance silently." |
| 12 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." | 10 DEFINE_boolean persist "${FLAGS_FALSE}" "Persist vm." |
| 13 DEFINE_boolean snapshot ${FLAGS_FALSE} "Don't commit changes to image." | 11 DEFINE_boolean snapshot ${FLAGS_FALSE} "Don't commit changes to image." |
| 14 DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over." | 12 DEFINE_integer ssh_port 9222 "Port to tunnel ssh traffic over." |
| 15 | 13 |
| 16 KVM_PID_FILE=/tmp/kvm.$$.pid | 14 KVM_PID_FILE=/tmp/kvm.$$.pid |
| 17 | 15 |
| 18 function get_pid() { | 16 function get_pid() { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 41 local nographics="" | 39 local nographics="" |
| 42 local usesnapshot="" | 40 local usesnapshot="" |
| 43 if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then | 41 if [ ${FLAGS_no_graphics} -eq ${FLAGS_TRUE} ]; then |
| 44 nographics="-nographic" | 42 nographics="-nographic" |
| 45 fi | 43 fi |
| 46 | 44 |
| 47 if [ ${FLAGS_snapshot} -eq ${FLAGS_TRUE} ]; then | 45 if [ ${FLAGS_snapshot} -eq ${FLAGS_TRUE} ]; then |
| 48 snapshot="-snapshot" | 46 snapshot="-snapshot" |
| 49 fi | 47 fi |
| 50 | 48 |
| 51 sudo kvm -m ${DEFAULT_MEM} \ | 49 sudo kvm -m 1024 \ |
| 52 -vga std \ | 50 -vga std \ |
| 53 -pidfile "${KVM_PID_FILE}" \ | 51 -pidfile "${KVM_PID_FILE}" \ |
| 54 -daemonize \ | 52 -daemonize \ |
| 55 -net nic \ | 53 -net nic \ |
| 56 ${nographics} \ | 54 ${nographics} \ |
| 57 ${snapshot} \ | 55 ${snapshot} \ |
| 58 -net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \ | 56 -net user,hostfwd=tcp::${FLAGS_ssh_port}-:22 \ |
| 59 -hda "${1}" | 57 -hda "${1}" |
| 60 fi | 58 fi |
| 61 } | 59 } |
| 62 | 60 |
| 63 function stop_kvm() { | 61 function stop_kvm() { |
| 64 if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then | 62 if [ "${FLAGS_persist}" -eq "${FLAGS_TRUE}" ]; then |
| 65 echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \ | 63 echo "Persist requested. Use --ssh_port ${FLAGS_ssh_port} " \ |
| 66 "--kvm_pid ${KVM_PID_FILE} to re-connect to it." | 64 "--kvm_pid ${KVM_PID_FILE} to re-connect to it." |
| 67 else | 65 else |
| 68 echo "Stopping the KVM instance" | 66 echo "Stopping the KVM instance" |
| 69 local pid=$(get_pid) | 67 local pid=$(get_pid) |
| 70 echo "Killing ${pid}" | 68 echo "Killing ${pid}" |
| 71 sudo kill ${pid} | 69 sudo kill ${pid} |
| 72 sudo rm "${KVM_PID_FILE}" | 70 sudo rm "${KVM_PID_FILE}" |
| 73 fi | 71 fi |
| 74 } | 72 } |
| OLD | NEW |