Changeset 95952b3


Ignore:
Timestamp:
05/03/13 10:43:08 (18 months ago)
Author:
Kris Moore <kris@…>
Branches:
master, 9.2-release, releng/10.0, releng/10.0.1, releng/10.0.2, releng/10.0.3
Children:
460cf4d
Parents:
fda1ea4
Message:

Welcome the new template system to creating jails!

Now you can create jail templates, and then select which template to use
when you create a new jail. Tested it all the way back to FreeBSD 4.1.1 ;)

Location:
src-sh/warden/scripts/backend
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src-sh/warden/scripts/backend/createjail.sh

    rfda1ea4 r95952b3  
    8787esac 
    8888 
    89 # Location of the chroot environment 
    90 isDirZFS "${JDIR}" 
    91 if [ $? -eq 0 ] ; then 
    92   WORLDCHROOT_PLUGINJAIL="${JDIR}/.warden-pj-chroot-${ARCH}" 
    93   WORLDCHROOT_STANDARD="${JDIR}/.warden-chroot-${ARCH}" 
    94 else 
    95   WORLDCHROOT_PLUGINJAIL="${JDIR}/.warden-pj-chroot-${ARCH}.tbz" 
    96   WORLDCHROOT_STANDARD="${JDIR}/.warden-chroot-${ARCH}.tbz" 
    97 fi 
    98 if [ "${PLUGINJAIL}" = "YES" ] ; then 
    99   WORLDCHROOT="${WORLDCHROOT_PLUGINJAIL}" 
    100 else 
    101   WORLDCHROOT="${WORLDCHROOT_STANDARD}" 
    102 fi 
    103 export WORLDCHROOT WORLDCHROOT_PLUGINJAIL WORLDCHROOT_STANDARD 
     89# See if we need to create a default template 
     90# If using a ARCHIVEFILE we can skip this step 
     91if [ -z "$TEMPLATE" -a -z "$ARCHIVEFILE" ] ; then 
     92  DEFTEMPLATE="`uname -r | cut -d '-' -f 1-2`-${ARCH}" 
     93 
     94  # If on a plugin jail, lets change the nickname 
     95  if [ "${PLUGINJAIL}" = "YES"  ] ; then 
     96    DEFTEMPLATE="${DEFTEMPLATE}-pluginjail" 
     97  fi 
     98 
     99  # See if we need to create a new template for this system 
     100  isDirZFS "${JDIR}" 
     101  if [ $? -eq 0 ] ; then 
     102     TDIR="${JDIR}/.warden-template-$DEFTEMPLATE" 
     103  else 
     104     TDIR="${JDIR}/.warden-template-$DEFTEMPLATE.tbz" 
     105  fi 
     106  if [ ! -e "$TDIR" ] ; then 
     107      FLAGS="-arch $ARCH -nick $DEFTEMPLATE" 
     108 
     109      uname -r 2>&1 | grep -q "TRUEOS" 
     110      if [ $? -eq 0 ] ; then 
     111         FLAGS="-trueos `uname -r | cut -d '-' -f 1-2` $FLAGS" ; export FLAGS 
     112      else 
     113         FLAGS="-fbsd `uname -r | cut -d '-' -f 1-2` $FLAGS" ; export FLAGS 
     114      fi 
     115 
     116      if [ "${PLUGINJAIL}" = "YES" ] ; then 
     117         FLAGS="$FLAGS -pluginjail" 
     118      fi 
     119      ${PROGDIR}/scripts/backend/createtemplate.sh ${FLAGS} 
     120      if [ $? -ne 0 ] ; then 
     121        exit_err "Failed create default template" 
     122      fi 
     123  fi 
     124  WORLDCHROOT="${TDIR}" 
     125elif [ -z "$ARCHIVEFILE" ] ; then 
     126  # Set WORLDCHROOT to the dir we will clone / file to extract 
     127  WORLDCHROOT="${JDIR}/.warden-template-$TEMPLATE" 
     128  isDirZFS "${JDIR}" 
     129  if [ $? -ne 0 ] ; then 
     130    WORLDCHROOT="${WORLDCHROOT}.tbz" 
     131  fi 
     132else  
     133   # See if we are overriding the default archive file 
     134   WORLDCHROOT="$ARCHIVEFILE" 
     135fi 
    104136 
    105137if [ "${IP4}" != "OFF" ] ; then 
     
    115147  MASK6="${JMASK}" 
    116148  if [ -z "$MASK6" ] ; then MASK6="64"; fi 
    117 fi 
    118  
    119 # See if we are overriding the default archive file 
    120 if [ ! -z "$ARCHIVEFILE" ] ; then 
    121    WORLDCHROOT="$ARCHIVEFILE" 
    122149fi 
    123150 
     
    156183done 
    157184: $(( META_ID += 1 )) 
    158  
    159 # Check if we need to download the chroot file 
    160  
    161 # 
    162 # If this is a pluginjail, we clone a regular freebsd chroot, then we 
    163 # bootstrap packageng, install the required packages that a pluginjail 
    164 # needs, then snapshot it. Once this is done, creating a pluginjail is 
    165 # as easy as doing a zfs clone. 
    166 # 
    167 if [ "${PLUGINJAIL}" = "YES" -a ! -e "${WORLDCHROOT}" -a -z "$TEMPLATE" ] ; then 
    168   if [ ! -e "${WORLDCHROOT_STANDARD}" ] ; then 
    169     downloadchroot "${WORLDCHROOT_STANDARD}" 
    170   fi 
    171  
    172   isDirZFS "${JDIR}" 
    173   if [ $? -eq 0 ] ; then 
    174     tank=`getZFSTank "$JDIR"` 
    175     zfsp=`getZFSRelativePath "${WORLDCHROOT_STANDARD}"` 
    176     clonep="/$(basename ${WORLDCHROOT_PLUGINJAIL})" 
    177  
    178     mnt=`getZFSMountpoint ${tank}` 
    179     pjdir="${mnt}${clonep}" 
    180  
    181     zfs clone ${tank}${zfsp}@clean ${tank}${clonep} 
    182     if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS pluginjail clone"; fi 
    183  
    184     cp /etc/resolv.conf ${pjdir}/etc/resolv.conf 
    185  
    186     bootstrap_pkgng "${pjdir}" "pluginjail" 
    187  
    188     zfs snapshot ${tank}${clonep}@clean 
    189     if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS pluginjail snapshot"; fi 
    190  
    191   # We're on UFS :-( 
    192   else 
    193     downloadchroot "${WORLDCHROOT_STANDARD}" 
    194  
    195   fi 
    196  
    197 elif [ ! -e "${WORLDCHROOT}" -a "${LINUXJAIL}" != "YES" -a -z "$TEMPLATE" ] ; then 
    198   downloadchroot "${WORLDCHROOT}" 
    199 fi 
    200185 
    201186# If we are setting up a linux jail, lets do it now 
     
    218203 
    219204echo "Building new Jail... Please wait..." 
    220  
    221 # Are we using a jail template to build / clone? 
    222 if [ -n "$TEMPLATE" ] ; then 
    223    # Reset WORLDCHROOT to the dir we will clone / file to extract 
    224    WORLDCHROOT="${JDIR}/.warden-template-$TEMPLATE" 
    225    isDirZFS "${JDIR}" 
    226    if [ $? -ne 0 ] ; then 
    227      WORLDCHROOT="${WORLDCHROOT}.tbz" 
    228    fi 
    229 fi 
    230205 
    231206isDirZFS "${JDIR}" 
  • src-sh/warden/scripts/backend/createtemplate.sh

    r411e12f r95952b3  
    100100    fi 
    101101 
     102    # Creating a plugin jail? 
     103    if [ "$TPLUGJAIL" = "YES" ] ; then 
     104      cp /etc/resolv.conf ${TDIR}/etc/resolv.conf 
     105      bootstrap_pkgng "${TDIR}" "pluginjail" 
     106    fi 
     107 
    102108    zfs snapshot ${tank}${zfsp}@clean 
    103109    if [ $? -ne 0 ] ; then exit_err "Failed creating clean ZFS base snapshot"; fi 
     
    117123      cat ${oldStr}.?? | tar --unlink -xpzf - -C ${JDIR}/.templatedir 2>/dev/null 
    118124      cd ${JDIR} 
     125 
     126      # Creating a plugin jail? 
     127      if [ "$TPLUGJAIL" = "YES" ] ; then 
     128        cp /etc/resolv.conf ${JDIR}/.templatedir/etc/resolv.conf 
     129        bootstrap_pkgng "${JDIR}/.templatedir/" "pluginjail" 
     130      fi 
     131 
    119132      echo "Creating template archive..." 
    120133      tar cvjf ${TDIR} -C ${JDIR}/.templatedir 2>/dev/null 
     
    133146      done 
    134147 
     148      # Creating a plugin jail? 
     149      if [ "$TPLUGJAIL" = "YES" ] ; then 
     150        cp /etc/resolv.conf ${JDIR}/.templatedir/etc/resolv.conf 
     151        bootstrap_pkgng "${JDIR}/.templatedir/" "pluginjail" 
     152      fi 
     153 
    135154      echo "Creating template archive..." 
    136155      tar cvjf ${TDIR} -C ${JDIR}/.templatedir 2>/dev/null 
     
    168187           if [ -z "$1" ] ; then exit_err "No nickname specified"; fi 
    169188           TNICK="${1}" 
     189           ;; 
     190 -pluginjail) shift 
     191           TPLUGJAIL="YES" 
    170192           ;; 
    171193        *) exit_err "Invalid option: $1" ;; 
     
    229251create_template 
    230252 
     253exit 0 
Note: See TracChangeset for help on using the changeset viewer.