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
This commit is contained in:
Auston McReynolds
2013-08-30 19:54:42 -07:00
parent 91e0d6d932
commit 34ea41c273
6 changed files with 35 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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() {

View File

@@ -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}