Commit 7265dc43 by Natanael Copa Committed by Stéphane Graber

cleanup: use lxc-info --state-is

We now have the possibility to test for a given state. Use this feature instead of parsing output with grep or awk Signed-off-by: 's avatarNatanael Copa <ncopa@alpinelinux.org> Acked-by: 's avatarStéphane Graber <stgraber@ubuntu.com>
parent 32e86901
...@@ -193,7 +193,7 @@ oldroot=`grep lxc.rootfs $lxc_path/$lxc_orig/config | awk -F'[= \t]+' '{ print $ ...@@ -193,7 +193,7 @@ oldroot=`grep lxc.rootfs $lxc_path/$lxc_orig/config | awk -F'[= \t]+' '{ print $
rootfs=`echo $oldroot |sed "s/$lxc_orig/$lxc_new/"` rootfs=`echo $oldroot |sed "s/$lxc_orig/$lxc_new/"`
container_running=True container_running=True
lxc-info -s -n $lxc_orig|grep RUNNING >/dev/null 2>&1 || container_running=False lxc-info -n $lxc_orig --state-is RUNNING || container_running=False
sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config
if [ -b $oldroot ]; then if [ -b $oldroot ]; then
......
...@@ -104,13 +104,12 @@ if [ ! -d "$lxc_path/$lxc_name" ]; then ...@@ -104,13 +104,12 @@ if [ ! -d "$lxc_path/$lxc_name" ]; then
fi fi
# make sure the container is stopped # make sure the container is stopped
state=`lxc-info -n $lxc_name 2>/dev/null | head -1 |awk '{print $2}'` if ! lxc-info -n $lxc_name --state-is "STOPPED"; then
if [ $state != "STOPPED" ]; then
if [ $force -eq 1 ]; then if [ $force -eq 1 ]; then
lxc-stop -n $lxc_name lxc-stop -n $lxc_name
lxc-wait -n $lxc_name -s STOPPED lxc-wait -n $lxc_name -s STOPPED
else else
echo "$(basename $0): '$lxc_name' is $state; aborted" >&2 echo "$(basename $0): '$lxc_name' $(lxc-info -n $lxc_name -s); aborted" >&2
exit 1 exit 1
fi fi
fi fi
......
...@@ -96,8 +96,7 @@ if [ -z "$exec" ]; then ...@@ -96,8 +96,7 @@ if [ -z "$exec" ]; then
exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name --exec "$@" exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name --exec "$@"
fi fi
lxc-info -n $name 2>&1 | grep -q 'STOPPED' if lxc-info -n $name --state-is 'STOPPED'; then
if [ $? -eq 0 ]; then
echo "$(basename $0): container '$name' is not running" >&2 echo "$(basename $0): container '$name' is not running" >&2
exit 1 exit 1
fi fi
......
...@@ -130,11 +130,7 @@ if [ $timeout != "-1" ]; then ...@@ -130,11 +130,7 @@ if [ $timeout != "-1" ]; then
alarmpid=$! alarmpid=$!
fi fi
while [ 1 ]; do while ! lxc-info -n $lxc_name --state-is STOPPED; do
s=`lxc-info -s -n $lxc_name | awk '{ print $2 }'`
if [ "$s" = "STOPPED" ]; then
break;
fi
sleep 1 sleep 1
done done
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment