Monday, August 27, 2012

Updating a OpenIndiana (Solaris) machine that is running several ipkg zones

Updating an OpenIndiana/Illumos/OpenSolaris/Solaris machine that is running many ipkg zones can be a daunting task.

I have one machine that is running 18 zones (and the global one to boot).

When the global zone has been updated, the rest of the zones need to be updated as well. Each and every one, one by one.

Which is why I wrote the following script which I wish to share. If you find it useful, enjoy :) If you improve it, please do tell me, and please share the improvements - it's not a requirement, but it's a nice gesture.

***** Start script *****


#!/bin/bash
#
# Author      : Þór Sigurðsson
# Date        : 2012-08-02
# Written For : Belgingur

# Description : The intent of this script is to run boot-environment updates on OpenIndiana.
#               It should make certain that some things are "kosher", but it doesn't attempt any
#               damage control at the moment. That is done via the ZFS snapshots which are an
#               integral part of the update process.
#
# Version 1.0

PATH=/usr/gnu/bin:/usr/bin:/usr/sbin:/sbin
export PATH

BEMNT=/bemnt     # where we want to mount the boot environment after update

MYID=$(whoami)
if [ "${MYID}x" != "rootx" ]
then
    echo "Must be root to run this script."
    exit 1
fi

# All kinds of tests on the $BEMNT
#
# does it exist?
if [ ! -d ${BEMNT} ] ; then
    mkdir ${BEMNT}
    RV=$?
    if [ $RV -ne 0 ] ; then
        echo "Could not make directory ${BEMNT}"
        exit 1
    fi
fi
# is it empty ?
if [ "$(ls -A ${BEMNT})" ] ; then
    echo "${BEMNT} is not empty. Either another update is being performed,"
    echo "the last update failed miserably, or you have chosen an unwise"
    echo "location to use as the mount-point for the boot evironment update."
    echo "Please investigate, revise and repeat."
    exit 2
fi

RILI=$(zoneadm list -cv | grep -v STATUS | grep -v global | awk '{printf("%s ",$4);}')

BENAME=$1
if [ "${BENAME}x" == "x" ] ; then
    echo "Usage: $0 bename"
    echo "Where bename is the boot environment name you wish to use."
    exit 3
fi

echo "Starting update of GLOBAL environment"

pkg image-update --be-name ${BENAME}

if [ "${RILI}" ] ; then

    echo "Mounting boot environment"

    beadm mount ${BENAME} ${BEMNT}

    echo "Now, updating the zones, one by one..."

    for ZUP in ${RILI} ; do
        ZNA=$(echo $ZUP | gawk -F '/' '{print $4}')
        echo "Updating $ZNA"
        pkg -R ${BEMNT}${ZUP}/root image-update
    done

    echo "Unmounting boot environment"

    beadm umount ${BENAME}

else
    echo "There are no zones, so there's nothing to do here. The global is already updated."
fi

# if the ${BEMNT} still exists, we should rmdir it, since we don't want an empty arbitrary directory 
# just lying around..

rmdir ${BEMNT}

echo "Done."
echo
echo "It would most probably be a very good idea to reboot at this moment. Thank you :-)"
echo
exit 0

***** End Script *****

I hope you find it useful - I did :)

Wednesday, August 22, 2012

Tilraun til að selja á eBay

Í dag gerði ég fyrstu tilraun til þess að selja á eBay. Mér skilst að maður eigi að fá fyrstu 10 sölurnar (eða 50, eftir því hvar maður skoðar) frítt (þ.e. frír auglýsingakostnaður, en svo borgar maður bara prósentu ef varan selst) - en einhverra hluta vegna þurfti ég nú samt að borga fimmtíu sent.

Ekkert stórmál - það er bara að sjá hvort þetta seljist eða hvort einhver áhugi sé fyrir hendi :)

Varan er þessi:    HP Hewlett Packard PA-8700 750 MHz (A6688A) Processor