summaryrefslogtreecommitdiff
path: root/ezjail-admin
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2015-04-15 00:11:46 +0200
committerDirk Engling <erdgeist@erdgeist.org>2015-04-15 00:11:46 +0200
commit3674126d9c258def8c7b2760fc9d2c00e23e9a01 (patch)
tree9e2d3867b257645ee6fe838cdf81a7d40c3556a5 /ezjail-admin
parente496f1aec590a696715f7934aed060f23862ba1e (diff)
To allow freezing jail states into flavours, allow keeping vanilla snapshot and add freeze subcommand
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-xezjail-admin47
1 files changed, 41 insertions, 6 deletions
diff --git a/ezjail-admin b/ezjail-admin
index 86ff736..67b75e7 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -41,7 +41,7 @@ ezjail_basesystem="base"
41case `uname -p` in amd64) ezjail_dirlist="${ezjail_dirlist} usr/lib32"; ezjail_basesystem="${ezjail_basesystem} lib32";; esac 41case `uname -p` in amd64) ezjail_dirlist="${ezjail_dirlist} usr/lib32"; ezjail_basesystem="${ezjail_basesystem} lib32";; esac
42 42
43# Synopsis messages 43# Synopsis messages
44ezjail_usage_ezjailadmin="${ezjail_admin} v3.4.2\nUsage: ${ezjail_admin} [archive|config|console|create|delete|install|list|restore|snapshot|troubleshoot|update] {params}" 44ezjail_usage_ezjailadmin="${ezjail_admin} v3.4.2\nUsage: ${ezjail_admin} [archive|config|console|create|delete|freeze|install|list|restore|snapshot|troubleshoot|update] {params}"
45ezjail_usage_install="Usage: ${ezjail_admin} install [-mMpPsS] [-h host] [-r release]" 45ezjail_usage_install="Usage: ${ezjail_admin} install [-mMpPsS] [-h host] [-r release]"
46ezjail_usage_create="Usage: ${ezjail_admin} create [-xbi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli|zfs] [-C args] [-a archive] [-z parentzfs] jailname jailip" 46ezjail_usage_create="Usage: ${ezjail_admin} create [-xbi] [-f flavour] [-r jailroot] [-s size] [-c bde|eli|zfs] [-C args] [-a archive] [-z parentzfs] jailname jailip"
47ezjail_usage_delete="Usage: ${ezjail_admin} delete [-wf] jailname" 47ezjail_usage_delete="Usage: ${ezjail_admin} delete [-wf] jailname"
@@ -50,6 +50,7 @@ ezjail_usage_config="Usage: ${ezjail_admin} config [-r run|norun] [-n newname] [
50ezjail_usage_console="Usage: ${ezjail_admin} console [-f] [-e command] jailname" 50ezjail_usage_console="Usage: ${ezjail_admin} console [-f] [-e command] jailname"
51ezjail_usage_archive="Usage: ${ezjail_admin} archive [-Af] [-a archive] [-d archivedir] jailname [jailname...]" 51ezjail_usage_archive="Usage: ${ezjail_admin} archive [-Af] [-a archive] [-d archivedir] jailname [jailname...]"
52ezjail_usage_restore="Usage: ${ezjail_admin} restore [-f] [-d archivedir] (archive|jailname)..." 52ezjail_usage_restore="Usage: ${ezjail_admin} restore [-f] [-d archivedir] (archive|jailname)..."
53ezjail_usage_freeze="Usage: ${ezjail_admin} freeze jailname newflavour"
53ezjail_usage_troubleshoot="Usage: ${ezjail_admin} troubleshoot [jailname...]" 54ezjail_usage_troubleshoot="Usage: ${ezjail_admin} troubleshoot [jailname...]"
54ezjail_usage_list="Usage: ${ezjail_admin} list" 55ezjail_usage_list="Usage: ${ezjail_admin} list"
55 56
@@ -534,7 +535,7 @@ case "$1" in
534create) 535create)
535 # Clean variables, prevent pollution 536 # Clean variables, prevent pollution
536 unset ezjail_rootdir ezjail_flavours ezjail_softlink ezjail_image ezjail_imagetype ezjail_imageparams ezjail_imagesize ezjail_parentzfs ezjail_device ezjail_devicelink ezjail_config ezjail_attachparams ezjail_exists ezjail_attachblocking ezjail_forceblocking ezjail_sourcedevice ezjail_rootdirempty ezjail_fromarchive ezjail_fromarchive_config 537 unset ezjail_rootdir ezjail_flavours ezjail_softlink ezjail_image ezjail_imagetype ezjail_imageparams ezjail_imagesize ezjail_parentzfs ezjail_device ezjail_devicelink ezjail_config ezjail_attachparams ezjail_exists ezjail_attachblocking ezjail_forceblocking ezjail_sourcedevice ezjail_rootdirempty ezjail_fromarchive ezjail_fromarchive_config
537 shift; while getopts :f:r:s:xbic:C:a:A:z: arg; do case ${arg} in 538 shift; while getopts :f:r:s:xbkic:C:a:A:z: arg; do case ${arg} in
538 x) ezjail_exists="YES";; 539 x) ezjail_exists="YES";;
539 r) ezjail_rootdir=${OPTARG};; 540 r) ezjail_rootdir=${OPTARG};;
540 f) ezjail_flavours=${OPTARG};; 541 f) ezjail_flavours=${OPTARG};;
@@ -547,6 +548,7 @@ create)
547 s) ezjail_imagesize=${OPTARG};; 548 s) ezjail_imagesize=${OPTARG};;
548 z) ezjail_imagetype="zfs"; 549 z) ezjail_imagetype="zfs";
549 ezjail_parentzfs=${OPTARG};; 550 ezjail_parentzfs=${OPTARG};;
551 k) ezjail_keepsnapshot="YES";; # undocumented
550 ?) exerr ${ezjail_usage_create};; 552 ?) exerr ${ezjail_usage_create};;
551 esac; done; shift $(( ${OPTIND} - 1 )) 553 esac; done; shift $(( ${OPTIND} - 1 ))
552 554
@@ -744,10 +746,10 @@ create)
744 # now take a copy of our template jail 746 # now take a copy of our template jail
745 if [ "${ezjail_imagetype}" = "zfs" -a "${ezjail_use_zfs}" = "YES" ]; then 747 if [ "${ezjail_imagetype}" = "zfs" -a "${ezjail_use_zfs}" = "YES" ]; then
746 # create ZFS filesystem first when using ZFS 748 # create ZFS filesystem first when using ZFS
747 /sbin/zfs snapshot ${ezjail_jailzfs}/newjail@_createnewjailtmp 749 /sbin/zfs snapshot ${ezjail_jailzfs}/newjail@_vanilla_newjail_
748 /sbin/zfs send ${ezjail_jailzfs}/newjail@_createnewjailtmp | zfs receive -F ${ezjail_parentzfs}/${ezjail_hostname} 750 /sbin/zfs send ${ezjail_jailzfs}/newjail@_vanilla_newjail_ | zfs receive -F ${ezjail_parentzfs}/${ezjail_hostname}
749 /sbin/zfs destroy ${ezjail_parentzfs}/${ezjail_hostname}@_createnewjailtmp 751 [ -z "${ezjail_keepsnapshot}" ] && /sbin/zfs destroy ${ezjail_parentzfs}/${ezjail_hostname}@_vanilla_newjail_
750 /sbin/zfs destroy ${ezjail_jailzfs}/newjail@_createnewjailtmp 752 /sbin/zfs destroy ${ezjail_jailzfs}/newjail@_vanilla_newjail_
751 else 753 else
752 mkdir -p "${ezjail_rootdir}" && cd "${ezjail_jailtemplate}" && find . | cpio -p -v "${ezjail_rootdir}" > /dev/null 754 mkdir -p "${ezjail_rootdir}" && cd "${ezjail_jailtemplate}" && find . | cpio -p -v "${ezjail_rootdir}" > /dev/null
753 fi 755 fi
@@ -1254,6 +1256,39 @@ console)
1254 1256
1255 exec ${_setfib} jexec ${ezjail_id} ${ezjail_default_execute} 1257 exec ${_setfib} jexec ${ezjail_id} ${ezjail_default_execute}
1256 ;; 1258 ;;
1259######################## ezjail-admin FREEZE ########################
1260freeze)
1261 shift
1262 [ $# -eq 2 ] || exerr ${ezjail_usage_freeze}
1263
1264 ezjail="$1"
1265 ezjail_flavour="$2"
1266
1267 fetchjailinfo ${ezjail}
1268
1269 # Check for existence of jail in our records
1270 [ "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}."
1271
1272 # Check if jail is of zfs type
1273 [ ${ezjail_imagetype} = "zfs" ] || exerr "Error: Can only freeze zfs based jails into a flavour.\n ${ezjail_name} is not a zfs jail."
1274
1275 # Check if jail has been snapshotted at create time
1276 /sbin/zfs list -H "${ezjail_parentzfs}/${ezjail_hostname}@_vanilla_newjail_" >/dev/null 2>/dev/null
1277 [ $? -eq 0 ] || exerr "Error: Jail ${ezjail_name} did not keep a snapshot when it was first created.\n Use ezjail-admin create with the -k option to keep a snapshot to diff."
1278
1279 # For now we will not overwrite an existing flavour
1280 [ -e "${ezjail_flavours_dir}/${ezjail_flavour}" ] && exerr "Error: A flavour already exists at ${ezjail_flavours_dir}/${ezjail_flavour}."
1281
1282 # Create the new frozen flavour's dir
1283 mkdir -p "${ezjail_flavours_dir}/${ezjail_flavour}"
1284
1285 # Now list all files that have been added or modified
1286 # TODO: This assumes no files have been deleted from when the jail was initially created. Safe assumption for now.
1287 # TODO: This assumes no files have been renamed from when the jail was initially created. Not so sure.
1288 /sbin/zfs diff -H "${ezjail_parentzfs}/${ezjail_hostname}@_vanilla_newjail_" "${ezjail_parentzfs}/${ezjail_hostname}" | \
1289 grep -E "^(M|+)" | cut -f 2 | cpio -d -m -p -v "${ezjail_flavours_dir}/${ezjail_flavour}"
1290
1291;;
1257######################## ezjail-admin SNAPSHOT ######################## 1292######################## ezjail-admin SNAPSHOT ########################
1258snapshot) 1293snapshot)
1259 shift 1294 shift