3
# (C) Copyright Canonical 2011,2012
5
# This library is free software; you can redistribute it and/or
6
# modify it under the terms of the GNU Lesser General Public
7
# License as published by the Free Software Foundation; either
8
# version 2.1 of the License, or (at your option) any later version.
10
# This library is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
# Lesser General Public License for more details.
15
# You should have received a copy of the GNU Lesser General Public
16
# License along with this library; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
echo "Usage: lxc-wait --name=NAME --state=STATE"
26
echo "lxc-wait waits for NAME container state to reach STATE"
29
echo " -n, --name=NAME NAME for name of the container"
30
echo " -s, --state=STATE ORed states to wait for"
31
echo " STOPPED, STARTING, RUNNING, STOPPING,"
32
echo " ABORTING, FREEZING, FROZEN"
37
valid_states=("STOPPED" "STARTING" "RUNNING" "STOPPING"
38
"ABORTING" "FREEZING" "FROZEN" "THAWED" "MAX_STATE")
42
local list=`lxc-ls -1`
46
if [ "$c" = "$name" ]; then
57
for((i=0;i<${#valid_states[@]};i++)); do
58
if [ "$s" = "${valid_states[$i]}" ]; then
73
v=$(verify_state "$s")
74
if [ $v = "bad" ]; then
89
if [ "$state" = "$s" ]; then
97
longoptions='help,name:,states:'
99
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
105
eval set -- "$getopt"
136
if [ -z "$lxc_name" ]; then
137
echo "no container name specified"
142
if [ "$(id -u)" != "0" ]; then
143
echo "This command has to be run as root"
147
type lxc-info > /dev/null || { echo "lxc-info not found."; exit 1; }
149
v=$(container_exists $lxc_name)
150
if [ "$v" = "no" ]; then
151
echo "Container $lxc_name does not exist"
154
states2="`echo $states | sed -e 's/|/ /g'`"
155
v=$(verify_states "${states2}")
156
if [ "$v" = "bad" ]; then
157
echo "invalid state $badstate in provided set"
163
o=`lxc-info -s -n $lxc_name`
164
s=`echo $o | awk '{ print $2 }'`
165
if [ $(state_is_in "$s" "${states2}") = "yes" ]; then