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: Natanael Copa <ncopa@alpinelinux.org>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
rootfs=`echo $oldroot |sed "s/$lxc_orig/$lxc_new/"`
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
if [ -b $oldroot ]; then
fi
# make sure the container is stopped
-state=`lxc-info -n $lxc_name 2>/dev/null | head -1 |awk '{print $2}'`
-if [ $state != "STOPPED" ]; then
+if ! lxc-info -n $lxc_name --state-is "STOPPED"; then
if [ $force -eq 1 ]; then
lxc-stop -n $lxc_name
lxc-wait -n $lxc_name -s STOPPED
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
fi
fi
exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name --exec "$@"
fi
-lxc-info -n $name 2>&1 | grep -q 'STOPPED'
-if [ $? -eq 0 ]; then
+if lxc-info -n $name --state-is 'STOPPED'; then
echo "$(basename $0): container '$name' is not running" >&2
exit 1
fi
alarmpid=$!
fi
-while [ 1 ]; do
- s=`lxc-info -s -n $lxc_name | awk '{ print $2 }'`
- if [ "$s" = "STOPPED" ]; then
- break;
- fi
+while ! lxc-info -n $lxc_name --state-is STOPPED; do
sleep 1
done