View Single Post
  #1   (View Single Post)  
Old 9th May 2008
cajunman4life cajunman4life is offline
Real Name: Aaron Graves
Package Pilot
Join Date: May 2008
Location: Coolidge, Arizona
Posts: 203
Default Keeping ports in multiple jails up to date

This might possibly belong in the guides section. If that's the case, then feel free to move mods

At any rate, I'm sitting here bored at work again. So I set out to solve one of the problems I've been thinking (admittedly not to heavily) about the last few days. I've recently begun using jails (specifically ezjail) more and more lately, and with all the different ports that I install in each one, it's becoming increasingly difficult to make sure each one is up-to-date.

On the host system I have a simple script that checks for updates:
/usr/sbin/pkg_version -v -L '='
This will output a nice list of the ports installed that are out of date. Using this list I can determine which, if any of these, actually needs to be updated (was it a security/bugfix, or did someone just bump something to the latest version and by upgrading I could potentially break other things?).

So, how can I also check my jails without having to manually log in to each jail and run the above command? Well, the "usual" way that is. By writing a shell script.

Background information: I don't have a ports tree installed in any of my jails. /usr/ports/ is an empty directory, and I use mount_nullfs to mount the ports tree on the host system to each jail.

Without further ado, here is my shell script. Feel free to use it yourself if you'd like (note however that it is "beerware", so if you're ever in the Phoenix metro area you'll be required to buy me a beer... or not ).

# CVAll - checkver all - Checks for available updates on all jails.
# Written by Aaron Graves - 05/09/2008
#  Let's just call this a release under the beerware license.
#  No need to be all formal and such.

# First step, see if we're running as root. If not, then complain and exit.
if [ `whoami` != "root" ]; then
        echo 1>&2 ERROR: This command must be run by root...
        exit 1

# Now that we've got that nasty business out of the way, let's mount the ports
#  tree to all jails.
echo -n "Mounting ports tree to all jails: "
./mports all > /dev/null
echo "Done."
echo ""

# Now we'll go step by step through each jail to check for updates...
for i in `jls | grep -v "JID" | awk '{print $3}'`
        echo "Checking for available updates on $i, please wait..."
        jexec -U root `jls | grep $i | awk '{print $1}'` /usr/sbin/pkg_version -v -L '='
        echo "Done."
        echo ""

# Now, unmount all ports
echo -n "Unmounting ports tree from all jails: "
./umports all > /dev/null
echo "Done."
An additional note: The "mports" and "umports" above references a few other scripts I've written which goes through and does mount_nullfs for each of the jails I have installed to mount the ports tree. If anyone's interested I can post the code for those scripts (or you can replace those sections with whatever code you want to use to mount the ports tree).

Any questions/comments can be directed back towards me. Enjoy!
I just saved a bunch of money on my car insurance by fleeing the scene of the accident!
Reply With Quote