1
0
mirror of https://git.yoctoproject.org/meta-arm synced 2026-01-12 03:10:15 +00:00

arm-autonomy/xenguest-manager: source init scripts

source init scripts in xenguest manager instead of executing
directly, so they can immediately access functions and
variables from the parent script.

Also added a check that init scripts are executable, and will
skip if not.

Change-Id: Ie6bbb1b480a7bfe5af095addcf1aefd122b57c50
Issue-Id: SCM-1587
Signed-off-by: Nathan Dunne <Nathan.Dunne@arm.com>
Signed-off-by: Jon Mason <jon.mason@arm.com>
This commit is contained in:
Nathan Dunne
2020-10-26 11:12:22 +00:00
committed by Jon Mason
parent cdfe259d13
commit 128af6b2d0
3 changed files with 82 additions and 33 deletions

View File

@@ -48,16 +48,16 @@ project compilation (those can be set in your project local.conf, for example).
The following parameters are available:
- XENGUEST_MANAGER_VOLUME_DEVICE: This is the device path used by the
- XENGUEST_MANAGER_VOLUME_DEVICE: This is the device path used by the
xenguest-manager on the device to create LVM disks when guests have a disk
configuration.
This is set by default to "/dev/sda2".
- XENGUEST_MANAGER_VOLUME_NAME: This is the LVM volume name that the
- XENGUEST_MANAGER_VOLUME_NAME: This is the LVM volume name that the
xenguest-manager will create and use to create guest LVM disks.
This is set by default to "vg-xen".
- XENGUEST_MANAGER_GUEST_DIR: This is the directory on Dom0 where the
- XENGUEST_MANAGER_GUEST_DIR: This is the directory on Dom0 where the
xenguest-manager will look for xenguest images to create during init. That's
the place where xenguest images can be added to have them automatically
created during next Dom0 boot. The xenguests found there will only be created
@@ -65,3 +65,35 @@ The following parameters are available:
name).
This is set by default to "/usr/share/guests".
Init scripts
------------
Shell scripts can be executed on the host when a guest is started. Depending on
when the script should be executed it should be installed in a different
directory on the target:
- /etc/xenguest/init.pre : Executed first, prior to guest creation
- /etc/xenguest/init.d : Executed after guest creation, but before it is started
- /etc/xenguest/init.post : Executed after starting the guest
Inside the directory, scripts will be executed in alphabetical order.
Since these scripts are sourced by xenguest-manager they can acccess functions
and variables from the parent file's scope, including:
- ${guestname} : The name of the guest being created
- ${guestdir} : The path to the guest directory
- ${LOGFILE} : The file to append any logging to, e.g.
echo "Hello, World" >> ${LOGFILE}
Sourcing also allows the script to access params.cfg.
An example of how to create the directory and install an init shell script can
be found in:
recipes-extended/xenguest/xenguest-network.bb
Where network-bridge.sh is installed from network-bridge.sh.in

View File

@@ -1,14 +1,13 @@
#!/bin/sh
# This script is setting up a virtual network interface connected to the
# xenguest-network-bridge if NETWORK_BRIDGE is set to 1 in the guest params
guestname="${1}"
#
# Since this script is sourced by xenguest-manager, it can access variables
# such as ${guestname} from the parent file's scope, as well as those in
# params.cfg, for example XENGUEST_NETWORK_TYPE
BRIDGE_NAME="###BRIDGE_NAME###"
# get guest parameters
. ./params.cfg
case "${XENGUEST_NETWORK_TYPE:-}" in
nat)
# Create the symlinks for the files that vif-nat script expects

View File

@@ -475,6 +475,9 @@ function xenguest_guest_start()
# Build init script lists (ignore non existing dirs errors,
# sort alphabetically and run global scripts first)
#
# These scripts are sourced throughout the start operation if they
# are executable
init_pre="$(find ${XENGUEST_CONF_BASE}/init.pre -type f 2> /dev/null | \
sort) $(find ${guestdir}/init.pre -type f 2> /dev/null | sort)"
init_d="$(find ${XENGUEST_CONF_BASE}/init.d -type f 2> /dev/null | \
@@ -484,13 +487,18 @@ function xenguest_guest_start()
# call pre init scripts
for f in ${init_pre}; do
echo "$f ${guestname}" >> ${LOGFILE} 2>&1
$f ${guestname} >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]; then
rm -f ${guestname}.cfg
popd > /dev/null 2>&1
echo "${PREF} Error during pre init script of ${guestname}"
exit 1
if [ -x "$f" ]; then
echo "( . $f )" >> ${LOGFILE} 2>&1
( . $f ) >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]; then
rm -f ${guestname}.cfg
popd > /dev/null 2>&1
echo "Error in init script $f" >> ${LOGFILE} 2>&1
echo "${PREF} Error during pre init script of ${guestname}"
exit 1
fi
else
echo "$f is not executable. Skipping." >> ${LOGFILE}
fi
done
@@ -506,15 +514,20 @@ function xenguest_guest_start()
# call init scripts
for f in ${init_d}; do
echo "$f ${guestname}" >> ${LOGFILE} 2>&1
$f ${guestname} >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]; then
rm -f ${guestname}.cfg
echo "xl destroy ${guestname}" >> ${LOGFILE} 2>&1
xl destroy ${guestname} >> ${LOGFILE} 2>&1
popd > /dev/null 2>&1
echo "${PREF} Error during init script of ${guestname}"
exit 1
if [ -x "$f" ]; then
echo "( . $f )" >> ${LOGFILE} 2>&1
( . $f ) >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]; then
rm -f ${guestname}.cfg
echo "xl destroy ${guestname}" >> ${LOGFILE} 2>&1
xl destroy ${guestname} >> ${LOGFILE} 2>&1
popd > /dev/null 2>&1
echo "Error in init script $f" >> ${LOGFILE} 2>&1
echo "${PREF} Error during init script of ${guestname}"
exit 1
fi
else
echo "$f is not executable. Skipping." >> ${LOGFILE}
fi
done
@@ -530,15 +543,20 @@ function xenguest_guest_start()
# call post init scripts
for f in ${init_post}; do
echo "$f ${guestname}" >> ${LOGFILE} 2>&1
$f ${guestname} >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]; then
rm -f ${guestname}.cfg
echo "xl destroy ${guestname}" >> ${LOGFILE} 2>&1
xl destroy ${guestname} >> ${LOGFILE} 2>&1
popd > /dev/null 2>&1
echo "${PREF} Error during post init script of ${guestname}"
exit 1
if [ -x "$f" ]; then
echo "( . $f )" >> ${LOGFILE} 2>&1
( . $f ) >> ${LOGFILE} 2>&1
if [ $? -ne 0 ]; then
rm -f ${guestname}.cfg
echo "xl destroy ${guestname}" >> ${LOGFILE} 2>&1
xl destroy ${guestname} >> ${LOGFILE} 2>&1
popd > /dev/null 2>&1
echo "Error in init script $f" >> ${LOGFILE} 2>&1
echo "${PREF} Error during post init script of ${guestname}"
exit 1
fi
else
echo "$f is not executable. Skipping." >> ${LOGFILE}
fi
done