~serge-hallyn/ubuntu/natty/lxc/lxc-clone

« back to all changes in this revision

Viewing changes to src/lxc/lxc-destroy.in

  • Committer: Serge Hallyn
  • Date: 2011-04-12 14:41:35 UTC
  • mfrom: (12.1.1 lxc-newclone)
  • Revision ID: serge.hallyn@canonical.com-20110412144135-rbirz8tvfxhz5yat
Tags: 0.7.4-0ubuntu8clone1
* re-merge in lxc-clone (see 0.7.4-0ubuntu4clone1 entry)
* Add lxc-clone to clone containers.  Also modify
  lxc-destroy to take optional argument requesting attempt to
  lvremove the rootfs (which is then a block device).

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
#
27
27
 
28
28
usage() {
29
 
    echo "usage: $0 -n <name>"
 
29
    echo "usage: $0 -n <name> [-l]"
 
30
    echo "       if -l is specified, attempt to lvremove the rootfs device"
30
31
}
31
32
 
32
33
if [ "$(id -u)" != "0" ]; then
34
35
   exit 1
35
36
fi
36
37
 
37
 
shortoptions='n:'
38
 
longoptions='name:'
39
 
lxc_path=@LXCPATH@
 
38
shortoptions='n:l'
 
39
longoptions='name:,lvm'
 
40
lxc_path=/var/lib/lxc
40
41
 
41
42
getopt=$(getopt -o $shortoptions --longoptions  $longoptions -- "$@")
42
43
if [ $? != 0 ]; then
46
47
 
47
48
eval set -- "$getopt"
48
49
 
 
50
lvremove=0
 
51
 
49
52
while true; do
50
53
        case "$1" in
51
54
            -n|--name)
53
56
                lxc_name=$1
54
57
                shift
55
58
                ;;
 
59
            -l|--lvm)
 
60
                shift
 
61
                lvremove=1
 
62
                ;;
56
63
            --)
57
64
                shift
58
65
                break;;
75
82
    exit 1
76
83
fi
77
84
 
 
85
if [ $lvremove -eq 1 ]; then
 
86
    rootdev=`grep lxc.rootfs $lxc_path/$lxc_name/config | awk -F= '{ print $2 '}`
 
87
    # only makes sense if it is a blockdev or a symlink to one
 
88
    if [ -b $rootdev -o -h $rootdev ]; then
 
89
            lvremove $rootdev
 
90
    fi
 
91
fi
 
92
 
78
93
# recursively remove the container to remove old container configuration
79
94
rm -rf --preserve-root $lxc_path/$lxc_name