[lxc-devel] [PATCH 3/4] support alternate container path in lxc-clone.in

Harald Dunkel harald.dunkel at aixigo.de
Fri May 3 08:53:42 UTC 2013


---
 src/lxc/lxc-clone.in | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/src/lxc/lxc-clone.in b/src/lxc/lxc-clone.in
index 4c8acb4..8ff9947 100755
--- a/src/lxc/lxc-clone.in
+++ b/src/lxc/lxc-clone.in
@@ -25,7 +25,7 @@ set -e
 
 usage() {
     echo "usage: $(basename $0) -o ORIG_NAME -n NEW_NAME [-s] [-h] [-L FS_SIZE]" >&2
-    echo "        [-v VG_NAME] [-p LV_PREFIX] [-t FS_TYPE]" >&2
+    echo "        [-P LXC_PATH] [-v VG_NAME] [-p LV_PREFIX] [-t FS_TYPE]" >&2
 }
 
 help() {
@@ -38,6 +38,7 @@ help() {
     echo "  -n NEW_NAME    specify the name of the new container" >&2
     echo "  -s             make the new rootfs a snapshot of the original" >&2
     echo "  -L FS_SIZE     specify the new filesystem size (default: same as original)" >&2
+    echo "  -P LXC_PATH    use an alternate container path (default: @LXCPATH@)" >&2
     echo "  -v VG_NAME     specify the new LVM volume group name (default: lxc)" >&2
     echo "  -p LV_PREFIX   add a prefix to new LVM logical volume names" >&2
     echo "  -t FS_TYPE     specify the new filesystem type (default: ext3;" >&2
@@ -83,6 +84,11 @@ while [ $# -gt 0 ]; do
             lxc_size=$1
             shift
             ;;
+        -P|--lxcpath)
+            optarg_check $opt $1
+            lxc_path="$1"
+            shift
+            ;;
         -t|--fstype)
             optarg_check $opt $1
             fstype=$1
@@ -167,9 +173,9 @@ cleanup() {
         fi
         lvremove -f $rootdev || true
     fi
-    ${bindir}/lxc-destroy -n $lxc_new || true
+    ${bindir}/lxc-destroy -n $lxc_new -P "$lxc_path" || true
     if [ $frozen -eq 1 ]; then
-        lxc-unfreeze -n $lxc_orig
+        lxc-unfreeze -n $lxc_orig -P "$lxc_path"
     fi
     echo "$(basename $0): aborted" >&2
     exit 1
@@ -196,7 +202,7 @@ oldroot=`grep lxc.rootfs $lxc_path/$lxc_orig/config | awk -F'[= \t]+' '{ print $
 rootfs=`echo $oldroot |sed "s/$lxc_orig/$lxc_new/"`
 
 container_running=True
-lxc-info -n $lxc_orig --state-is RUNNING || container_running=False
+lxc-info -n $lxc_orig -P "$lxc_path" --state-is RUNNING || container_running=False
 
 sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config
 if [ -b $oldroot ]; then
@@ -205,7 +211,7 @@ if [ -b $oldroot ]; then
     lvm=TRUE
     # ok, create a snapshot of the lvm device
     if [ $container_running = "True" ]; then
-        lxc-freeze -n $lxc_orig
+        lxc-freeze -n $lxc_orig -P "$lxc_path"
         frozen=1
     fi
     if [ $lxc_size = "_unset" ]; then
@@ -219,7 +225,7 @@ if [ -b $oldroot ]; then
     }
 
     if [ $container_running = "True" ]; then
-        lxc-unfreeze -n $lxc_orig
+        lxc-unfreeze -n $lxc_orig -P "$lxc_path"
         frozen=0
     fi
     if [ $snapshot = "no" ]; then
@@ -274,14 +280,14 @@ else
         cleanup
     fi
     if [ $container_running = "True" ]; then
-        lxc-freeze -n $lxc_orig
+        lxc-freeze -n $lxc_orig -P "$lxc_path"
         frozen=1
     fi
     mkdir -p $rootfs/
     rsync -Hax $oldroot/ $rootfs/
     echo "lxc.rootfs = $rootfs" >> $lxc_path/$lxc_new/config
     if [ $container_running = "True" ]; then
-        lxc-unfreeze -n $lxc_orig
+        lxc-unfreeze -n $lxc_orig -P "$lxc_path"
         frozen=0
     fi
 fi
-- 
1.8.1.3





More information about the lxc-devel mailing list