Hi Guys,
Can you shed some light on this for me please. I am trying to install a management agent (hp) in the %post section of my KS.cfg file. It doesnt install for some reason. However once the script completes and the esx box is built I can copy the exact lines that install the agent in my script into an ssh session on the esx box and the agent installs just fine.
Not sure why this is...
Thanks
Can you you share with us the code that you're using to install the agent? If you rely on any particular VMware components such as esxupdate, since the OS has just installed, not all components have been started up. My generall rule of thumb is to only run things in %post that is 100% necessary, else I'll have everything as part of the "post installation" upon first boot and set it as the last S* script so that all components have been loaded up.
lawm,
Thanks for the response... sure here is the part of the script:
echo "***12">>/var/log/esx_install.log
/tmp/hpmgmt/851//install851vibs.sh --silent --inputfile /tmp/hpmgmt/851/hpmgmt.conf
echo "***12RT=$?">>/var/log/esx_install.log
Like I said it runs fine when I paste these lines into the esx box after the o/s is built and I ssh to it. I was starting to think on the same lines as what you suggested. How would I get the majority of my %post section into S* all automated as I have always been accustomed having esx build scripts run in rc.local?
This particular script looks interesting:
/tmp/hpmgmt/851/install851vibs.sh
The name *vibs* is probably the key and I'm going to assume if you take a look inside this script it's probably using a VMware VIB and esxupdate to perform the installation? Could you share the contents of that installation script?
What version of ESX(i) are you using?
Hi lawm,
I am running ESX 4.0.0, 261974
Something interesting....
Everything runs in my lines but the failure occurs after install851vibs.sh is executed. Specifically around the time just after it puts the server in maintenance mode... So I tried something else. I tried running this script as a run once logon script when ESX is fully installed and running, however again it failed with the same thing...
the contents of the script:
#
# *********************************************************************
# ** Global Variables that need to be modified with each release **
# *********************************************************************
BULLETIN_ID_TOKEN=hp-classic-mgmt-solution
BUILD_NUMBER=1
VERSION_NAME=8.5.1
CONFIG_SCRIPTNAME=configurevm851.sh
VIB_SIGNED_SW=
# *********************************************************************
# Following are for setting colors
# *********************************************************************
. /etc/init.d/functions
# Set the positon to print OK/FAILED
RES_COL=74
MOVE_TO_COL="echo -en \\033[${RES_COL}G"
SETCOLOR_BLUE="echo -en \\033[1;34m"
SETCOLOR_WHITE="echo -en \\033[0;39m"
SETCOLOR_RED="echo -en \\033[0;31m"
SETCOLOR_CYAN="echo -en \\033[0;36m"
SETCOLOR_MAGENTA="echo -en \\033[1;31m"
SETCOLOR_LIGHTRED="echo -en \\033[1;31m"
SETCOLOR_YELLOW="echo -en \\033[1;33m"
SETCOLOR_WARNING=$SETCOLOR_YELLOW
SETCOLOR_FAILURE=$SETCOLOR_RED
# *********************************************************************
# The name of the log file
# *********************************************************************
ESX_v41=4.1.0
LOGFILENAME="vib_bulletin_update.log"
HPIM_VMLIST="HPIM_VM_list.txt"
#count=0
#count1=0
#declare -a arr
#i=0
HP_AGENTS_GENERIC_NAME="HP Insight Manager Agents"
OFFLINE_BUNDLE_NAME=hpmgmt.zip
HP_IM_AGENTS_CONF_FILE=hpmgmt.conf.example
AGENTS_CONFIG_FOLDER=/opt/hp/hp-agents-config
AGENTS_CONFIG_ARG1="Arg1 not initialized"
AGENTS_CONFIG_ARG2="Arg2 not initialized"
AGENTS_CONFIG_ARG3="Arg3 not initialized"
TRUE_VALUE=true,
FALSE_VALUE=false,
UNINITIALIZED_VALUE=999
PKG_BULLETIN_ID=
PKG_REL_DATE=
MAX_BLTN_IDS=5
nSTAT_UNINSTALL=
ESX_HOST_REBOOT_REQ=$UNINITIALIZED_VALUE
INITIAL_ESX_STATE=$UNINITIALIZED_VALUE
CURRENT_ESX_STATE=$UNINITIALIZED_VALUE
ISTAT_REG=$UNINITIALIZED_VALUE
OPERATION_REQUESTED=$UNINITIALED_VALUE
# Return codes
nSTATUS_SUCCESS=0
nSTAT_BLTN_FOUND=$nSTATUS_SUCCESS
nSTAT_BLTN_NOT_FOUND=13
nSTAT_ESX_REBOOT_REQ=80
nSTAT_CMD_ERROR=90
nSTAT_PKG_BLTN_ERR=91
nSTAT_BLTN_SAME=92
nSTAT_PKG_BLTN_OLD=93
nSTAT_UNINSTALL_ERR=94
nSTAT_MULTI_BLTN_FOUND=101
nSTAT_ESX_MAINT_ON=105
nSTAT_ESX_MAINT_OFF=205
nSTAT_ESX_MAINT_MODE_ERR=111
nSTAT_ESX_MAINT_MODE_FLAG=$UNINITIALIZED_VALUE
nHOST_MAINTENANCE_MODE=$UNINITIALIZED_VALUE
# Config Agents Return codes (95 -100)
nSTAT_CONFIG_AGENTS=
nSTAT_CONFIG_AGENTS_RET_VALUE=
nSTAT_CONFIG_AGENTS_SUCCESS=0
nSTAT_CONFIG_AGENTS_USAGE_ERR=95
nSTAT_CONFIG_AGENTS_FILE_MISSING=96
if [ ! -n "$VERSION_NAME" ] ; then
VERSION_NAME="UNK.UNK.UNK"
fi
if [ -n "$BUILD_NUMBER" ]
then
MINOR_VERSION="-$BUILD_NUMBER"
else
MINOR_VERSION=""
fi
# Identify server
TARGET_SERVER=`dmidecode | grep "Product Name" | cut -d":" -f2`
# Identify the ESX Version where agents are to be installed
ESX_BUILD_VERSION=`vmware -v | cut -d"-" -f2`
INSTALLATION_VERSION=`vmware -v`
INSTALLED_VERSION=`vmware -v | awk '{print $3}'`
ESX_HOST_NAME=`hostname`
RELDATE_TAG="Release"
ID_TAG="Id"
if [ $INSTALLED_VERSION = $ESX_v41 ]
then
ID_TAG="ID"
fi
# Search pattern for checking installed agents and driver
SEARCH_AGENTS="hp-health\|hp-snmp-agents\|hpsmh\|hp-smh-templates\|hp-agents-config\|hpilo"
setsuccess() {
echo "....OK"
echo -e "\t[ OK ]" >> $LOGFILENAME
}
setfailure() {
echo "....FAILED"
echo -e "\t[ FAILED ]" >> $LOGFILENAME
}
splash() {
echo " "
if [[ ! $SILENT ]]; then $SETCOLOR_BLUE; fi
echo "HP Insight Manager Agent ${VERSION_NAME}${MINOR_VERSION} Installer for VMware ESX "
echo " Target System is $INSTALLATION_VERSION "
echo " Server: $TARGET_SERVER "
if [[ ! $SILENT ]]; then $SETCOLOR_NORMAL; fi
echo -e "HP Insight Manager Agent ${VERSION_NAME}${MINOR_VERSION} Installer for VMware ESX" >> $LOGFILENAME
echo " Target System is $INSTALLATION_VERSION " >> $LOGFILENAME
echo " Server: $TARGET_SERVER " >> $LOGFILENAME
echo " "
}
error() {
$SETCOLOR_LIGHTRED
echo $1 | tee -a $LOGFILENAME
echo -e "Check $LOGFILENAME for additional information"
$SETCOLOR_NORMAL
}
do_exit() {
#
# ESX Host must be in the same state as before agents installation
# If it was not in maintenance mode, we need to put it back
# If it was in maintenacne mode, then do nothing
#
ISTAT_RET=$1
# remove temp file
if [ -f $HPIM_VMLIST ]; then
rm -f $HPIM_VMLIST
fi
echo Installer exit is called with status - [$ISTAT_RET] >> $LOGFILENAME
if [ $INITIAL_ESX_STATE = $CURRENT_ESX_STATE ]; then
echo Leaving the system as is in the original state [$CURRENT_ESX_STATE ] >> $LOGFILENAME
else
# the assumption is that the host was in normal mode before the agents installation
echo Setting the ESX system to normal mode >> $LOGFILENAME
reset_host
ISTAT_RET=$?
if [ $ISTAT_RET = $nSTAT_ESX_MAINT_OFF ]; then
# Host is succesfully set to normal mode.
# Return the previous status code from esxupdate installer
# else, return the host status from the reset_host
echo ESX system is set to normal mode >> $LOGFILENAME
ISTAT_RET=$1
fi
fi
echo -e "**** [`date`] **** Exit $ISTAT_RET ****" >> $LOGFILENAME
# if [ $? = $nSTAT_ESX_MAINT_OFF ]; then
# exit $nSTAT_ESX_MAINT_OFF
# else
# exit $1
# fi
exit $ISTAT_RET
}
verify_action() {
echo "" | tee -a $LOGFILENAME
echo "This script will now attempt to $1 the $HP_AGENTS_GENERIC_NAME. " | tee -a $LOGFILENAME
echo -n "Do you wish to continue? (y/n) " | tee -a $LOGFILENAME
read answer
echo "$answer" >> $LOGFILENAME
if [ "$answer" != "y" ]; then
error "Action cancelled by user"
do_exit 34
fi
}
verify_host_action() {
echo "" | tee -a $LOGFILENAME
$SETCOLOR_LIGHTRED
echo "This script will now attempt to set ESX Host in Maintenance Mode " | tee -a $LOGFILENAME
echo "for IM agents $1." | tee -a $LOGFILENAME
$SETCOLOR_NORMAL
echo -n "Do you wish to continue? (y/n) " | tee -a $LOGFILENAME
read answer
echo "$answer" >> $LOGFILENAME
if [ "$answer" != "y" ]; then
error "Action cancelled by user"
do_exit 35
fi
}
check_installed_pkgs() {
INSTALLEDAGENTS=`rpm -qa | grep "$SEARCH_AGENTS"`
echo -n "Checking for previously installed agents" | tee -a $LOGFILENAME
if [ -z "$INSTALLEDAGENTS" ]; then
setsuccess
else
setfailure
echo " The following packages have already been installed on the system:" >> $LOGFILENAME
rpm -qa | grep "$SEARCH_AGENTS" >> $LOGFILENAME
echo "Please remove the previous installation" >> $LOGFILENAME
$SETCOLOR_LIGHTRED
echo "Some agents have already been installed. Please remove the previous installation."
echo -e "Check $LOGFILENAME for additional information"
$SETCOLOR_NORMAL
do_exit 1
fi
}
check_esx_host_maintenancemode() {
nHOST_MAINTENANCE_MODE=`vim-cmd hostsvc/runtimeinfo | grep inMaintenanceMode | awk '{print $3}'`
if [ "$nHOST_MAINTENANCE_MODE" = "$TRUE_VALUE" ]; then
echo "ESX host is in Maintenance Mode." >> $LOGFILENAME
nSTAT_ESX_MAINT_MODE_FLAG=$nSTAT_ESX_MAINT_ON
else
echo "ESX host is NOT in Maintenance Mode." >> $LOGFILENAME
nSTAT_ESX_MAINT_MODE_FLAG=$nSTAT_ESX_MAINT_OFF
fi
return $nSTAT_ESX_MAINT_MODE_FLAG
}
set_esx_host_maintenancemode() {
#prepare_vms
echo " Putting system into maintenance mode " | tee -a $LOGFILENAME
vim-cmd hostsvc/maintenance_mode_enter >> $LOGFILENAME 2>&1
if [ $? = 0 ]; then
sleep 30
echo "ESX host Maintenance Mode is SET." | tee -a $LOGFILENAME
echo " " | tee -a $LOGFILENAME
else
echo "ESX host Maintenance Mode SET failed." >> $LOGFILENAME
echo " " | tee -a $LOGFILENAME
fi
}
unset_esx_host_maintenancemode() {
echo " Putting system into normal mode " >> $LOGFILENAME
vim-cmd hostsvc/maintenance_mode_exit >> $LOGFILENAME 2>&1
if [ $? = 0 ]; then
sleep 30
echo "ESX host Maintenance Mode is UNSET." | tee -a $LOGFILENAME
echo " " | tee -a $LOGFILENAME
else
echo "ESX host Maintenance Mode UNSET failed." >> $LOGFILENAME
echo " " | tee -a $LOGFILENAME
return $nSTAT_ESX_MAINT_MODE_ERR
fi
#restore_vms
}
set_host() {
check_state_of_vms
Active_VMs=$?
if [ $Active_VMs = 0 ]; then
if [ $CURRENT_ESX_STATE = $nSTAT_ESX_MAINT_OFF ]; then
set_esx_host_maintenancemode
else
echo "System is already in Maintenace mode. " | tee -a $LOGFILENAME
fi
check_esx_host_maintenancemode
RET_UNINSTALL=$?
if [ $RET_UNINSTALL = $nSTAT_ESX_MAINT_OFF ]; then
echo "ESX host Maintenance mode is not set to continue." | tee -a $LOGFILENAME
do_exit 36
fi
CURRENT_ESX_STATE=$RET_UNINSTALL
else
echo " " | tee -a $LOGFILENAME
echo " The ESX host will be put into maintenance mode " | tee -a $LOGFILENAME
echo " to be able to install/uninstall the agents." | tee -a $LOGFILENAME
echo " The Virtual Machines must be either Powered off or Suspended " | tee -a $LOGFILENAME
echo " by the operator to allow the transition " | tee -a $LOGFILENAME
echo " of the ESX host into maintenance mode. " | tee -a $LOGFILENAME
echo " Please modify the state of the VMs to be Suspended or powered off " | tee -a $LOGFILENAME
echo " and then retry Agents $OPERATION_REQUESTED." | tee -a $LOGFILENAME
echo " " | tee -a $LOGFILENAME
do_exit 137
fi
}
reset_host() {
# called from do_exit. exit will be made from do_exit
check_esx_host_maintenancemode
RET_UNINSTALL=$?
if [ $RET_UNINSTALL = $nSTAT_ESX_MAINT_ON ]; then
unset_esx_host_maintenancemode
else
return $RET_UNINSTALL
fi
# This is only after unsetting the maintenance mode
check_esx_host_maintenancemode
RET_UNINSTALL=$?
if [ $RET_UNINSTALL = $nSTAT_ESX_MAINT_OFF ]; then
echo "ESX host Maintenance mode is reset to normal." | tee -a $LOGFILENAME
return $RET_UNINSTALL
else
echo "ESX host Maintenance mode is NOT Reset cleanly. Manual fix is required." | tee -a $LOGFILENAME
return $nSTAT_ESX_MAINT_MODE_ERR
fi
}
vmops_list_vm() {
vim-cmd vmsvc/getallvms > $HPIM_VMLIST
}
check_state_of_vms() {
vmops_list_vm
declare LINE
total_count=0
count_vm_powered_off=0
count_vm_suspended=0
count_vm_active=0
exec 3< $HPIM_VMLIST
while read LINE <&3; do
# use VM_ID for VM commands and VM_NAME for display and logging
VM_ID=`echo $LINE | cut -d" " -f1`
VM_NAME=`echo $LINE | cut -d" " -f2`
if [ "$VM_ID" = "Vmid" ] ; then
continue
else
total_count=`expr $total_count + 1`
STATE=`vim-cmd vmsvc/power.getstate $VM_ID |grep Suspended|cut -d " " -f1`
STATE1=`vim-cmd vmsvc/power.getstate $VM_ID |grep "Powered off"|cut -d " " -f2`
if [ "$STATE1" = "off" ] ; then
echo Found VM [$VM_NAME] in Powered Off state >> $LOGFILENAME
count_vm_powered_off=`expr $count_vm_powered_off + 1`
elif [ "$STATE" = "Suspended" ] ; then
echo Found VM [$VM_NAME] in Suspended state >> $LOGFILENAME
count_vm_suspended=`expr $count_vm_suspended + 1`
else
count_vm_active=`expr $count_vm_active + 1`
echo " An active Virtual Machine [ $VM_NAME ] has been detected on host [$ESX_HOST_NAME]" | tee -a $LOGFILENAME
break
fi
fi
done
# echo Total number of VMs detected on system [$total_count]
# echo Number of VMS powered off [ $count_vm_powered_off ]
# echo Number of VMS suspended [ $count_vm_suspended ]
# echo Found active VM [ $count_vm_active ]
return $count_vm_active
}
configure_agents() {
# Assumption is no one tampered this system folder and the
# right config script is available in the agents config folder
pushd $AGENTS_CONFIG_FOLDER
if [ $? = 0 ]; then
# Get the Config script name. Shouldn't be any
# old configure scripts at this system location
CONFIG_SCRIPTNAME=`ls configure*`
if [ -z $CONFIG_SCRIPTNAME ]; then
echo "Config script doesn't exist" >> $LOGFILENAME
popd
return 2
elif [ -f $CONFIG_SCRIPTNAME ]; then
./$CONFIG_SCRIPTNAME $1 $2 $3
nSTAT_CONFIG_AGENTS_RET_VALUE=$?
fi
else
echo "[$AGENTS_CONFIG_FOLDER] doesn't exist" >> $LOGFILENAME
return 2
fi
popd
echo "Completed agents configuration with status [$nSTAT_CONFIG_AGENTS_RET_VALUE]" >> $LOGFILENAME
return $nSTAT_CONFIG_AGENTS_RET_VALUE
}
find_pkg_info()
{
# query Bulletin Id and ReleaseDate from the agents package
PKG_BULLETIN_ID=`esxupdate info --bundle=$OFFLINE_BUNDLE_NAME | grep $ID_TAG | cut -b22-`
PKG_REL_DATE=`esxupdate info --bundle=$OFFLINE_BUNDLE_NAME | grep $RELDATE_TAG`
if [ -z "$PKG_BULLETIN_ID" ]; then
PKG_BULLETIN_ID=UNK_UNK_BULLETIN
echo "$HP_AGENTS_GENERIC_NAME Bulletin ID error in offline bundle." >> $LOGFILENAME
setfailure
do_exit $nSTAT_PKG_BLTN_ERR
fi
}
compare_relDates()
{
BLTN_REL_DATE=`esxupdate info -b $1 | grep $RELDATE_TAG`
# bNewPackage=0 is old package
bNewPackage=0
bSameDate=0
echo "Comparing Package Releasedate [$PKG_REL_DATE] with Bulletin Releasedate [$BLTN_REL_DATE]." >> $LOGFILENAME
CUR_PKG_MONTH=`echo $PKG_REL_DATE | cut -d"-" -f2`
CUR_PKG_DAY=`echo $PKG_REL_DATE | cut -d"-" -f3`
CUR_PKG_YEAR=`echo $PKG_REL_DATE | cut -d"-" -f4`
BLTN_MONTH=`echo $BLTN_REL_DATE | cut -d"-" -f2`
BLTN_DAY=`echo $BLTN_REL_DATE | cut -d"-" -f3`
BLTN_YEAR=`echo $BLTN_REL_DATE | cut -d"-" -f4`
if [ $CUR_PKG_YEAR -gt $BLTN_YEAR ] ; then
echo "CUR_PKG_YEAR [$CUR_PKG_YEAR] is greater than BLTN_YEAR [$BLTN_YEAR]." >> $LOGFILENAME
bNewPackage=1
return $bNewPackage
elif [ $CUR_PKG_YEAR -eq $BLTN_YEAR ] ; then
echo "CUR_PKG_YEAR [$CUR_PKG_YEAR] is equal to BLTN_YEAR [$BLTN_YEAR]." >> $LOGFILENAME
bSameDate=1
fi
if [ -n $bSameDate ] ; then
bSameDate=0
if [ $CUR_PKG_MONTH -gt $BLTN_MONTH ]; then
echo "CUR_PKG_MONTH [$CUR_PKG_MONTH] is greater than BLTN_MONTH [$BLTN_MONTH]." >> $LOGFILENAME
bNewPackage=1
return $bNewPackage
elif [ $CUR_PKG_MONTH -eq $BLTN_MONTH ]; then
echo "CUR_PKG_MONTH [$CUR_PKG_MONTH] is equal to BLTN_MONTH [$BLTN_MONTH]." >> $LOGFILENAME
bSameDate=2
fi
fi
if [ -n $bSameDate ] ; then
bSameDate=0
if [ $CUR_PKG_DAY -gt $BLTN_DAY ]; then
echo "CUR_PKG_DAY [$CUR_PKG_DAY] is greater than BLTN_DAY [$BLTN_DAY]." >> $LOGFILENAME
bNewPackage=1
return $bNewPackage
elif [ $CUR_PKG_DAY -eq $BLTN_DAY ]; then
echo "CUR_PKG_DAY [$CUR_PKG_DAY] is equal to BLTN_DAY [$BLTN_DAY]." >> $LOGFILENAME
bSameDate=3
fi
fi
if [ $bSameDate = 3 ] ; then
return $bSameDate
else
return $bNewPackage
fi
}
is_bulletin_same_or_new()
{
# By design there should be only one bulletin in the list.
# for loop is to handle error cases also
for iBulletin in $ESX_BULLETIN_ID; do
# Compare installed Bulletin ID with the ID from Package
if [ "$iBulletin" = "$PKG_BULLETIN_ID" ]; then
echo "Attempted bundle [$PKG_BULLETIN_ID] is same as the currently installed bundle [$iBulletin]. NO ACTION TAKEN." | tee -a $LOGFILENAME
do_exit $nSTAT_BLTN_SAME
else
# compare_relDates gives us info about the old package. Same package case is handled above
compare_relDates $iBulletin
CMP_RESULT=$?
if [ $CMP_RESULT = 3 ] ; then
echo "Attempted bundle [$PKG_BULLETIN_ID] has same release date as the currently installed bundle [$iBulletin]. NO ACTION TAKEN." | tee -a $LOGFILENAME
do_exit $nSTAT_BLTN_SAME
elif [ $CMP_RESULT != 1 ] ; then
echo "Attempted bundle [$PKG_BULLETIN_ID] is older than the currently installed bundle [$iBulletin]. NO ACTION TAKEN." | tee -a $LOGFILENAME
do_exit $nSTAT_PKG_BLTN_OLD
fi
fi
done
}
count_bulletin_list()
{
TMP_BLTN_LIST=$1
cBlntId=0
for iBulletin in $TMP_BLTN_LIST; do
cBltnId=$(expr $cBltnId + 1)
done
len=$(expr $cBltnId - 1)
return $len
}
query_bulletin()
{
# query the installed Bulletin Id from the ESX host
ESX_BULLETIN_ID=`esxupdate query | grep $BULLETIN_ID_TOKEN | cut -d" " -f1`
if [ -z "$ESX_BULLETIN_ID" ]; then
# echo "$HP_AGENTS_GENERIC_NAME Bulletin not found." >> $LOGFILENAME
# setfailure
return $nSTAT_BLTN_NOT_FOUND
else
count_bulletin_list $ESX_BULLETIN_ID
NUM_BLTNS=$?
if [ $NUM_BLTNS -gt 1 ]; then
echo "More than 1 bulletin found. Num found - [$NUM_BLTNS]." >> $LOGFILENAME
return $nSTAT_MULTI_BLTN_FOUND
else
# echo "[$ESX_BULLETIN_ID] bulletin found." >> $LOGFILENAME
return $nSTAT_BLTN_FOUND
fi
fi
}
remove_bulletin() {
nSTAT_REMOVE_BULLETIN=$nSTATUS_SUCCESS
for iBulletin in $ESX_BULLETIN_ID; do
echo "Removing [$iBulletin] ..." >> $LOGFILENAME
esxupdate -b $iBulletin remove >> $LOGFILENAME 2>&1
bInstallStatus=$?
if [ $bInstallStatus -eq 0 ]; then
echo "Removed Bulletin - [$iBulletin]" >> $LOGFILENAME
setsuccess
elif [ $bInstallStatus -eq $nSTAT_ESX_REBOOT_REQ ] ; then
ESX_HOST_REBOOT_REQ=$bInstallStatus
echo $HP_AGENTS_GENERIC_NAME bulletin uninstalled with esxupdate status [$bInstallStatus]. >> $LOGFILENAME
setsuccess
else
# If a Bulletin is not removed, continue with the rest
# Finally return this error to indicate the failure
echo "Unable to remove [$iBulletin]. esxupdate status [$bInstallStatus]" >> $LOGFILENAME
setfailure
nSTAT_REMOVE_BULLETIN=$bInstallStatus
fi
done
return $nSTAT_REMOVE_BULLETIN
}
uninstall_bulletin() {
query_bulletin
nQUERY_STATUS=$?
if [ $nQUERY_STATUS -eq 0 ]; then
echo "Uninstalling $HP_AGENTS_GENERIC_NAME bulletin [$ESX_BULLETIN_ID] ... " | tee -a $LOGFILENAME
remove_bulletin
nSTAT_UNINSTALL=$?
if [ $nSTAT_UNINSTALL != $nSTATUS_SUCCESS ]; then
echo $HP_AGENTS_GENERIC_NAME Bulletin uninstall [$ESX_BULLETIN_ID] FAILED with status [$nSTAT_UNINSTALL] >> $LOGFILENAME
do_exit $nSTAT_UNINSTALL
fi
else
echo "Bulletin not found"
echo "Bulletin not found" >> $LOGFILENAME
do_exit $nQUERY_STATUS
fi
}
install_bulletin() {
# esxupdate --bundle=hpmgmt.zip $VIB_SIGNED_SW --nocache --maintenancemode update >> $LOGFILENAME 2>&1
esxupdate --bundle=hpmgmt.zip $VIB_SIGNED_SW --nocache update >> $LOGFILENAME 2>&1
# bInstallStatus will be used to later decide on reboot message
bInstallStatus=$?
# return status 80 (nSTAT_ESX_REBOOT_REQ) is for reboot request and 0 is success.
# hpilo installation requires a system reboot for driver updates
if [ $bInstallStatus -eq $nSTAT_ESX_REBOOT_REQ ] ; then
ESX_HOST_REBOOT_REQ=$bInstallStatus
echo $HP_AGENTS_GENERIC_NAME bulletin installed with esxupdate status [$bInstallStatus]. >> $LOGFILENAME
setsuccess
elif [ $bInstallStatus -eq 0 ] ; then
echo $HP_AGENTS_GENERIC_NAME bulletin installed with esxupdate status [$bInstallStatus]. >> $LOGFILENAME
setsuccess
else
echo Installation of $HP_AGENTS_GENERIC_NAME bulletin FAILED. esxupdate status [$bInstallStatus] >> $LOGFILENAME
setfailure
do_exit $bInstallStatus
fi
return $bInstallStatus
echo "" >> $LOGFILENAME
}
install() {
# Both Install and reinstall scenarios are handled
# [[ ! $SILENT ]] && verify_action "install"
[[ ! $SILENT ]] && verify_host_action "install"
echo "" | tee -a $LOGFILENAME
set_host
# Check for installed
# check_installed_pkgs
# find_pkg_info and query_bulletin need to be run before
# using any bulletin ID comparisions
find_pkg_info
query_bulletin
nQUERY_STATUS=$?
if [ $nQUERY_STATUS -eq $nSTAT_MULTI_BLTN_FOUND ]; then
echo "$HP_AGENTS_GENERIC_NAME Multiple Bulletins [$ESX_BULLETIN_ID] found. ERROR." | tee -a $LOGFILENAME
do_exit $nSTAT_MULTI_BLTN_FOUND
elif [ $nQUERY_STATUS -eq $nSTAT_BLTN_FOUND ]; then
echo "$HP_AGENTS_GENERIC_NAME [$ESX_BULLETIN_ID] is installed"
echo $HP_AGENTS_GENERIC_NAME [$ESX_BULLETIN_ID] is installed >> $LOGFILENAME
is_bulletin_same_or_new
echo "Uninstalling installed $HP_AGENTS_GENERIC_NAME bulletin [$ESX_BULLETIN_ID]" | tee -a $LOGFILENAME
uninstall
nERR=$?
if [ $nERR -ne $nSTATUS_SUCCESS ]; then
echo "Uninstall failed [$nERR]. ERROR" >> $LOGFILENAME
do_exit $nERR
fi
# query for bulletin again to make sure uninstall worked
# and ESX doesnt have any traces of old IDs.
query_bulletin
if [ $? -eq $nSTAT_BLTN_FOUND ]; then
echo "Bulletin found after Uninstall. ERROR" >> $LOGFILENAME
do_exit $nSTAT_UNINSTALL_ERR
fi
fi
echo Installing $HP_AGENTS_GENERIC_NAME bulletin [$PKG_BULLETIN_ID] | tee -a $LOGFILENAME
# Return value from install_bulletin is good case values. Error case will stop program execution
install_bulletin
RET_INSTALL=$?
return $RET_INSTALL
}
uninstall() {
if [[ ! $SILENT ]]; then
# echo NON silent mode, prompt for confirmation
# verify_action "uninstall"
verify_host_action "uninstall"
fi
set_host
echo "" | tee -a $LOGFILENAME
# Before removing vibs, unconfigure the agents
configure_agents --uninstall
# Agents are unconfigured, uninstall binaries
uninstall_bulletin
}
prompt_reboot() {
if [ $ESX_HOST_REBOOT_REQ -eq $nSTAT_ESX_REBOOT_REQ ]; then
$SETCOLOR_WARNING
echo ""
# echo -e "\tHP SNMP agents are installed and configured"
echo -e "\tHP SNMP agents are $1"
echo -e "\tReboot the system to make the changes effective."
echo ""
$SETCOLOR_NORMAL
fi
}
usage() {
echo "Usage:"
echo ""
echo "${0} {--install|--uninstall|--silent} [--inputfile filename]"
echo ""
echo -e "--install:"
echo -e "\tThis will attempt to install version ${VERSION_NAME}${MINOR_VERSION}"
echo -e "\tof the HP Insight Manager Agents VIBs. If a previous version of the agents"
echo -e "\tare detected, the previous version of the agents will be uninstalled"
echo -e "\tbefore installing version ${VERSION_NAME}."
echo ""
echo -e "--uninstall:"
echo -e "\tThis will attempt to uninstall the HP Insight Manager Agents VIBs"
echo -e "\tfrom the system."
echo ""
echo -e "--silent"
echo -e "\tThis will attempt a silent installation of the HP Insight"
echo -e "\tManager Agents VIBs. If a previous version of the agents"
echo -e "\tare detected, the previous version of the agents will be uninstalled"
echo -e "\tbefore installing version ${VERSION_NAME}. This option also requires"
echo -e "\tthe '--inputfile' option where filename points to the"
echo -e "\tconfiguration file that contains the settings."
echo -e "\tPlease see the README and the hpmgmt.conf.example files"
echo -e "\tfor more details."
do_exit $nSTAT_CMD_ERROR
}
echo -e "\n********** [`date`] **********\n" >> $LOGFILENAME
splash
#
# get the intial state of the ESX host
#
check_esx_host_maintenancemode
INITIAL_ESX_STATE=$?
CURRENT_ESX_STATE=$INITIAL_ESX_STATE
case "$1" in
--silent)
OPERATION_REQUESTED="Installation"
SILENT=1
if [ "$2" != "--inputfile" ] ; then
usage
elif [ ! -e "$3" ]; then
echo $3
echo "Input file does not exist!" | tee -a $LOGFILENAME
do_exit 20;
elif [ "$4" != "" ]; then
usage
else
AGENTS_CONFIG_ARG1=$1
AGENTS_CONFIG_ARG2=$2
AGENTS_CONFIG_ARG3=$3
# . $3
fi
# Install vibs/bulletin
install
# Without installing the VIBs the config file is not available.
# Providing another config file in the top install folder as a special case
# for silent mode installs. Copy this file to $AGENTS_CONFIG_FOLDER
# copy Input file to $AGENTS_CONFIG_FOLDER folder
cp $AGENTS_CONFIG_ARG3 $AGENTS_CONFIG_FOLDER/$HP_IM_AGENTS_CONF_FILE
if [ -f $AGENTS_CONFIG_FOLDER/$HP_IM_AGENTS_CONF_FILE ]; then
echo "Executing - configure_agents $AGENTS_CONFIG_ARG1 $AGENTS_CONFIG_ARG2 $HP_IM_AGENTS_CONF_FILE" >> $LOGFILENAME
configure_agents $AGENTS_CONFIG_ARG1 $AGENTS_CONFIG_ARG2 $HP_IM_AGENTS_CONF_FILE
nSTAT_CONFIG_AGENTS=$?
if [ $nSTAT_CONFIG_AGENTS -ne 0 ]; then
echo "Configuration of agents failed. Error [ $nSTAT_CONFIG_AGENTS] " >> $LOGFILENAME
rm -f $AGENTS_CONFIG_FOLDER/$HP_IM_AGENTS_CONF_FILE
uninstall_bulletin
do_exit $nSTAT_CONFIG_AGENTS
else
rm -f $AGENTS_CONFIG_FOLDER/$HP_IM_AGENTS_CONF_FILE
prompt_reboot "installed and configured"
fi
else
echo "Could not copy config file!" | tee -a $LOGFILENAME
do_exit 20;
fi
;;
--install)
OPERATION_REQUESTED="Installation"
if [ "$2" != "" ]; then
usage
else
AGENTS_CONFIG_ARG1=$1
# Install vibs/bulletin
install
# After vib installation configure the agents
configure_agents $AGENTS_CONFIG_ARG1
nSTAT_CONFIG_AGENTS=$?
if [ $nSTAT_CONFIG_AGENTS -ne 0 ]; then
echo "Configuration of agents failed. Error [ $nSTAT_CONFIG_AGENTS] " >> $LOGFILENAME
uninstall_bulletin
do_exit $nSTAT_CONFIG_AGENTS
else
# Remind users for a reboot. As hpilo driver install requires a reboot
prompt_reboot "installed and configured"
fi
fi
;;
--uninstall)
OPERATION_REQUESTED="Uninstallation"
if [ "$2" != "" ]; then
usage
else
uninstall
# Remind users for a reboot. As hpilo driver uninstall may require a reboot on ESX 4.1
prompt_reboot "uninstalled"
fi
;;
*)
OPERATION_REQUESTED="Usage"
usage
;;
esac
do_exit 0
Is it possible to just put the host into mainteance as part of your %post but don't apply the HP patches until firstboot and create an init script that runs at the very end? (e.g. S999999InstallHPStuff)? I'm wondering if it's just having some issues around maintenance mode and then running the script ...
Hi Lawm,
Yep I can try that and let you know... the other odd thing that relates to this is that my scripted section for creating user accounts doesnt work. All the users get created with group memberships as specified, the only thing is the password doesnt get recognised and I have to manually reset the user password after they are created inorder for them to work. Again, if I run this scrip line by line after the build manually, it works just fine including password. When I run the script the account passwords are created as 3DES... when commands are run manualy the account passwords are created as MD5, not sure why the difference, the lines are same in both methods...
Just these two niggly things in my script that arent working as expected, and I cant figure out why.
Thanks for your help so far.
Lamw, i've been spelling your name wrong... apologies about that.
lamw, still the same thing... eve if I put the ESX server into maintenance mode before running the HP script, it still fails... how does everyone else fully automate their builds i wonder...?
Hi so how to be breif and informative here. I also have HP SIM install and do so with automation as part of the load. To be honest I do as little as possible in the ks.cfg portion in %post. I do have it put a rc script out as suggested S9999blah that runs post reboot and that does the work including cleanup. I have found the extra reboot(s) may be needed espcially if you use esxupdate for patching. here are some key things to note:
Putting things into maintenance mode required hostd to be fully up and running which may take 50-90 second beyond percieved completion of boot.
Next be aware that HP SIM is very particular as to build number. In fact if you are patching as I do the build number changes but NOT until after reboot.
So if you install HP-SIM to match your final post patching build number, before you reboot after patching, it will fail plain and simple. If you are patching to update, you may even have to uninstall HPSIM N-1 and then reboot post patching in oder to install the N version of HP-SIM properly. Multiple reboots can solve things but do get messy.
So a healthy sleep post rebooting a host never goes amiss, should you plan to do any commands like maintence mode, which HP-SIM does in fact do, just like good patching scripts will do.
In the end, simple right? So I am new to posting, what is the ettiquette? May I say to contact me if you have questions? That is as long as you don't work for one of our competitors.