From 2c934d4ec418aac94d3592b06a91b65566cd2edc Mon Sep 17 00:00:00 2001 From: Fabio Rehm Date: Sun, 9 Mar 2014 20:20:37 -0300 Subject: [PATCH] boxes: Fix output logging --- boxes/common/package.sh | 4 ++-- boxes/common/ui.sh | 6 +++--- boxes/common/utils.sh | 15 +++++---------- boxes/debian/install-extras.sh | 2 +- boxes/mk-ubuntu.sh | 6 ++++++ 5 files changed, 17 insertions(+), 16 deletions(-) diff --git a/boxes/common/package.sh b/boxes/common/package.sh index e223ee4..a897317 100755 --- a/boxes/common/package.sh +++ b/boxes/common/package.sh @@ -16,10 +16,10 @@ if [ -f ${WORKING_DIR}/rootfs.tar.gz ]; then fi log "Compressing container's rootfs" -pushd $(dirname ${ROOTFS}) &>${LOG} +pushd $(dirname ${ROOTFS}) &>>${LOG} tar --numeric-owner --anchored --exclude=./rootfs/dev/log -czf \ ${WORKING_DIR}/rootfs.tar.gz ./rootfs/* -popd &>${LOG} +popd &>>${LOG} # Prepare package contents log 'Preparing box package contents' diff --git a/boxes/common/ui.sh b/boxes/common/ui.sh index b389b67..6372a8d 100644 --- a/boxes/common/ui.sh +++ b/boxes/common/ui.sh @@ -6,17 +6,17 @@ export ERROR_COLOR='\033[31;01m' export WARN_COLOR='\033[33;01m' log() { - echo " [${RELEASE}] ${1}" >${LOG} + echo " [${RELEASE}] ${1}" >>${LOG} echo " [${RELEASE}] ${1}" >&2 } warn() { - echo "==> [${RELEASE}] [WARN] ${1}" >${LOG} + echo "==> [${RELEASE}] [WARN] ${1}" >>${LOG} echo -e "${WARN_COLOR}==> [${RELEASE}] ${1}${NO_COLOR}" } info() { - echo "==> [${RELEASE}] [INFO] ${1}" >${LOG} + echo "==> [${RELEASE}] [INFO] ${1}" >>${LOG} echo -e "${OK_COLOR}==> [${RELEASE}] ${1}${NO_COLOR}" } diff --git a/boxes/common/utils.sh b/boxes/common/utils.sh index 7cc89d8..e7a7f9f 100644 --- a/boxes/common/utils.sh +++ b/boxes/common/utils.sh @@ -1,28 +1,23 @@ #!/bin/bash -mkdir -p $(dirname $LOG) -rm -f ${LOG} -touch ${LOG} -chmod +rw ${LOG} - utils.lxc.attach() { cmd="$@" log "Running [${cmd}] inside '${CONTAINER}' container..." - (lxc-attach -n ${CONTAINER} -- $cmd) &> ${LOG} + (lxc-attach -n ${CONTAINER} -- $cmd) &>> ${LOG} } utils.lxc.start() { - lxc-start -d -n ${CONTAINER} &>${LOG} || true + lxc-start -d -n ${CONTAINER} &>>${LOG} || true } utils.lxc.stop() { - lxc-stop -n ${CONTAINER} &>${LOG} || true + lxc-stop -n ${CONTAINER} &>>${LOG} || true } utils.lxc.destroy() { - lxc-destroy -n ${CONTAINER} &>${LOG} + lxc-destroy -n ${CONTAINER} &>>${LOG} } utils.lxc.create() { - lxc-create -n ${CONTAINER} "$@" &>${LOG} + lxc-create -n ${CONTAINER} "$@" &>>${LOG} } diff --git a/boxes/debian/install-extras.sh b/boxes/debian/install-extras.sh index 1dc4f3e..d69d3e5 100755 --- a/boxes/debian/install-extras.sh +++ b/boxes/debian/install-extras.sh @@ -52,7 +52,7 @@ if [ $PUPPET = 1 ]; then warn "Puppet can't be installed on Ubuntu Trusty 14.04, skipping" else log "Installing Puppet" - wget http://apt.puppetlabs.com/puppetlabs-release-stable.deb -O "${ROOTFS}/tmp/puppetlabs-release-stable.deb" &>${LOG} + wget http://apt.puppetlabs.com/puppetlabs-release-stable.deb -O "${ROOTFS}/tmp/puppetlabs-release-stable.deb" &>>${LOG} utils.lxc.attach dpkg -i "/tmp/puppetlabs-release-stable.deb" utils.lxc.attach apt-get update utils.lxc.attach apt-get install puppet -y --force-yes diff --git a/boxes/mk-ubuntu.sh b/boxes/mk-ubuntu.sh index 563be5f..4d5c9ab 100755 --- a/boxes/mk-ubuntu.sh +++ b/boxes/mk-ubuntu.sh @@ -18,6 +18,12 @@ export WORKING_DIR="/tmp/${CONTAINER}" export NOW=$(date -u) export LOG=$(readlink -f .)/log/${CONTAINER}.log +mkdir -p $(dirname $LOG) +echo '############################################' > ${LOG} +echo "# Beginning build at $(date)" >> ${LOG} +touch ${LOG} +chmod +rw ${LOG} + if [ -f ${PACKAGE} ]; then warn "The box '${PACKAGE}' already exists, skipping..." echo