From 6fb8b19b7cd2f8e7b335c047992846f719ae5445 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Fri, 9 Nov 2012 21:48:41 +0000 Subject: [PATCH] Update ramdisk building to support init hooks for flavours --- flavours/baremetal/init | 26 +++++++++++++++++++ flavours/hwburnin/init | 4 +++ flavours/hwdiscovery/init | 5 ++++ lib/ramdisk-functions | 16 ++++++++++++ scripts/init | 53 --------------------------------------- scripts/init-end | 11 ++++++++ 6 files changed, 62 insertions(+), 53 deletions(-) create mode 100644 flavours/baremetal/init create mode 100644 flavours/hwburnin/init create mode 100644 flavours/hwdiscovery/init create mode 100644 scripts/init-end diff --git a/flavours/baremetal/init b/flavours/baremetal/init new file mode 100644 index 00000000..7a5e26da --- /dev/null +++ b/flavours/baremetal/init @@ -0,0 +1,26 @@ +if [ -z "$ISCSI_TARGET_IQN" ]; then + echo "iscsi_target_iqn is not defined" + echo "Starting troubleshooting shell." + bash +fi + +target_disk=`find_disk "$DISK"` +echo "start iSCSI target on $target_disk" +start_iscsi_target "$ISCSI_TARGET_IQN" "$target_disk" ALL +if [ $? -ne 0 ]; then + echo "Could not find disk to use." + echo "Starting troubleshooting shell." + bash +fi + +echo "request boot server to deploy image" +d="i=$DEPLOYMENT_ID&k=$DEPLOYMENT_KEY&a=$BOOT_IP_ADDRESS&n=$ISCSI_TARGET_IQN" +wget --post-data "$d" "http://$BOOT_SERVER:10000" + +echo "waiting for notice of complete" +nc -l -p 10000 + +echo "stop iSCSI target on $target_disk" + +stop_iscsi_target + diff --git a/flavours/hwburnin/init b/flavours/hwburnin/init new file mode 100644 index 00000000..ed6bb873 --- /dev/null +++ b/flavours/hwburnin/init @@ -0,0 +1,4 @@ +echo "Starting HW Burnin" +memtester 1G 10 # XXX: Discover RAM size +# XXX: Discover and test disks with spew + diff --git a/flavours/hwdiscovery/init b/flavours/hwdiscovery/init new file mode 100644 index 00000000..8c03dbde --- /dev/null +++ b/flavours/hwdiscovery/init @@ -0,0 +1,5 @@ +echo "Starting HW Discovery" +# XXX: Collect iLO specific data, bundle everything up and POST it somewhere +lshw -json # XXX: Do something with this +sleep 30 + diff --git a/lib/ramdisk-functions b/lib/ramdisk-functions index ff36f78e..369ab5a4 100644 --- a/lib/ramdisk-functions +++ b/lib/ramdisk-functions @@ -107,6 +107,22 @@ function populate_init () { for F in "$FUNCTIONS_D"/* ; do cp "$F" "$TMP_MOUNT_PATH" done + + # Append /init with any flavour fragments that are present + for _FLVR in ${RAMDISK_FLAVOUR} ; do + _FILE="${FLAVOURS_DIR}/${_FLVR}/init" + if [ -a $_FILE ]; then + cat >>$TMP_MOUNT_PATH/init <>$TMP_MOUNT_PATH/init + fi + done + + # Add our final steps to /init + cat <${INIT}-end >>$TMP_MOUNT_PATH/init + } function finalise_image () { diff --git a/scripts/init b/scripts/init index 436238a3..a6bbf0fb 100644 --- a/scripts/init +++ b/scripts/init @@ -34,8 +34,6 @@ mount -t proc proc /proc readonly _BOOTIF_=$(get_kernel_parameter BOOTIF) readonly _IP_=$(get_kernel_parameter ip) -readonly _CMDLINE_FLAVOUR=$(get_kernel_parameter FLAVOUR) -readonly FLAVOUR=${_CMDLINE_FLAVOUR:-baremetal} readonly BOOT_MAC_ADDRESS=$(echo "$_BOOTIF_" | sed -e "s/-/:/g" | sed -e "s/^01://g" | tr 'a-f' 'A-F') readonly BOOT_IP_ADDRESS=$(echo "$_IP_" | cut -d':' -f1) readonly BOOT_SERVER=$(echo "$_IP_" | cut -d':' -f2) @@ -47,13 +45,6 @@ readonly DEPLOYMENT_ID=$(get_kernel_parameter deployment_id) readonly DEPLOYMENT_KEY=$(get_kernel_parameter deployment_key) readonly ISCSI_TARGET_IQN=$(get_kernel_parameter iscsi_target_iqn) -string_contains $FLAVOUR "baremetal" -if [ "$?" == "0" -a -z "$ISCSI_TARGET_IQN" ]; then - echo "iscsi_target_iqn is not defined" - echo "Starting troubleshooting shell." - bash -fi - mount -t sysfs none /sys mount -t tmpfs none /dev ln -sf /proc/self/fd /dev/fd @@ -132,47 +123,3 @@ done echo "network ready" -string_contains $FLAVOUR "baremetal" -if [ "$?" == "0" ]; then - target_disk=`find_disk "$DISK"` - echo "start iSCSI target on $target_disk" - start_iscsi_target "$ISCSI_TARGET_IQN" "$target_disk" ALL - if [ $? -ne 0 ]; then - echo "Could not find disk to use." - echo "Starting troubleshooting shell." - bash - fi - - echo "request boot server to deploy image" - d="i=$DEPLOYMENT_ID&k=$DEPLOYMENT_KEY&a=$BOOT_IP_ADDRESS&n=$ISCSI_TARGET_IQN" - wget --post-data "$d" "http://$BOOT_SERVER:10000" - - echo "waiting for notice of complete" - nc -l -p 10000 - - echo "stop iSCSI target on $target_disk" - - stop_iscsi_target -fi - -string_contains $FLAVOUR "hwdiscovery" -if [ "$?" == "0" ]; then - echo "Starting HW Discovery" - # XXX: Collect iLO specific data, bundle everything up and POST it somewhere - lshw -json # XXX: Do something with this - sleep 30 -fi - -string_contains $FLAVOUR "hwburnin" -if [ "$?" == "0" ]; then - echo "Starting HW Burnin" - memtester 1G 10 # XXX: Discover RAM size - # XXX: Discover and test disks with spew -fi - -echo "rebooting" -reboot -f - -echo "failed to reboot" -echo "Starting troubleshooting shell." -bash diff --git a/scripts/init-end b/scripts/init-end new file mode 100644 index 00000000..3180f1fc --- /dev/null +++ b/scripts/init-end @@ -0,0 +1,11 @@ + + +# Final init steps + +echo "rebooting" +reboot -f + +echo "failed to reboot" +echo "Starting troubleshooting shell." +bash +