From 34ea41c273d16728c9d40dfb16009ea44a681652 Mon Sep 17 00:00:00 2001 From: Auston McReynolds Date: Fri, 30 Aug 2013 19:54:42 -0700 Subject: [PATCH] Custom Guest Log Directory Causes Init Failure The log_dir in trove-guestagent.conf.sample currently defaults to '/tmp', and the log_file to 'logfile.txt'. If the log_dir value is changed to, say, '/var/log/trove', guest initialization will fail because the directory does not exist. Even if log_dir is set to '/var/log', initialization will fail due to insufficient write permissions in said directory. Solution: The log_dir specified in trove-guestagent.conf.sample should be created on-demand if necessary. Change-Id: Ic819aaa08f8a78483e1c0ae0aa8af370c6705562 Closes-Bug: #1219137 --- .../fedora-guest/extra-data.d/20-guest-upstart | 4 +++- .../ubuntu-guest/extra-data.d/20-guest-upstart | 4 +++- scripts/files/trove-guest.systemd.conf | 2 ++ scripts/files/trove-guest.upstart.conf | 3 +++ scripts/functions | 11 +++++++++++ scripts/functions_qemu | 13 +++++++++++++ 6 files changed, 35 insertions(+), 2 deletions(-) diff --git a/scripts/files/elements/fedora-guest/extra-data.d/20-guest-upstart b/scripts/files/elements/fedora-guest/extra-data.d/20-guest-upstart index 4d429e6c..3f7192ad 100755 --- a/scripts/files/elements/fedora-guest/extra-data.d/20-guest-upstart +++ b/scripts/files/elements/fedora-guest/extra-data.d/20-guest-upstart @@ -16,9 +16,11 @@ source $_LIB/die [ -n "${NETWORK_GATEWAY}" ] || die "NETWORK_GATEWAY needs to be set to the user for the host instance" [ -n "${REDSTACK_SCRIPTS}" ] || die "REDSTACK_SCRIPTS needs to be set to the trove-integration scripts dir" [ -n "${SERVICE_TYPE}" ] || die "SERVICE_TYPE must be set to something like mysql to create upstart conf" +[ -n "${GUEST_LOGDIR}" ] || die "GUEST_LOGDIR must be set to the desired guest log dir" +[ -n "${ESCAPED_GUEST_LOGDIR}" ] || die "ESCAPED_GUEST_LOGDIR must be set to the escaped guest log dir" # put this file in first-boot.d directory so that it is executed on startup sed "s/GUEST_USERNAME/${GUEST_USERNAME}/g;s/HOST_USERNAME/${HOST_USERNAME}/g;s/NETWORK_GATEWAY/${NETWORK_GATEWAY}/g;s/PATH_TROVE/${ESCAPED_PATH_TROVE}/g" ${REDSTACK_SCRIPTS}/files/bootstrap_init-mysql.sh > ${TMP_HOOKS_PATH}/first-boot.d/60-bootstrap_init-mysql chmod 755 ${TMP_HOOKS_PATH}/first-boot.d/60-bootstrap_init-mysql -sed "s/GUEST_USERNAME/${GUEST_USERNAME}/g" ${REDSTACK_SCRIPTS}/files/trove-guest.systemd.conf > ${TMP_HOOKS_PATH}/trove-guest.service +sed "s/GUEST_USERNAME/${GUEST_USERNAME}/g;s/GUEST_LOGDIR/${ESCAPED_GUEST_LOGDIR}/g" ${REDSTACK_SCRIPTS}/files/trove-guest.systemd.conf > ${TMP_HOOKS_PATH}/trove-guest.service diff --git a/scripts/files/elements/ubuntu-guest/extra-data.d/20-guest-upstart b/scripts/files/elements/ubuntu-guest/extra-data.d/20-guest-upstart index 4621667f..6b748468 100755 --- a/scripts/files/elements/ubuntu-guest/extra-data.d/20-guest-upstart +++ b/scripts/files/elements/ubuntu-guest/extra-data.d/20-guest-upstart @@ -16,9 +16,11 @@ source $_LIB/die [ -n "${NETWORK_GATEWAY}" ] || die "NETWORK_GATEWAY needs to be set to the user for the host instance" [ -n "${REDSTACK_SCRIPTS}" ] || die "REDSTACK_SCRIPTS needs to be set to the trove-integration scripts dir" [ -n "${SERVICE_TYPE}" ] || die "SERVICE_TYPE must be set to something like mysql to create upstart conf" +[ -n "${GUEST_LOGDIR}" ] || die "GUEST_LOGDIR must be set to the desired guest log dir" +[ -n "${ESCAPED_GUEST_LOGDIR}" ] || die "ESCAPED_GUEST_LOGDIR must be set to the escaped guest log dir" # put this file in first-boot.d directory so that it is executed on startup sed "s/GUEST_USERNAME/${GUEST_USERNAME}/g;s/HOST_USERNAME/${HOST_USERNAME}/g;s/NETWORK_GATEWAY/${NETWORK_GATEWAY}/g;s/PATH_TROVE/${ESCAPED_PATH_TROVE}/g" ${REDSTACK_SCRIPTS}/files/bootstrap_init-mysql.sh > ${TMP_HOOKS_PATH}/first-boot.d/60-bootstrap_init-mysql chmod 775 ${TMP_HOOKS_PATH}/first-boot.d/60-bootstrap_init-mysql -sed "s/GUEST_USERNAME/${GUEST_USERNAME}/g" ${REDSTACK_SCRIPTS}/files/trove-guest.upstart.conf > ${TMP_HOOKS_PATH}/trove-guest.conf +sed "s/GUEST_USERNAME/${GUEST_USERNAME}/g;s/GUEST_LOGDIR/${ESCAPED_GUEST_LOGDIR}/g" ${REDSTACK_SCRIPTS}/files/trove-guest.upstart.conf > ${TMP_HOOKS_PATH}/trove-guest.conf diff --git a/scripts/files/trove-guest.systemd.conf b/scripts/files/trove-guest.systemd.conf index 7f7a5dca..91fa206b 100644 --- a/scripts/files/trove-guest.systemd.conf +++ b/scripts/files/trove-guest.systemd.conf @@ -8,6 +8,8 @@ Type=simple User=GUEST_USERNAME Group=GUEST_USERNAME +ExecStartPre=mkdir -p GUEST_LOGDIR ; chown GUEST_USERNAME:root GUEST_LOGDIR + # Note: we set --basedir to prevent probes that might trigger SELinux alarms, # per bug #547485 ExecStart=/home/GUEST_USERNAME/trove/bin/trove-guestagent --config-file=/etc/guest_info --config-file=/home/GUEST_USERNAME/trove/etc/trove/trove-guestagent.conf.sample diff --git a/scripts/files/trove-guest.upstart.conf b/scripts/files/trove-guest.upstart.conf index bc362010..8a956024 100644 --- a/scripts/files/trove-guest.upstart.conf +++ b/scripts/files/trove-guest.upstart.conf @@ -10,6 +10,9 @@ pre-start script mkdir -p /var/lock/trove chown GUEST_USERNAME:root /var/lock/trove/ + + mkdir -p GUEST_LOGDIR + chown GUEST_USERNAME:root GUEST_LOGDIR end script exec su -c "/home/GUEST_USERNAME/trove/bin/trove-guestagent --config-file=/etc/guest_info --config-file=/home/GUEST_USERNAME/trove/etc/trove/trove-guestagent.conf.sample" GUEST_USERNAME diff --git a/scripts/functions b/scripts/functions index e0c06f77..d205d053 100644 --- a/scripts/functions +++ b/scripts/functions @@ -67,6 +67,17 @@ function ini_has_option() { [ -n "$line" ] } +# Get an option from an INI file +# iniget config-file section option +function iniget() { + local file=$1 + local section=$2 + local option=$3 + local line + line=$(sed -ne "/^\[$section\]/,/^\[.*\]/ { /^$option[ \t]*=/ p; }" "$file") + echo ${line#*=} +} + # Set an option in an INI file # iniset config-file section option value function iniset() { diff --git a/scripts/functions_qemu b/scripts/functions_qemu index 2f1e5976..1c7101f0 100644 --- a/scripts/functions_qemu +++ b/scripts/functions_qemu @@ -40,6 +40,8 @@ function build_vm() { export SERVICE_TYPE export ESCAPED_PATH_TROVE export SSH_DIR + export GUEST_LOGDIR + export ESCAPED_GUEST_LOGDIR export ELEMENTS_PATH=$REDSTACK_SCRIPTS/files/elements:$PATH_TRIPLEO_ELEMENTS/elements ${PATH_DISKIMAGEBUILDER}/bin/disk-image-create -a amd64 -o "${VM}" -x ${DISTRO} ${EXTRA_ELEMENTS} vm heat-cfntools ${DISTRO}-guest ${DISTRO}-${SERVICE_TYPE} } @@ -61,6 +63,17 @@ function cmd_build_image() { iniset $TROVE_CONF_DIR/trove.conf DEFAULT service_type $SERVICE_TYPE + GUEST_LOGDIR=$(iniget $TROVE_SOURCE/etc/trove/trove-guestagent.conf.sample DEFAULT log_dir) + GUEST_LOGFILE=$(iniget $TROVE_SOURCE/etc/trove/trove-guestagent.conf.sample DEFAULT log_file) + + if [ -z $GUEST_LOGDIR ] || [ -z $GUEST_LOGFILE ] + then + exclaim "error: log_dir and log_file are required in: " $TROVE_SOURCE/etc/trove/trove-guestagent.conf.sample + exit 1 + fi + + ESCAPED_GUEST_LOGDIR=`echo $GUEST_LOGDIR | sed 's/\//\\\\\//g'` + USERNAME=`whoami` # To change the distro, edit the redstack.rc file readonly IMAGENAME=${DISTRO}_${SERVICE_TYPE}