On 04/29/13 14:23, Daniel Baumann wrote: > On 04/29/2013 02:17 PM, Harald Dunkel wrote: >> The lxc* scripts don't. > > patches welcome. >
See attachment. I tried to match your style on the scripts in debian. I have forwarded the patches for -P in upstream's scripts also to the lxc-devel mailing list. Upstream refused the patch for lxc-clone, because this script is going to be replaced by a binary executable, but the rest has been accepted, afaics. Hope this helps. Please mail if there is something weird and should be changed/improved. Many thanx Harri
diff -urN lxc-0.9.0.orig/debian/local/lxc-backup lxc-0.9.0/debian/local/lxc-backup --- lxc-0.9.0.orig/debian/local/lxc-backup 2013-04-19 14:23:08.000000000 +0200 +++ lxc-0.9.0/debian/local/lxc-backup 2013-04-30 08:24:05.000000000 +0200 @@ -12,14 +12,51 @@ . /usr/share/lxc/lxc.functions _LXC_DIRECTORY="${lxc_path}" -_CONTAINER="${1}" -if [ -n "${_CONTAINER}" ] +_OPTIONS="$(getopt -o n:,P: -l name:,lxcpath: -- "${@}")" + +if [ "${?}" -ne 0 ] +then + echo "Usage: $(basename ${0}) -n|--name CONTAINER [-P|--lxcpath DIRECTORY]" >&2 + exit 1 +fi + +eval set -- "${_OPTIONS}" + +while true +do + case "${1}" in + -n|--name) + _CONTAINER="${2}" + shift 2 + ;; + + -P|--lxcpath) + _LXC_DIRECTORY="${2}" + shift 2 + ;; + + --) + shift + break + ;; + + *) + echo "E: $(basename ${0}): internal error ${0}" >&2 + exit 1 + ;; + esac +done + +if [ -z "${_CONTAINER}" ] +then + echo "E: $(basename ${0}): missing container name, use --name option" >&2 + exit 1 +fi + +if [ ! -d "${_LXC_DIRECTORY}" ] then - shift -else -# echo "Usage: ${0} CONTAINER [BACKUP_NUMBER]" - echo "Usage: ${0} CONTAINER" + echo "E: ${_LXC_DIRECTORY}: no such directory." >&2 exit 1 fi @@ -35,13 +72,13 @@ exit 1 fi -if ! lxc-info -n ${_CONTAINER} 2>&1 | grep -qs "STOPPED" +if ! lxc-info -n ${_CONTAINER} -P "${_LXC_DIRECTORY}" 2>&1 | grep -qs "STOPPED" then echo "E: ${_CONTAINER} - not stopped" >&2 exit 1 fi -if [ -e "${_LXC_DIRECTORY}/${_CONTAINER}/rootfs" ] +if [ -d "${_LXC_DIRECTORY}/${_CONTAINER}/rootfs" ] then # if [ -n "${2}" ] # then diff -urN lxc-0.9.0.orig/debian/local/lxc-halt lxc-0.9.0/debian/local/lxc-halt --- lxc-0.9.0.orig/debian/local/lxc-halt 2013-04-19 14:23:08.000000000 +0200 +++ lxc-0.9.0/debian/local/lxc-halt 2013-04-30 10:18:41.000000000 +0200 @@ -13,11 +13,11 @@ _LXC_DIRECTORY="${lxc_path}" -_OPTIONS="$(getopt -o n: -l name: -- "${@}")" +_OPTIONS="$(getopt -o n:,P: -l name:,lxcpath: -- "${@}")" if [ "${?}" -ne 0 ] then - echo "Usage: $(basename ${0}) -n|--name CONTAINER" >&2 + echo "Usage: $(basename ${0}) -n|--name CONTAINER [-P|--lxcpath DIRECTORY]" >&2 exit 1 fi @@ -31,6 +31,11 @@ shift 2 ;; + -P|--lxcpath) + _LXC_DIRECTORY="${2}" + shift 2 + ;; + --) shift break @@ -49,7 +54,13 @@ exit 1 fi -if lxc-info -n ${_CONTAINER} 2>&1 | grep -qs "STOPPED" +if [ ! -d "${_LXC_DIRECTORY}" ] +then + echo "E: ${_LXC_DIRECTORY}: no such directory." >&2 + exit 1 +fi + +if lxc-info -n ${_CONTAINER} -P "${_LXC_DIRECTORY}" 2>&1 | grep -qs "STOPPED" then echo "P: ${_CONTAINER} - already stopped" exit 0 @@ -57,7 +68,7 @@ if [ -e "${_LXC_DIRECTORY}/${_CONTAINER}/rootfs" ] then - chroot "${_LXC_DIRECTORY}/{_CONTAINER}/rootfs" telinit 0 + chroot "${_LXC_DIRECTORY}/${_CONTAINER}/rootfs" telinit 0 else echo "E: ${_LXC_DIRECTORY}/${_CONTAINER}/rootfs - no such directory" exit 1 diff -urN lxc-0.9.0.orig/debian/local/lxc-list lxc-0.9.0/debian/local/lxc-list --- lxc-0.9.0.orig/debian/local/lxc-list 2013-04-19 14:23:08.000000000 +0200 +++ lxc-0.9.0/debian/local/lxc-list 2013-04-29 16:29:54.000000000 +0200 @@ -9,6 +9,40 @@ set -e +. /usr/share/lxc/lxc.functions + +_LXC_DIRECTORY="${lxc_path}" + +_OPTIONS="$(getopt -o P: -l lxcpath: -- "${@}")" + +if [ "${?}" -ne 0 ] +then + echo "Usage: $(basename ${0}) [-P|--lxcpath DIRECTORY]" >&2 + exit 1 +fi + +eval set -- "${_OPTIONS}" + +while true +do + case "${1}" in + -P|--lxcpath) + _LXC_DIRECTORY="${2}" + shift 2 + ;; + + --) + shift + break + ;; + + *) + echo "E: $(basename ${0}): internal error ${0}" >&2 + exit 1 + ;; + esac +done + if [ ! -x "$(which lxc-info 2>/dev/null)" ] then echo "E: lxc-info - no such file" >&2 @@ -19,9 +53,9 @@ do echo ${_STATUS} - for _CONTAINER in $(lxc-ls) + for _CONTAINER in $(lxc-ls -P "${_LXC_DIRECTORY}") do - if lxc-info -n ${_CONTAINER} 2>&1 | grep -qs "${_STATUS}" + if lxc-info -n ${_CONTAINER} -P "${_LXC_DIRECTORY}" 2>&1 | grep -qs "${_STATUS}" then printf " %-55.50s" "${_CONTAINER}" diff -urN lxc-0.9.0.orig/debian/local/lxc-ls lxc-0.9.0/debian/local/lxc-ls --- lxc-0.9.0.orig/debian/local/lxc-ls 2013-04-19 14:23:08.000000000 +0200 +++ lxc-0.9.0/debian/local/lxc-ls 2013-04-30 08:08:08.000000000 +0200 @@ -13,7 +13,37 @@ _LXC_DIRECTORY="${lxc_path}" -if [ ! -e "${_LXC_DIRECTORY}" ] +_OPTIONS="$(getopt -o P: -l lxcpath: -- "${@}")" + +if [ "${?}" -ne 0 ] +then + echo "Usage: $(basename ${0}) [-P|--lxcpath DIRECTORY]" >&2 + exit 1 +fi + +eval set -- "${_OPTIONS}" + +while true +do + case "${1}" in + -P|--lxcpath) + _LXC_DIRECTORY="${2}" + shift 2 + ;; + + --) + shift + break + ;; + + *) + echo "E: $(basename ${0}): internal error ${0}" >&2 + exit 1 + ;; + esac +done + +if [ ! -d "${_LXC_DIRECTORY}" ] then echo "E: ${_LXC_DIRECTORY}: no such directory." >&2 exit 1 diff -urN lxc-0.9.0.orig/debian/local/lxc-restore lxc-0.9.0/debian/local/lxc-restore --- lxc-0.9.0.orig/debian/local/lxc-restore 2013-04-19 14:23:08.000000000 +0200 +++ lxc-0.9.0/debian/local/lxc-restore 2013-04-30 08:24:05.000000000 +0200 @@ -12,14 +12,51 @@ . /usr/share/lxc/lxc.functions _LXC_DIRECTORY="${lxc_path}" -_CONTAINER="${1}" -if [ -n "${_CONTAINER}" ] +_OPTIONS="$(getopt -o n:,P: -l name:,lxcpath: -- "${@}")" + +if [ "${?}" -ne 0 ] +then + echo "Usage: $(basename ${0}) -n|--name CONTAINER [-P|--lxcpath DIRECTORY]" >&2 + exit 1 +fi + +eval set -- "${_OPTIONS}" + +while true +do + case "${1}" in + -n|--name) + _CONTAINER="${2}" + shift 2 + ;; + + -P|--lxcpath) + _LXC_DIRECTORY="${2}" + shift 2 + ;; + + --) + shift + break + ;; + + *) + echo "E: $(basename ${0}): internal error ${0}" >&2 + exit 1 + ;; + esac +done + +if [ -z "${_CONTAINER}" ] +then + echo "E: $(basename ${0}): missing container name, use --name option" >&2 + exit 1 +fi + +if [ ! -d "${_LXC_DIRECTORY}" ] then - shift -else -# echo "Usage: ${0} CONTAINER [BACKUP_NUMBER]" - echo "Usage: ${0} CONTAINER" + echo "E: ${_LXC_DIRECTORY}: no such directory." >&2 exit 1 fi @@ -35,7 +72,7 @@ exit 1 fi -if ! lxc-info -n ${_CONTAINER} 2>&1 | grep -qs "STOPPED" +if ! lxc-info -n ${_CONTAINER} -P "${_LXC_DIRECTORY}" 2>&1 | grep -qs "STOPPED" then echo "E: ${_CONTAINER} - not stopped" >&2 exit 1 diff -urN lxc-0.9.0.orig/debian/lxc.init lxc-0.9.0/debian/lxc.init --- lxc-0.9.0.orig/debian/lxc.init 2013-04-19 14:23:08.000000000 +0200 +++ lxc-0.9.0/debian/lxc.init 2013-04-30 14:41:53.000000000 +0200 @@ -26,9 +26,9 @@ for _CONFFILE in /etc/default/lxc /etc/default/lxc.d/* do - if [ -e /etc/default/lxc ] + if [ -e ${_CONFFILE} ] then - . /etc/default/lxc || true + . ${_CONFFILE} || true fi done @@ -87,7 +87,7 @@ *) log_progress_msg "${_CONTAINER}" - lxc ${_PROGRAM} ${_CONTAINER} ${_OPTIONS} + lxc-${_PROGRAM} -n ${_CONTAINER} ${_OPTIONS} ;; esac done diff -urN lxc-0.9.0.orig/debian/patches/0008-lxc-shutdown.patch lxc-0.9.0/debian/patches/0008-lxc-shutdown.patch --- lxc-0.9.0.orig/debian/patches/0008-lxc-shutdown.patch 1970-01-01 01:00:00.000000000 +0100 +++ lxc-0.9.0/debian/patches/0008-lxc-shutdown.patch 2013-05-06 11:00:44.620443837 +0200 @@ -0,0 +1,73 @@ +--- a/src/lxc/lxc-shutdown.in ++++ b/src/lxc/lxc-shutdown.in +@@ -18,13 +18,17 @@ + + set -e + ++lxcpath=/var/lib/lxc ++test ! -f @DATADIR@/lxc/lxc.conf || . @DATADIR@/lxc/lxc.conf ++ + usage() { +- echo "usage: lxc-shutdown -n name [-w] [-r]" ++ echo "usage: lxc-shutdown -n name [-w] [-r] [-P lxcpath]" + echo " Cleanly shut down a container." + echo " -w: wait for shutdown to complete." + echo " -r: reboot (ignore -w)." + echo " -t timeout: wait at most timeout seconds (implies -w), then kill" + echo " the container." ++ echo " -P lxcpath: path to the lxc container directories." + } + + alarm() { +@@ -38,7 +42,7 @@ + dolxcstop() + { + echo "Calling lxc-stop on $lxc_name" +- lxc-stop -n $lxc_name ++ lxc-stop -n $lxc_name -P "$lxcpath" + exit 0 + } + +@@ -82,6 +86,12 @@ + dowait=1 + shift + ;; ++ -P|--lxcpath) ++ optarg_check $opt "$1" ++ lxcpath=$1 ++ dowait=1 ++ shift ++ ;; + --) + break;; + -?) +@@ -104,6 +114,11 @@ + exit 1 + fi + ++if [ ! -d "$lxcpath" ]; then ++ echo "$lxcpath: no such directory" ++ exit 1 ++fi ++ + if [ "$(id -u)" != "0" ]; then + echo "This command has to be run as root" + exit 1 +@@ -112,7 +127,7 @@ + which lxc-info > /dev/null 2>&1 || { echo "lxc-info not found."; exit 1; } + which lxc-wait > /dev/null 2>&1 || { echo "lxc-wait not found."; exit 1; } + +-pid=`lxc-info -n $lxc_name -p 2>/dev/null | awk '{ print $2 }'` ++pid=`lxc-info -n $lxc_name -P "$lxcpath" -p 2>/dev/null | awk '{ print $2 }'` + if [ "$pid" = "-1" ]; then + echo "$lxc_name is not running" + exit 1 +@@ -135,7 +150,7 @@ + alarmpid=$! + fi + +-while ! lxc-info -n $lxc_name --state-is STOPPED; do ++while ! lxc-info -n $lxc_name -P "$lxcpath" --state-is STOPPED; do + sleep 1 + done + diff -urN lxc-0.9.0.orig/debian/patches/0009-lxc-clone.patch lxc-0.9.0/debian/patches/0009-lxc-clone.patch --- lxc-0.9.0.orig/debian/patches/0009-lxc-clone.patch 1970-01-01 01:00:00.000000000 +0100 +++ lxc-0.9.0/debian/patches/0009-lxc-clone.patch 2013-05-02 08:40:32.000000000 +0200 @@ -0,0 +1,87 @@ +--- a/src/lxc/lxc-clone.in ++++ b/src/lxc/lxc-clone.in +@@ -25,7 +25,7 @@ + + 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 @@ + 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 @@ + 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 @@ + 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 @@ + 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 @@ + 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 [ $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 @@ + 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 diff -urN lxc-0.9.0.orig/debian/patches/0010-lxc-create.patch lxc-0.9.0/debian/patches/0010-lxc-create.patch --- lxc-0.9.0.orig/debian/patches/0010-lxc-create.patch 1970-01-01 01:00:00.000000000 +0100 +++ lxc-0.9.0/debian/patches/0010-lxc-create.patch 2013-05-02 08:48:33.000000000 +0200 @@ -0,0 +1,11 @@ +--- a/src/lxc/lxc-create.in ++++ b/src/lxc/lxc-create.in +@@ -264,7 +264,7 @@ + btrfs subvolume delete "$rootfs" + fi + +- ${bindir}/lxc-destroy -n $lxc_name ++ ${bindir}/lxc-destroy -n $lxc_name -P "$lxc_path" + echo "$(basename $0): aborted" >&2 + exit 1 + } diff -urN lxc-0.9.0.orig/debian/patches/0011-lxc-netstat.patch lxc-0.9.0/debian/patches/0011-lxc-netstat.patch --- lxc-0.9.0.orig/debian/patches/0011-lxc-netstat.patch 1970-01-01 01:00:00.000000000 +0100 +++ lxc-0.9.0/debian/patches/0011-lxc-netstat.patch 2013-05-02 09:01:48.000000000 +0200 @@ -0,0 +1,55 @@ +--- a/src/lxc/lxc-netstat.in ++++ b/src/lxc/lxc-netstat.in +@@ -17,8 +17,10 @@ + # License along with this library; if not, write to the Free Software + # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + ++. @DATADIR@/lxc/lxc.functions ++ + usage() { +- echo "usage: $(basename $0) -n|--name <name> -- [netstat_options]" >&2 ++ echo "usage: $(basename $0) -n|--name <name> [-P|--lxcpath <lxc_path>] -- [netstat_options]" >&2 + } + + help() { +@@ -26,8 +28,9 @@ + echo >&2 + echo "Execute 'netstat' for the specified container." >&2 + echo >&2 +- echo " --name NAME specify the container name" >&2 +- echo " NETSTAT_OPTIONS netstat command options (see \`netstat --help')" >&2 ++ echo " --name NAME specify the container name" >&2 ++ echo " --lxcpath LXC_PATH use an alternate container path" >&2 ++ echo " NETSTAT_OPTIONS netstat command options (see \`netstat --help')" >&2 + } + + get_parent_cgroup() +@@ -73,6 +76,8 @@ + help; exit 1;; + -n|--name) + name=$2; shift 2;; ++ -P|--lxcpath) ++ lxc_path="$2"; shift 2;; + --exec) + exec="exec"; shift;; + --) +@@ -92,11 +97,17 @@ + exit 1 + fi + ++if [ -z "$lxc_path" ]; then ++ echo "$(basename $0): no configuration path defined" >&2 ++ usage ++ exit 1 ++fi ++ + if [ -z "$exec" ]; then +- exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name --exec "$@" ++ exec @BINDIR@/lxc-unshare -s MOUNT -- $0 -n $name -P "$lxc_path" --exec "$@" + fi + +-if lxc-info -n $name --state-is 'STOPPED'; then ++if lxc-info -n $name -P "$lxc_path" --state-is 'STOPPED'; then + echo "$(basename $0): container '$name' is not running" >&2 + exit 1 + fi diff -urN lxc-0.9.0.orig/debian/patches/series lxc-0.9.0/debian/patches/series --- lxc-0.9.0.orig/debian/patches/series 2013-04-19 14:23:08.000000000 +0200 +++ lxc-0.9.0/debian/patches/series 2013-05-02 08:51:54.000000000 +0200 @@ -5,3 +5,7 @@ 0005-lxc-init-path.patch 0006-lxc-quote-arguments.patch 0007-lxc-unshare-manpage.patch +0008-lxc-shutdown.patch +0009-lxc-clone.patch +0010-lxc-create.patch +0011-lxc-netstat.patch