Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Large update to warden backend.

1. Start by updating various commands, remove {zfs} prefix from them

2. Create a new "snap" sub-command, which will handle aspects of
   snapshot management, such as listing, creation, removal, reverting

3. Rewrite our "clone" functionality. Instead of just cloning to a
   new directory for the user to inspect, now you can run:

   # warden clone myjail newjail --ipv4=127.0.0.9/24

   This command will take an instant snapshot of "myjail" and clone it
   to the new jail "newjail", setting the new IP address optionally

4. Remove some legacy cloning cruft, and re-do help pages for all
   the effected commands

These changes mean that you can now create a master jail, and manually
or scripted create as many new "clones" of that jail as you like.
  • Loading branch information...
commit d2b5358e68fe53f53b3cf20b54904f47c5aaa330 1 parent fd6b78d
@kmoore134 kmoore134 authored
View
270 src-sh/warden/bin/warden
@@ -63,14 +63,9 @@ cat<<__EOF__
stop - Stops a jail
type - Set the jail type (pluginjail|portjail|standard)
template - Manage jail templates
- zfsmksnap - Create a ZFS snapshot of a jail
- zfslistclone - List clones of jail snapshots
- zfslistsnap - List snapshots of a jail
- zfsclonesnap - Clone a jail snapshot
- zfscronsnap - Schedule snapshot creation via cron
-zfsrevertsnap - Revert jail to a snapshot
- zfsrmclone - Remove a clone directory
- zfsrmsnap - Remove snapshot of a jail
+ snap - Jail snapshot management
+ clone - Clone an existing jail to a new jail
+ cron - Schedule snapshot creation via cron
__EOF__
};
@@ -169,67 +164,61 @@ Example:
"
};
-help_zfslistclone()
+help_snap()
{
title
- echo "Help zfslistclone
+ echo "Help snap
-List ZFS clones of a jail
+Perform Snapshot operations on a jail
-Usage:
+Available Sub-Commands: list make remove revert
- warden zfslistclone <Jail>
+list:
-Example:
+ warden snap list <jail>
- warden zfslistclone myjail
-"
-};
+make:
-help_zfslistsnap()
-{
- title
- echo "Help zfslistsnap
+ warden snap make <jail> <Optional Comment>
-List ZFS snapshots of a jail
+remove:
-Usage:
+ warden snap remove <jail> <snapshot>
- warden zfslistsnap <Jail>
+revert:
-Example:
+ warden snap revert <jail> <snapshot>
- warden zfslistsnap myjail
"
};
-help_zfsclonesnap()
+help_clone()
{
title
- echo "Help zfsclonesnap
+ echo "Help clone
-Clone a ZFS jail snapshot
+Clone an existing jail into a new jail with (optional) new IP address
Usage:
- warden zfsclonesnap <Jail> <SNAP>
+ warden clone <Jail> <NewJail>
Example:
- warden zfsclonesnap myjail 20120505-140510
+ warden clone myjail newjail --ipv4=127.0.0.4/24
"
};
-help_zfscronsnap()
+help_cronsnap()
{
title
- echo "Help zfscronsnap
+ echo "Help cronsnap
-Schedule a ZFS jail snapshot
+Schedule a jail snapshot
Usage:
- warden zfscronsnap <Jail> <action> <frequency> <daysToKeep>
+ warden cronsnap <Jail> <action> <frequency> <daysToKeep>
action = start / stop
frequency = daily / hourly
@@ -237,80 +226,11 @@ Usage:
Example:
- warden zfscronsnap myjail start daily 10
+ warden cronsnap myjail start daily 10
or
- warden zfscronsnap myjail stop
-"
-};
-
-help_zfsrevertsnap()
-{
- title
- echo "Help zfsrevertsnap
-
-Revert ZFS snapshot of a jail
-
-Usage:
-
- warden zfsrevertsnap <Jail> <SNAP>
-
-Example:
-
- warden zfsrevertsnap myjail 20120505-140510
-"
-};
-
-help_zfsrmclone()
-{
- title
- echo "Help zfsrmclone
-
-Remove ZFS clone of a jail
-
-Usage:
-
- warden zfsrmclone <Jail> <CLONE>
-
-Example:
-
- warden zfsrmclone myjail 20120505-140510
-"
-};
-
-help_zfsrmsnap()
-{
- title
- echo "Help zfsrmsnap
-
-Remove ZFS snapshot of a jail
-
-Usage:
-
- warden zfsrmsnap <Jail> <SNAP>
-
-Example:
-
- warden zfsrmsnap myjail 20120505-140510
-"
-};
-
-
-help_zfsmksnap()
-{
- title
- echo "Help zfsmksnap
-
-Create a new ZFS snapshot of a jail, with an optional comment
-
-Usage:
-
- warden zfsmksnap <Jail> <comment>
-
-Example:
-
- warden zfsmksnap myjail
+ warden cronsnap myjail stop
"
};
@@ -678,14 +598,9 @@ case "$1" in
type) help_type ;;
get) help_get ;;
set) help_set ;;
- zfsmksnap) help_zfsmksnap ;;
- zfslistsnap) help_zfslistsnap ;;
- zfslistclone) help_zfslistclone ;;
- zfsrevertsnap) help_zfsrevertsnap ;;
- zfsclonesnap) help_zfsclonesnap ;;
- zfscronsnap) help_zfscronsnap ;;
- zfsrmsnap) help_zfsrmsnap ;;
- zfsrmclone) help_zfsrmclone ;;
+ snap) help_snap ;;
+ cronsnap) help_cronsnap ;;
+ clone) help_clone ;;
*) help_main ;;
esac ;;
@@ -974,64 +889,7 @@ defaultrouter-ipv6) DEFAULTROUTER="${4}"
HOST=`basename "${IFILE}" | sed 's|\.wdn$||'`
- IP4="OFF"
- IP6="OFF"
- HOST="OFF"
- for i in "$@"
- do
- # Check if we have a new IPv4 address for this import
- echo "${i}" | grep '\-\-ipv4=' >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
- then
- tmp="`echo ${i} | cut -d '=' -f 2`"
- IP4="`echo ${tmp} | cut -d '/' -f 1 -s`"
- MASK4="`echo ${tmp} | cut -d '/' -f 2 -s`"
-
- #Sanity check on the IP
- if ! is_ipv4 "${IP4}" ; then
- exit_err "Invalid IPv4 address: $IP4"
- fi
-
- for i in `ls -d ${JDIR}/.*.meta 2>/dev/null`
- do
- if [ "`cat ${i}/ipv4 2>/dev/null`" = "${IP4}/${MASK4}" ] ; then
- exit_err "A jail with this IPv4 address already exists!"
- fi
- done
- fi
-
- # Check if we have a new IPv6 address for this import
- echo "${i}" | grep '\-\-ipv6=' >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
- then
- tmp="`echo ${i} | cut -d '=' -f 2`"
- IP6="`echo ${tmp} | cut -d '/' -f 1 -s`"
- MASK6="`echo ${tmp} | cut -d '/' -f 2 -s`"
-
- #Sanity check on the IP
- if ! is_ipv6 "${IP6}" ; then
- exit_err "Invalid IPv6 address!"
- fi
-
- for i in `ls -d ${JDIR}/.*.meta 2>/dev/null`
- do
- _ipv6=`cat ${i}/ipv6 2>/dev/null | tr a-z A-Z`
- _nipv6="`echo ${IP6}|tr a-z A-Z`/${MASK6}"
-
- if [ "${_ipv6}" = "${_nipv6}" ] ; then
- exit_err "A jail with this IPv6 address already exists!"
- fi
- done
- fi
-
- # Check if we have a new hostname for this jail
- echo ${i} | grep '\-\-host=' >/dev/null 2>/dev/null
- if [ "$?" = "0" ]
- then
- HOST="`echo ${i} | cut -d '=' -f 2`"
- fi
-
- done
+ get_ip_host_flags "$@"
if [ "${IP4}" != "OFF" ] ; then
IP4="${IP4}/${MASK4}"
@@ -1070,74 +928,48 @@ defaultrouter-ipv6) DEFAULTROUTER="${4}"
;;
- zfsmksnap) require_root
- JAILNAME="$2"
- if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
- if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
- set_warden_metadir
- ${PROGDIR}/scripts/backend/zfsmksnap.sh "${JAILNAME}" "$3"
- ;;
-
- zfslistclone) require_root
- JAILNAME="$2"
+ snap) require_root
+ JAILNAME="$3"
if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
set_warden_metadir
- ${PROGDIR}/scripts/backend/zfslistclone.sh "${JAILNAME}"
- ;;
- zfslistsnap) require_root
- JAILNAME="$2"
- if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
- if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
- set_warden_metadir
- ${PROGDIR}/scripts/backend/zfslistsnap.sh "${JAILNAME}"
+ # Get the sub-command here
+ case $2 in
+ list) ${PROGDIR}/scripts/backend/zfslistsnap.sh "${JAILNAME}" ;;
+ make) ${PROGDIR}/scripts/backend/zfsmksnap.sh "${JAILNAME}" "$4" ;;
+ remove) ${PROGDIR}/scripts/backend/zfsrmsnap.sh "${JAILNAME}" "$4" ;;
+ revert) ${PROGDIR}/scripts/backend/zfsrevertsnap.sh "${JAILNAME}" "$4" ;;
+ *) help_snap ; exit 1 ;;
+ esac
;;
- zfsclonesnap) require_root
+ clone) require_root
JAILNAME="$2"
- SNAP="$3"
if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
set_warden_metadir
- ${PROGDIR}/scripts/backend/zfsclonesnap.sh "${JAILNAME}" "${SNAP}"
- ;;
- zfscronsnap) require_root
- JAILNAME="$2"
- if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
- if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
- set_warden_metadir
- ${PROGDIR}/scripts/backend/zfscronsnap.sh "${JAILNAME}" "$3" "$4" "$5"
- ;;
+ get_ip_host_flags "$@"
+ if [ "${IP4}" != "OFF" ] ; then
+ IP4="${IP4}/${MASK4}"
+ fi
+ if [ "${IP6}" != "OFF" ] ; then
+ IP6="${IP6}/${MASK6}"
+ fi
- zfsrevertsnap) require_root
- JAILNAME="$2"
- SNAP="$3"
- if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
- if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
- set_warden_metadir
- ${PROGDIR}/scripts/backend/zfsrevertsnap.sh "${JAILNAME}" "$SNAP"
+ ${PROGDIR}/scripts/backend/zfsclone.sh "${JAILNAME}" "$3" "$IP4" "$IP6"
;;
- zfsrmclone) require_root
+ cronsnap) require_root
JAILNAME="$2"
- CLONE="$3"
if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
set_warden_metadir
- ${PROGDIR}/scripts/backend/zfsrmclone.sh "${JAILNAME}" "${CLONE}"
+ ${PROGDIR}/scripts/backend/zfscronsnap.sh "${JAILNAME}" "$3" "$4" "$5"
;;
- zfsrmsnap) require_root
- JAILNAME="$2"
- SNAP="$3"
- if [ -z "${JAILNAME}" ]; then exit_err "No jail specified!"; fi
- if [ ! -e "${JDIR}/${JAILNAME}" ]; then exit_err "No such jail!"; fi
- set_warden_metadir
- ${PROGDIR}/scripts/backend/zfsrmsnap.sh "${JAILNAME}" "${SNAP}"
- ;;
create) require_root
# The user wants to create a new jail, do error checking
View
83 src-sh/warden/scripts/backend/functions.sh
@@ -44,7 +44,7 @@ ATMP="/tmp/.wans"
export ATMP
# Warden Version
-WARDENVER="1.3"
+WARDENVER="1.4"
export WARDENVER
# Dirs to nullfs mount in X jail
@@ -438,25 +438,26 @@ revertZFSSnap() {
}
-cloneZFSSnap() {
+cloneZFSDir() {
isDirZFS "${1}" "1"
if [ $? -ne 0 ] ; then printerror "Not a ZFS volume: ${1}" ; fi
+
tank=`getZFSTank "$1"`
rp=`getZFSRelativePath "$1"`
- cdir=`getZFSRelativePath "${CDIR}"`
+ newrp=`getZFSRelativePath "$2"`
- # Make sure this is a valid snapshot
- zfs list -t snapshot | grep -w "^${tank}${rp}" | cut -d '@' -f 2 | awk '{print $1}' | grep -q ${2}
- if [ $? -ne 0 ] ; then printerror "Invalid ZFS snapshot!" ; fi
+ zdate=`date +%Y-%m-%d-%H-%M-%S`
+ snapName="preClone-$zdate"
- if [ -d "${CDIR}/${3}-${2}" ] ; then
- printerror "This snapshot is already cloned and mounted at: ${CDIR}/${3}-${2}"
- fi
+ # Create a temp snapshot we can clone
+ zfs snapshot $tank${rp}@${snapName}
+ if [ $? -ne 0 ] ; then printerror "Failed creating snapshot!" ; fi
# Clone the snapshot
- zfs clone -p ${tank}${rp}@$2 ${tank}${cdir}/${3}-${2}
+ zfs clone -p ${tank}${rp}@${snapName} ${tank}${newrp}
+ if [ $? -ne 0 ] ; then printerror "Failed cloning snapshot!" ; fi
- echo "Snapshot cloned and mounted to: ${CDIR}/${3}-${2}"
+ return 0
}
set_warden_metadir()
@@ -1164,3 +1165,63 @@ delete_template()
exit 0
}
+
+get_ip_host_flags()
+{
+ IP4="OFF"
+ IP6="OFF"
+ HOST="OFF"
+ for i in "$@"
+ do
+ # Check if we have a new IPv4 address for this import
+ echo "${i}" | grep '\-\-ipv4=' >/dev/null 2>/dev/null
+ if [ "$?" = "0" ]; then
+ tmp="`echo ${i} | cut -d '=' -f 2`"
+ IP4="`echo ${tmp} | cut -d '/' -f 1 -s`"
+ MASK4="`echo ${tmp} | cut -d '/' -f 2 -s`"
+
+ #Sanity check on the IP
+ if ! is_ipv4 "${IP4}" ; then
+ exit_err "Invalid IPv4 address: $IP4"
+ fi
+
+ for i in `ls -d ${JDIR}/.*.meta 2>/dev/null`
+ do
+ if [ "`cat ${i}/ipv4 2>/dev/null`" = "${IP4}/${MASK4}" ] ; then
+ exit_err "A jail with this IPv4 address already exists!"
+ fi
+ done
+ fi
+
+ # Check if we have a new IPv6 address for this import
+ echo "${i}" | grep '\-\-ipv6=' >/dev/null 2>/dev/null
+ if [ "$?" = "0" ]; then
+ tmp="`echo ${i} | cut -d '=' -f 2`"
+ IP6="`echo ${tmp} | cut -d '/' -f 1 -s`"
+ MASK6="`echo ${tmp} | cut -d '/' -f 2 -s`"
+
+ #Sanity check on the IP
+ if ! is_ipv6 "${IP6}" ; then
+ exit_err "Invalid IPv6 address!"
+ fi
+
+ for i in `ls -d ${JDIR}/.*.meta 2>/dev/null`
+ do
+ _ipv6=`cat ${i}/ipv6 2>/dev/null | tr a-z A-Z`
+ _nipv6="`echo ${IP6}|tr a-z A-Z`/${MASK6}"
+
+ if [ "${_ipv6}" = "${_nipv6}" ] ; then
+ exit_err "A jail with this IPv6 address already exists!"
+ fi
+ done
+ fi
+
+ # Check if we have a new hostname for this jail
+ echo ${i} | grep '\-\-host=' >/dev/null 2>/dev/null
+ if [ "$?" = "0" ]; then
+ HOST="`echo ${i} | cut -d '=' -f 2`"
+ fi
+
+ done
+
+}
View
80 src-sh/warden/scripts/backend/zfsclone.sh
@@ -0,0 +1,80 @@
+#!/bin/sh
+# ZFS functionality
+# Args $1 = jail-name
+# Args $2 = new jail name
+# Args $3 = new IPV4
+# Args $4 = new IPV6
+#######################################################################
+
+# Source our functions
+PROGDIR="/usr/local/share/warden"
+
+# Source our variables
+. ${PROGDIR}/scripts/backend/functions.sh
+
+JAILNAME="${1}"
+NEWJAILNAME="${2}"
+IPV4="${3}"
+IPV6="${4}"
+
+if [ -z "${JAILNAME}" ]
+then
+ echo "ERROR: No jail specified to start!"
+ exit 5
+fi
+
+if [ -z "${JDIR}" ]
+then
+ echo "ERROR: JDIR is unset!!!!"
+ exit 5
+fi
+
+JAILDIR="${JDIR}/${JAILNAME}"
+NEWJAILDIR="${JDIR}/${NEWJAILNAME}"
+
+if [ ! -d "${JAILDIR}" ]
+then
+ echo "ERROR: No jail located at ${JAILDIR}"
+ exit 5
+fi
+
+if [ -d "${NEWJAILDIR}" ] ; then
+ echo "ERROR: $NEWJAILNAME already exists!"
+ exit 1
+fi
+
+
+# Create a new snap and clone the original jail
+cloneZFSDir "$JAILDIR" "$NEWJAILDIR"
+if [ $? -ne 0 ] ; then
+ exit_err "Failed doing jail clone!"
+fi
+
+# Get the warden meta-dirs
+set_warden_metadir
+NEWJMETADIR="${JDIR}/.${NEWJAILNAME}.meta"
+
+# Copy the meta-dir
+cp -r "$JMETADIR" "${NEWJMETADIR}"
+if [ $? -ne 0 ] ; then
+ exit_err "Failed creating new jail meta-dir"
+fi
+
+# Set some of the new data
+echo "$NEWJAILNAME" > ${NEWJMETADIR}/host
+
+# Set IPV4
+if [ "$IPV4" = "OFF" ] ; then
+ rm ${NEWJMETADIR}/ipv4 2>/dev/null
+else
+ echo "$IPV4" > ${NEWJMETADIR}/ipv4
+fi
+
+# Set IPV6
+if [ "$IPV6" = "OFF" ] ; then
+ rm ${NEWJMETADIR}/ipv6 2>/dev/null
+else
+ echo "$IPV6" > ${NEWJMETADIR}/ipv6
+fi
+
+exit 0
View
41 src-sh/warden/scripts/backend/zfsclonesnap.sh
@@ -1,41 +0,0 @@
-#!/bin/sh
-# ZFS functionality
-# Args $1 = jail-name
-# Args $2 = zfs directive
-#######################################################################
-
-# Source our functions
-PROGDIR="/usr/local/share/warden"
-
-# Source our variables
-. ${PROGDIR}/scripts/backend/functions.sh
-
-JAILNAME="${1}"
-SNAP="${2}"
-
-if [ -z "${SNAP}" ] ; then
- echo "ERROR: No snapshot specified!"
- exit 1
-fi
-
-if [ -z "${JAILNAME}" ]
-then
- echo "ERROR: No jail specified to start!"
- exit 5
-fi
-
-if [ -z "${JDIR}" ]
-then
- echo "ERROR: JDIR is unset!!!!"
- exit 5
-fi
-
-JAILDIR="${JDIR}/${JAILNAME}"
-
-if [ ! -d "${JAILDIR}" ]
-then
- echo "ERROR: No jail located at ${JAILDIR}"
- exit 5
-fi
-
-cloneZFSSnap "${JAILDIR}" "$SNAP" "${JAILNAME}"
View
35 src-sh/warden/scripts/backend/zfslistclone.sh
@@ -1,35 +0,0 @@
-#!/bin/sh
-# ZFS functionality
-# Args $1 = jail-name
-# Args $2 = zfs directive
-#######################################################################
-
-# Source our functions
-PROGDIR="/usr/local/share/warden"
-
-# Source our variables
-. ${PROGDIR}/scripts/backend/functions.sh
-
-JAILNAME="${1}"
-
-if [ -z "${JAILNAME}" ]
-then
- echo "ERROR: No jail specified!"
- exit 5
-fi
-
-if [ -z "${JDIR}" ]
-then
- echo "ERROR: JDIR is unset!!!!"
- exit 5
-fi
-
-JAILDIR="${JDIR}/${JAILNAME}"
-
-if [ ! -d "${JAILDIR}" ]
-then
- echo "ERROR: No jail located at ${JAILDIR}"
- exit 5
-fi
-
-listZFSClone "${JAILDIR}" "${JAILNAME}"
View
41 src-sh/warden/scripts/backend/zfsrmclone.sh
@@ -1,41 +0,0 @@
-#!/bin/sh
-# ZFS functionality
-# Args $1 = jail-name
-# Args $2 = zfs directive
-#######################################################################
-
-# Source our functions
-PROGDIR="/usr/local/share/warden"
-
-# Source our variables
-. ${PROGDIR}/scripts/backend/functions.sh
-
-JAILNAME="${1}"
-CLONE="${2}"
-
-if [ -z "${CLONE}" ] ; then
- echo "ERROR: No clone specified!"
- exit 1
-fi
-
-if [ -z "${JAILNAME}" ]
-then
- echo "ERROR: No jail specified to start!"
- exit 5
-fi
-
-if [ -z "${JDIR}" ]
-then
- echo "ERROR: JDIR is unset!!!!"
- exit 5
-fi
-
-JAILDIR="${JDIR}/${JAILNAME}"
-
-if [ ! -d "${JAILDIR}" ]
-then
- echo "ERROR: No jail located at ${JAILDIR}"
- exit 5
-fi
-
-rmZFSClone "${JAILDIR}" "${CLONE}" "${JAILNAME}"
Please sign in to comment.
Something went wrong with that request. Please try again.