DaemonForums  

Go Back   DaemonForums > Miscellaneous > Guides

Guides All Guides and HOWTO's.

Reply
 
Thread Tools Display Modes
  #1   (View Single Post)  
Old 10th September 2008
anomie's Avatar
anomie anomie is offline
Local
 
Join Date: Apr 2008
Location: Texas
Posts: 446
Thanked 69 Times in 46 Posts
Default Updating FreeBSD Jails after rebuilding world on host

This is a simple script I put together to automate the monotonous - and potentially dangerous - process of updating your jails to stay in sync with their host system. This is the only purpose the script serves; it is not intended to be a comprehensive jail management utility (like ezjail, for example). Please use it only if you understand what it is doing. It performs a few basic sanity checks, but if you were to provide weird directory data to MYJAILS1 you could get into serious trouble.

As written, this script applies to FreeBSD 6.x and 7.0. It assumes:
  1. You've rebuilt world on the host system, as described in Chapter 23 The Cutting Edge.
  2. You haven't deleted files (i.e. cleanworld) from /usr/src on the host system after the successful build.
  3. You have installed the sysutils/cpdup port.
  4. You're running the script as root.

Code:
#!/bin/sh

# Author: anomie
# Date  : 2008-09-06

# Please see copyright at bottom of script

PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin

# Initialize MYJAILS1 with your Jails!   
# Do not use trailing slashes (/). 
########################################
MYJAILS1="/usr/home/jail/10.5.5.101 \
          /usr/home/jail/10.5.5.102 \
          /usr/home/jail/10.5.5.103" 
########################################

# Functions

chatter() {

  echo ${MSG1}
  echo '<Press Enter>'
  read DUMMY1
  echo ' ----------- '
  echo 'Working...'

}

# Quick audit to make sure Jails are stopped. 

JCHK1=$(jls)

if [ -n "${JCHK1}" ] ; then 
  echo 'Shut down all Jails and try again. Exiting...'
  exit 1
fi

# Iterate through all Jails: first back each Jail up, then 
# install world, then merge. 

for I in ${MYJAILS1} ; do

  if [ ! -e ${I} ] ; then
    MSG1="Bad Jail directory ${I} - skipping..."
    chatter
    continue 
  fi 

  if [ -e ${I}.dup ] ; then 
    chflags -R 0 ${I}.dup
    rm -rf ${I}.dup
  fi

  cpdup ${I} ${I}.dup

  if [ $? -ne 0 ] ; then 
    MSG1="Problem backing up ${I} - skipping to next Jail..."
    chatter
    continue 
  fi

  MSG1="Done backing up ${I}" 
  chatter

  cd /usr/src && make installworld DESTDIR=${I}

  if [ $? -ne 0 ] ; then 
    MSG1="installworld problem for ${I} - skipping to next Jail..."
    chatter
    continue 
  fi

  MSG1="Done installing world for ${I}"
  chatter

  mergemaster -iU -D ${I}

  if [ $? -ne 0 ] ; then 
    MSG1="merge problem for ${I} - skipping to next Jail..."
    chatter
    continue
  fi

  MSG1="Done merging files for ${I}"
  chatter

done

echo 'Finished!'

exit 0

# ---------------------------------
#  Copyright (c) 2008 anomie
#  All rights reserved.
#
#  Redistribution and use in source and binary forms, with or without
#  modification, are permitted provided that the following conditions
#  are met:
#  1. Redistributions of source code must retain the above copyright
#     notice, this list of conditions and the following disclaimer.
#  2. Redistributions in binary form must reproduce the above copyright
#     notice, this list of conditions and the following disclaimer in the
#     documentation and/or other materials provided with the distribution.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
#  ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
#  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
#  ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
#  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
#  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
#  OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
#  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
#  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
#  SUCH DAMAGE.
__________________
Kill your t.v.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rebuilding RAIDframe mirror after crash/power failure sherekhan OpenBSD Installation and Upgrading 7 25th September 2009 10:06 PM
jails, aliasing, router, and dmz? neurosis FreeBSD Security 17 7th November 2008 03:47 AM
Updating FreeBSD carpman FreeBSD Installation and Upgrading 6 26th October 2008 11:49 AM
Updating FreeBSD and Building a Custom Kernel bsdforlife FreeBSD Installation and Upgrading 8 16th August 2008 02:45 AM
Upgrading and rebuilding ALL packages/ports chill FreeBSD Ports and Packages 8 16th June 2008 04:55 AM


All times are GMT. The time now is 01:40 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick