mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-15 04:09:46 +00:00
make help consistent for other scripts
Display help information in a consistent format. Print error messages and help information to stderr. Prefix error messages with the name of the script (for easier debugging as part of larger scripts). Allow help information to be printed as a non-root user. Fix file mode for lxc-checkconfig.in. Signed-off-by: David Ward <david.ward@ll.mit.edu> Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com>
This commit is contained in:
parent
8edcbf3366
commit
2775bb4c5a
15
src/lxc/lxc-checkconfig.in
Executable file → Normal file
15
src/lxc/lxc-checkconfig.in
Executable file → Normal file
@ -32,7 +32,7 @@ is_enabled() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if [ ! -f $CONFIG ]; then
|
if [ ! -f $CONFIG ]; then
|
||||||
echo "Kernel config $CONFIG not found, looking in other places..."
|
echo "Kernel configuration not found at $CONFIG; searching..."
|
||||||
KVER="`uname -r`"
|
KVER="`uname -r`"
|
||||||
HEADERS_CONFIG="/lib/modules/$KVER/build/.config"
|
HEADERS_CONFIG="/lib/modules/$KVER/build/.config"
|
||||||
BOOT_CONFIG="/boot/config-$KVER"
|
BOOT_CONFIG="/boot/config-$KVER"
|
||||||
@ -40,15 +40,14 @@ if [ ! -f $CONFIG ]; then
|
|||||||
[ -f "${BOOT_CONFIG}" ] && CONFIG=${BOOT_CONFIG}
|
[ -f "${BOOT_CONFIG}" ] && CONFIG=${BOOT_CONFIG}
|
||||||
GREP=grep
|
GREP=grep
|
||||||
if [ ! -f $CONFIG ]; then
|
if [ ! -f $CONFIG ]; then
|
||||||
echo
|
echo "$(basename $0): unable to retrieve kernel configuration" >&2
|
||||||
echo "The kernel configuration can not be retrieved."
|
echo >&2
|
||||||
echo "Please recompile with IKCONFIG_PROC, or"
|
echo "Try recompiling with IKCONFIG_PROC, installing the kernel headers," >&2
|
||||||
echo "install the kernel headers, or specify"
|
echo "or specifying the kernel configuration path with:" >&2
|
||||||
echo "the path to the config file with: CONFIG=<path> lxc-checkconfig"
|
echo " CONFIG=<path> $(basename $0)" >&2
|
||||||
echo
|
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
echo "Found kernel config file $CONFIG"
|
echo "Kernel configuration found at $CONFIG"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -24,22 +24,24 @@
|
|||||||
set -e
|
set -e
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: lxc-clone -o <orig> -n <new> [-s] [-h] [-L fssize] [-v vgname] [-p lxc_lv_prefix] [-t fstype]"
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
usage
|
usage
|
||||||
echo
|
echo >&2
|
||||||
echo "creates a lxc system object."
|
echo "Clone an existing container on the system." >&2
|
||||||
echo
|
echo >&2
|
||||||
echo "Options:"
|
echo "Options:" >&2
|
||||||
echo "orig : name of the original container"
|
echo " -o ORIG_NAME specify the name of the original container" >&2
|
||||||
echo "new : name of the new container"
|
echo " -n NEW_NAME specify the name of the new container" >&2
|
||||||
echo "-s : make the new rootfs a snapshot of the original"
|
echo " -s make the new rootfs a snapshot of the original" >&2
|
||||||
echo "fssize : size if creating a new fs. By default, 2G"
|
echo " -L FS_SIZE specify the new filesystem size (default: 2G)" >&2
|
||||||
echo "vgname : lvm volume group name, lxc by default"
|
echo " -v VG_NAME specify the new LVM volume group name (default: lxc)" >&2
|
||||||
echo "lvprefix : lvm volume name prefix, none by default, e.g. --lvprefix=lxc_ then new lxc lv name will be lxc_newname"
|
echo " -p LV_PREFIX add a prefix to new LVM logical volume names" >&2
|
||||||
echo "fstype : new container file system type, ext3 by default (only works for non-snapshot lvm)"
|
echo " -t FS_TYPE specify the new filesystem type (default: ext3;" >&2
|
||||||
|
echo " only works for non-snapshot LVM)" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
shortoptions='ho:n:sL:v:p:t:'
|
shortoptions='ho:n:sL:v:p:t:'
|
||||||
@ -102,7 +104,6 @@ while true; do
|
|||||||
break
|
break
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo $1
|
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
@ -110,44 +111,39 @@ while true; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$lxc_path" ]; then
|
if [ -z "$lxc_path" ]; then
|
||||||
echo "no configuration path defined !"
|
echo "$(basename $0): no configuration path defined" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -r $lxc_path ]; then
|
if [ ! -r $lxc_path ]; then
|
||||||
echo "configuration path '$lxc_path' not found"
|
echo "$(basename $0): configuration path '$lxc_path' not found" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$lxc_orig" ]; then
|
if [ -z "$lxc_orig" ]; then
|
||||||
echo "no original container name specified"
|
echo "$(basename $0): no original container name specified" >&2
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$lxc_new" ]; then
|
if [ -z "$lxc_new" ]; then
|
||||||
echo "no new container name specified"
|
echo "$(basename $0): no new container name specified" >&2
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
echo "This command has to be run as root"
|
echo "$(basename $0): must be run as root" >&2
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ ! -r $lxc_path ]; then
|
|
||||||
echo "no configuration path defined !"
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -d "$lxc_path/$lxc_orig" ]; then
|
if [ ! -d "$lxc_path/$lxc_orig" ]; then
|
||||||
echo "'$lxc_orig' does not exist"
|
echo "$(basename $0): '$lxc_orig' does not exist" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d "$lxc_path/$lxc_new" ]; then
|
if [ -d "$lxc_path/$lxc_new" ]; then
|
||||||
echo "'$lxc_new' already exists"
|
echo "$(basename $0): '$lxc_new' already exists" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -166,7 +162,7 @@ cleanup() {
|
|||||||
if [ $frozen -eq 1 ]; then
|
if [ $frozen -eq 1 ]; then
|
||||||
lxc-unfreeze -n $lxc_orig
|
lxc-unfreeze -n $lxc_orig
|
||||||
fi
|
fi
|
||||||
echo aborted
|
echo "$(basename $0): aborted" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
trap cleanup SIGHUP SIGINT SIGTERM
|
trap cleanup SIGHUP SIGINT SIGTERM
|
||||||
@ -195,8 +191,8 @@ lxc-info -s -n $lxc_orig|grep RUNNING >/dev/null 2>&1 || container_running=False
|
|||||||
sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config
|
sed -i '/lxc.rootfs/d' $lxc_path/$lxc_new/config
|
||||||
oldroot=`grep lxc.rootfs $lxc_path/$lxc_orig/config | awk -F= '{ print $2 '}`
|
oldroot=`grep lxc.rootfs $lxc_path/$lxc_orig/config | awk -F= '{ print $2 '}`
|
||||||
if [ -b $oldroot ]; then
|
if [ -b $oldroot ]; then
|
||||||
type vgscan || { echo "Please install lvm"; false; }
|
type vgscan || { echo "$(basename $0): lvm is not installed" >&2; false; }
|
||||||
lvdisplay $oldroot > /dev/null 2>&1 || { echo "non-lvm blockdev cloning not supported"; false; }
|
lvdisplay $oldroot > /dev/null 2>&1 || { echo "$(basename $0): non-lvm blockdev cloning is not supported" >&2; false; }
|
||||||
lvm=TRUE
|
lvm=TRUE
|
||||||
# ok, create a snapshot of the lvm device
|
# ok, create a snapshot of the lvm device
|
||||||
if [ $container_running = "True" ]; then
|
if [ $container_running = "True" ]; then
|
||||||
@ -211,16 +207,16 @@ if [ -b $oldroot ]; then
|
|||||||
if [ $snapshot = "no" ]; then
|
if [ $snapshot = "no" ]; then
|
||||||
#mount snapshot
|
#mount snapshot
|
||||||
mkdir -p ${rootfs}_snapshot
|
mkdir -p ${rootfs}_snapshot
|
||||||
mount /dev/$lxc_vg/${lxc_lv_prefix}${lxc_new}_snapshot ${rootfs}_snapshot || { echo "failed to mount new rootfs_snapshot"; false; }
|
mount /dev/$lxc_vg/${lxc_lv_prefix}${lxc_new}_snapshot ${rootfs}_snapshot || { echo "$(basename $0): failed to mount new rootfs_snapshot" >&2; false; }
|
||||||
#create a new lv
|
#create a new lv
|
||||||
lvcreate -L $lxc_size $lxc_vg -n ${lxc_lv_prefix}$lxc_new
|
lvcreate -L $lxc_size $lxc_vg -n ${lxc_lv_prefix}$lxc_new
|
||||||
echo "lxc.rootfs = /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new" >> $lxc_path/$lxc_new/config
|
echo "lxc.rootfs = /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new" >> $lxc_path/$lxc_new/config
|
||||||
# and mount it so we can tweak it
|
# and mount it so we can tweak it
|
||||||
mkdir -p $lxc_path/$lxc_new/rootfs
|
mkdir -p $lxc_path/$lxc_new/rootfs
|
||||||
mkfs -t $fstype /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new
|
mkfs -t $fstype /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new
|
||||||
mount /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new $rootfs || { echo "failed to mount new rootfs"; false; }
|
mount /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new $rootfs || { echo "$(basename $0): failed to mount new rootfs" >&2; false; }
|
||||||
mounted=1
|
mounted=1
|
||||||
rsync -ax ${rootfs}_snapshot/ ${rootfs}/ || { echo "copy of data to new lv failed"; false; }
|
rsync -ax ${rootfs}_snapshot/ ${rootfs}/ || { echo "$(basename $0): copying data to new lv failed" >&2; false; }
|
||||||
umount ${rootfs}_snapshot
|
umount ${rootfs}_snapshot
|
||||||
rmdir ${rootfs}_snapshot
|
rmdir ${rootfs}_snapshot
|
||||||
lvremove -f $lxc_vg/${lxc_lv_prefix}${lxc_new}_snapshot
|
lvremove -f $lxc_vg/${lxc_lv_prefix}${lxc_new}_snapshot
|
||||||
@ -229,18 +225,18 @@ if [ -b $oldroot ]; then
|
|||||||
echo "lxc.rootfs = /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new" >> $lxc_path/$lxc_new/config
|
echo "lxc.rootfs = /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new" >> $lxc_path/$lxc_new/config
|
||||||
# and mount it so we can tweak it
|
# and mount it so we can tweak it
|
||||||
mkdir -p $lxc_path/$lxc_new/rootfs
|
mkdir -p $lxc_path/$lxc_new/rootfs
|
||||||
mount /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new $rootfs || { echo "failed to mount new rootfs"; false; }
|
mount /dev/$lxc_vg/${lxc_lv_prefix}$lxc_new $rootfs || { echo "$(basename $0): failed to mount new rootfs" >&2; false; }
|
||||||
mounted=1
|
mounted=1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif out=$(btrfs subvolume list "$lxc_path/$lxc_orig/rootfs" 2>&1); then
|
elif out=$(btrfs subvolume list "$lxc_path/$lxc_orig/rootfs" 2>&1); then
|
||||||
|
|
||||||
out=$(btrfs subvolume snapshot "$lxc_path/$lxc_orig/rootfs" "$rootfs" 2>&1) || { echo "failed btrfs snapshot"; false; }
|
out=$(btrfs subvolume snapshot "$lxc_path/$lxc_orig/rootfs" "$rootfs" 2>&1) || { echo "$(basename $0): btrfs snapshot failed" >&2; false; }
|
||||||
echo "lxc.rootfs = $rootfs" >> "$lxc_path/$lxc_new/config"
|
echo "lxc.rootfs = $rootfs" >> "$lxc_path/$lxc_new/config"
|
||||||
|
|
||||||
else
|
else
|
||||||
if [ $snapshot = "yes" ]; then
|
if [ $snapshot = "yes" ]; then
|
||||||
echo "Can't snapshot a directory"
|
echo "$(basename $0): cannot snapshot a directory" >&2
|
||||||
cleanup
|
cleanup
|
||||||
fi
|
fi
|
||||||
if [ $container_running = "True" ]; then
|
if [ $container_running = "True" ]; then
|
||||||
|
@ -21,44 +21,41 @@
|
|||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: lxc-create -n <name> [-f configuration] [-t template] [-h] [fsopts] -- [template_options]"
|
echo "usage: $(basename $0) -n NAME [-f CONFIG_FILE] [-t TEMPLATE] [FS_OPTIONS] --" >&2
|
||||||
echo " fsopts: -B none"
|
echo " [TEMPLATE_OPTIONS]" >&2
|
||||||
echo " fsopts: -B lvm [--lvname lvname] [--vgname vgname] [--fstype fstype] [--fssize fssize]"
|
echo >&2
|
||||||
echo " fsopts: -B btrfs"
|
echo "where FS_OPTIONS is one of:" >&2
|
||||||
echo " flag is not necessary, if possible btrfs support will be used"
|
echo " -B none" >&2
|
||||||
# echo " fsopts: -B union [--uniontype overlayfs]"
|
echo " -B lvm [--lvname LV_NAME] [--vgname VG_NAME] [--fstype FS_TYPE]" >&2
|
||||||
# echo " fsopts: -B loop [--fstype fstype] [--fssize fssize]"
|
echo " [--fssize FS_SIZE]" >&2
|
||||||
# echo " fsopts: -B qemu-nbd [--type qed|qcow2|raw] [--fstype fstype] [--fssize fssize] # Qemu qed disk format"
|
echo " -B btrfs" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
help() {
|
help() {
|
||||||
usage
|
usage
|
||||||
echo
|
echo >&2
|
||||||
echo "creates a lxc system object."
|
echo "Create a new container on the system." >&2
|
||||||
echo
|
echo >&2
|
||||||
echo "Options:"
|
echo "Options:" >&2
|
||||||
echo "name : name of the container"
|
echo " -n NAME specify the name of the container" >&2
|
||||||
echo "configuration: lxc configuration"
|
echo " -f CONFIG_FILE use an existing configuration file" >&2
|
||||||
echo "template : lxc-template is an accessible template script"
|
echo " -t TEMPLATE use an accessible template script" >&2
|
||||||
echo
|
echo " -B BACKING_STORE alter the container backing store (default: none)" >&2
|
||||||
echo "The container backing store can be altered using '-B'. By default it"
|
echo " --lvname LV_NAME specify the LVM logical volume name" >&2
|
||||||
echo "is 'none', which is a simple directory tree under /var/lib/lxc/<name>/rootfs"
|
echo " (default: container name)" >&2
|
||||||
echo "Otherwise, the following option values may be relevant:"
|
echo " --vgname VG_NAME specify the LVM volume group name (default: lxc)" >&2
|
||||||
echo "lvname : [for -lvm] name of lv in which to create lv,"
|
echo " --fstype FS_TYPE specify the filesystem type (default: ext4)" >&2
|
||||||
echo " container-name by default"
|
echo " --fssize FS_SIZE specify the filesystem size (default: 500M)" >&2
|
||||||
echo "vgname : [for -lvm] name of vg in which to create lv, 'lxc' by default"
|
echo >&2
|
||||||
echo "fstype : name of filesystem to create, ext4 by default"
|
|
||||||
echo "fssize : size of filesystem to create, 500M by default"
|
|
||||||
echo
|
|
||||||
if [ -z $lxc_template ]; then
|
if [ -z $lxc_template ]; then
|
||||||
echo "for template-specific help, specify a template, for instance:"
|
echo "To see template-specific options, specify a template. For example:" >&2
|
||||||
echo "lxc-create -t ubuntu -h"
|
echo " $(basename $0) -t ubuntu -h" >&2
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
type ${templatedir}/lxc-$lxc_template >/dev/null
|
type ${templatedir}/lxc-$lxc_template 2>/dev/null
|
||||||
echo
|
|
||||||
echo "template-specific help follows: (these options follow '--')"
|
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
|
echo >&2
|
||||||
|
echo "Template-specific options (TEMPLATE_OPTIONS):" >&2
|
||||||
${templatedir}/lxc-$lxc_template -h
|
${templatedir}/lxc-$lxc_template -h
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -133,7 +130,6 @@ while true; do
|
|||||||
shift
|
shift
|
||||||
break;;
|
break;;
|
||||||
*)
|
*)
|
||||||
echo $1
|
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
@ -141,17 +137,17 @@ while true; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$lxc_path" ]; then
|
if [ -z "$lxc_path" ]; then
|
||||||
echo "no configuration path defined !"
|
echo "$(basename $0): no configuration path defined" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -r $lxc_path ]; then
|
if [ ! -r $lxc_path ]; then
|
||||||
echo "configuration path '$lxc_path' not found"
|
echo "$(basename $0): configuration path '$lxc_path' not found" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$lxc_name" ]; then
|
if [ -z "$lxc_name" ]; then
|
||||||
echo "no container name specified"
|
echo "$(basename $0): no container name specified" >&2
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -161,20 +157,20 @@ if [ -z "$lvname" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
echo "This command has to be run as root"
|
echo "$(basename $0): must be run as root" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$backingstore" in
|
case "$backingstore" in
|
||||||
lvm|none|btrfs|_unset) :;;
|
lvm|none|btrfs|_unset) :;;
|
||||||
*) echo "'$backingstore' is not known ('none', 'lvm', 'btrfs')"
|
*) echo "$(basename $0): '$backingstore' is not known (try 'none', 'lvm', 'btrfs')" >&2
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
if [ -d "$lxc_path/$lxc_name" ]; then
|
if [ -d "$lxc_path/$lxc_name" ]; then
|
||||||
echo "'$lxc_name' already exists"
|
echo "$(basename $0): '$lxc_name' already exists" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -187,7 +183,7 @@ if [ "$backingstore" = "_unset" -o "$backingstore" = "btrfs" ]; then
|
|||||||
backingstore="btrfs"
|
backingstore="btrfs"
|
||||||
else
|
else
|
||||||
if [ "$backingstore" = "btrfs" ]; then
|
if [ "$backingstore" = "btrfs" ]; then
|
||||||
echo "missing 'btrfs' command or $lxc_path is not btrfs";
|
echo "$(basename $0): missing 'btrfs' command or $lxc_path is not btrfs" >&2
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
backingstore="none"
|
backingstore="none"
|
||||||
@ -197,34 +193,32 @@ fi
|
|||||||
if [ $backingstore = "lvm" ]; then
|
if [ $backingstore = "lvm" ]; then
|
||||||
which vgscan > /dev/null
|
which vgscan > /dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "vgscan not found. Please install lvm2 package"
|
echo "$(basename $0): vgscan not found (is lvm2 installed?)" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
grep -q "\<$fstype\>" /proc/filesystems
|
grep -q "\<$fstype\>" /proc/filesystems
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "$fstype is not listed in /proc/filesystems"
|
echo "$(basename $0): $fstype is not listed in /proc/filesystems" >&2
|
||||||
usage
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vgscan | grep -q "Found volume group \"$vgname\""
|
vgscan | grep -q "Found volume group \"$vgname\""
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "Could not find volume group \"$vgname\""
|
echo "$(basename $0): could not find volume group \"$vgname\"" >&2
|
||||||
usage
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
rootdev=/dev/$vgname/$lvname
|
rootdev=/dev/$vgname/$lvname
|
||||||
lvdisplay $rootdev > /dev/null 2>&1
|
lvdisplay $rootdev > /dev/null 2>&1
|
||||||
if [ $? -eq 0 ]; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "backing store already exists: $rootdev"
|
echo "$(basename $0): backing store already exists: $rootdev" >&2
|
||||||
echo "please delete it (using \"lvremove $rootdev\") and try again"
|
echo "please delete it (using \"lvremove $rootdev\") and try again" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
elif [ "$backingstore" = "btrfs" ]; then
|
elif [ "$backingstore" = "btrfs" ]; then
|
||||||
mkdir "$lxc_path/$lxc_name"
|
mkdir "$lxc_path/$lxc_name"
|
||||||
if ! out=$(btrfs subvolume create "$rootfs" 2>&1); then
|
if ! out=$(btrfs subvolume create "$rootfs" 2>&1); then
|
||||||
echo "failed to create subvolume in $rootfs: $out";
|
echo "$(basename $0): failed to create subvolume in $rootfs: $out" >&2
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@ -235,7 +229,7 @@ cleanup() {
|
|||||||
lvremove -f $rootdev
|
lvremove -f $rootdev
|
||||||
fi
|
fi
|
||||||
${bindir}/lxc-destroy -n $lxc_name
|
${bindir}/lxc-destroy -n $lxc_name
|
||||||
echo aborted
|
echo "$(basename $0): aborted" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -247,7 +241,7 @@ if [ -z "$lxc_config" ]; then
|
|||||||
touch $lxc_path/$lxc_name/config
|
touch $lxc_path/$lxc_name/config
|
||||||
else
|
else
|
||||||
if [ ! -r "$lxc_config" ]; then
|
if [ ! -r "$lxc_config" ]; then
|
||||||
echo "'$lxc_config' configuration file not found"
|
echo "$(basename $0): '$lxc_config' configuration file not found" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -265,9 +259,9 @@ fi
|
|||||||
|
|
||||||
if [ ! -z $lxc_template ]; then
|
if [ ! -z $lxc_template ]; then
|
||||||
|
|
||||||
type ${templatedir}/lxc-$lxc_template >/dev/null
|
type ${templatedir}/lxc-$lxc_template 2>/dev/null
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "unknown template '$lxc_template'"
|
echo "$(basename $0): unknown template '$lxc_template'" >&2
|
||||||
cleanup
|
cleanup
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -299,7 +293,7 @@ if [ ! -z $lxc_template ]; then
|
|||||||
|
|
||||||
${templatedir}/lxc-$lxc_template --path=$lxc_path/$lxc_name --name=$lxc_name $*
|
${templatedir}/lxc-$lxc_template --path=$lxc_path/$lxc_name --name=$lxc_name $*
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "failed to execute template '$lxc_template'"
|
echo "$(basename $0): failed to execute template '$lxc_template'" >&2
|
||||||
cleanup
|
cleanup
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -26,24 +26,28 @@
|
|||||||
#
|
#
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
echo "usage: $0 -n <name> [-f]"
|
echo "usage: $(basename $0) -n NAME [-f]" >&2
|
||||||
echo " -f: if a container is running, stop it first. Default is to abort"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
help() {
|
||||||
echo "This command has to be run as root"
|
usage
|
||||||
exit 1
|
echo >&2
|
||||||
fi
|
echo "Remove an existing container on the system." >&2
|
||||||
|
echo >&2
|
||||||
|
echo "Options:" >&2
|
||||||
|
echo " -n NAME specify the name of the container" >&2
|
||||||
|
echo " -f stop the container if it is running (rather than abort)" >&2
|
||||||
|
}
|
||||||
|
|
||||||
shortoptions='n:f'
|
shortoptions='hn:f'
|
||||||
longoptions='name:'
|
longoptions='help,name:'
|
||||||
localstatedir=@LOCALSTATEDIR@
|
localstatedir=@LOCALSTATEDIR@
|
||||||
lxc_path=@LXCPATH@
|
lxc_path=@LXCPATH@
|
||||||
force=0
|
force=0
|
||||||
|
|
||||||
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
|
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
usage $0
|
usage
|
||||||
exit 1;
|
exit 1;
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -51,6 +55,10 @@ eval set -- "$getopt"
|
|||||||
|
|
||||||
while true; do
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
|
-h|--help)
|
||||||
|
help
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
-n|--name)
|
-n|--name)
|
||||||
shift
|
shift
|
||||||
lxc_name=$1
|
lxc_name=$1
|
||||||
@ -64,21 +72,25 @@ while true; do
|
|||||||
shift
|
shift
|
||||||
break;;
|
break;;
|
||||||
*)
|
*)
|
||||||
echo $1
|
usage
|
||||||
usage $0
|
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$lxc_name" ]; then
|
if [ -z "$lxc_name" ]; then
|
||||||
echo "no container name specified"
|
echo "$(basename $0): no container name specified" >&2
|
||||||
usage $0
|
usage $0
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "$(basename $0): must be run as root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ ! -d "$lxc_path/$lxc_name" ]; then
|
if [ ! -d "$lxc_path/$lxc_name" ]; then
|
||||||
echo "'$lxc_name' does not exist"
|
echo "$(basename $0): '$lxc_name' does not exist" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -88,7 +100,7 @@ if [ $? -eq 0 ]; then
|
|||||||
if [ $force -eq 1 ]; then
|
if [ $force -eq 1 ]; then
|
||||||
lxc-stop -n $lxc_name
|
lxc-stop -n $lxc_name
|
||||||
else
|
else
|
||||||
echo "Container $lxc_name is running, aborting the deletion."
|
echo "$(basename $0): '$lxc_name' is running; aborted" >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -37,9 +37,17 @@ LXC_RESTART_CAPS="$LXC_START_CAPS,cap_mknod"
|
|||||||
LXC_CHECKPOINT_CAPS="$LXC_COMMON_CAPS,cap_sys_ptrace,cap_mknod"
|
LXC_CHECKPOINT_CAPS="$LXC_COMMON_CAPS,cap_sys_ptrace,cap_mknod"
|
||||||
LXC_DROP_CAPS=""
|
LXC_DROP_CAPS=""
|
||||||
|
|
||||||
usage()
|
usage() {
|
||||||
{
|
echo "usage: $(basename $0) [-d]" >&2
|
||||||
echo "lxc-setcap [-d] : set or remove capabilities on the lxc tools"
|
}
|
||||||
|
|
||||||
|
help() {
|
||||||
|
usage
|
||||||
|
echo >&2
|
||||||
|
echo "Set or drop file capabilities on the lxc tools." >&2
|
||||||
|
echo >&2
|
||||||
|
echo "Options:" >&2
|
||||||
|
echo " -d drop file capabilities" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
lxc_setcaps()
|
lxc_setcaps()
|
||||||
@ -69,32 +77,31 @@ lxc_dropcaps()
|
|||||||
setcap -r @BINDIR@/lxc-netstat
|
setcap -r @BINDIR@/lxc-netstat
|
||||||
setcap -r @BINDIR@/lxc-checkpoint
|
setcap -r @BINDIR@/lxc-checkpoint
|
||||||
setcap -r @LXCINITDIR@/lxc-init
|
setcap -r @LXCINITDIR@/lxc-init
|
||||||
|
|
||||||
chmod 0755 @LXCPATH@
|
chmod 0755 @LXCPATH@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shortoptions='hd'
|
||||||
|
longoptions='help'
|
||||||
libdir=@LIBDIR@
|
libdir=@LIBDIR@
|
||||||
localstatedir=@LOCALSTATEDIR@
|
localstatedir=@LOCALSTATEDIR@
|
||||||
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
|
||||||
echo "You have to be root to run this script"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -- $(getopt dh "$@")
|
eval set -- "$getopt"
|
||||||
|
|
||||||
for i in "$@"; do
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-d)
|
-d)
|
||||||
LXC_DROP_CAPS="yes"
|
LXC_DROP_CAPS="yes"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-h)
|
-h|--help)
|
||||||
usage
|
help
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
@ -108,6 +115,11 @@ for i in "$@"; do
|
|||||||
esac
|
esac
|
||||||
done;
|
done;
|
||||||
|
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "$(basename $0): must be run as root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$LXC_DROP_CAPS" ]; then
|
if [ -z "$LXC_DROP_CAPS" ]; then
|
||||||
lxc_setcaps
|
lxc_setcaps
|
||||||
else
|
else
|
||||||
|
@ -25,9 +25,17 @@
|
|||||||
# When the capabilities are set, a non root user can manage the containers.
|
# When the capabilities are set, a non root user can manage the containers.
|
||||||
#
|
#
|
||||||
|
|
||||||
usage()
|
usage() {
|
||||||
{
|
echo "usage: $(basename $0) [-d]" >&2
|
||||||
echo "lxc-setuid [-d] : set or remove setuid on the lxc tools"
|
}
|
||||||
|
|
||||||
|
help() {
|
||||||
|
usage
|
||||||
|
echo >&2
|
||||||
|
echo "Set or drop the setuid attribute on the lxc tools." >&2
|
||||||
|
echo >&2
|
||||||
|
echo "Options:" >&2
|
||||||
|
echo " -d drop the setuid attribute" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
setuid()
|
setuid()
|
||||||
@ -70,29 +78,27 @@ lxc_dropuid()
|
|||||||
chmod 0755 @LXCPATH@
|
chmod 0755 @LXCPATH@
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shortoptions='hd'
|
||||||
|
longoptions='help'
|
||||||
libdir=@LIBDIR@
|
libdir=@LIBDIR@
|
||||||
localstatedir=@LOCALSTATEDIR@
|
localstatedir=@LOCALSTATEDIR@
|
||||||
|
|
||||||
if [ "$(id -u)" != "0" ]; then
|
getopt=$(getopt -o $shortoptions --longoptions $longoptions -- "$@")
|
||||||
echo "You have to be root to run this script"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ $? != 0 ]; then
|
if [ $? != 0 ]; then
|
||||||
usage
|
usage
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
set -- $(getopt dh "$@")
|
eval set -- "$getopt"
|
||||||
|
|
||||||
for i in "$@"; do
|
while true; do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
-d)
|
-d)
|
||||||
LXC_DROP_CAPS="yes"
|
LXC_DROP_CAPS="yes"
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
-h)
|
-h|--help)
|
||||||
usage
|
help
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
--)
|
--)
|
||||||
@ -106,6 +112,11 @@ for i in "$@"; do
|
|||||||
esac
|
esac
|
||||||
done;
|
done;
|
||||||
|
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "$(basename $0): must be run as root" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [ -z "$LXC_DROP_CAPS" ]; then
|
if [ -z "$LXC_DROP_CAPS" ]; then
|
||||||
lxc_setuid
|
lxc_setuid
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user