summaryrefslogtreecommitdiff
path: root/ezjail-admin
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2012-09-08 15:09:47 +0000
committererdgeist <erdgeist@erdgeist.org>2012-09-08 15:09:47 +0000
commit4037d12aaadf376fcdd6b63a58bb9932b287b9fc (patch)
treeda8ca1f0aaec82915981611af33920f024bac498 /ezjail-admin
parent7646f7e7776b361fad92069ba7f0d2e68f5e5e26 (diff)
Cleanup zfs code. Make sure, ezjail_zfs_properties are properly passed. Move checks for ezjails zfs to a central location. Fix typos
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-xezjail-admin60
1 files changed, 33 insertions, 27 deletions
diff --git a/ezjail-admin b/ezjail-admin
index 06579b2..b27d871 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -261,10 +261,8 @@ ezjail_splitworld() {
261 cd "${ezjail_jailfull}" || exerr "Error: Cant access temporary Jail directory." 261 cd "${ezjail_jailfull}" || exerr "Error: Cant access temporary Jail directory."
262 262
263 if [ "${ezjail_use_zfs}" = "YES" ]; then 263 if [ "${ezjail_use_zfs}" = "YES" ]; then
264 echo "ZFS: create the basejail" 264 ensure_jailzfs
265 echo "/sbin/zfs create -p -o mountpoint=${ezjail_jaildir} ${ezjail_zfs_properties} ${ezjail_jailzfs}" 265 /sbin/zfs create ${ezjail_jailzfs}/basejail
266 /sbin/zfs create -p -o mountpoint=${ezjail_jaildir} ${ezjail_zfs_properties} ${ezjail_jailzfs}
267 /sbin/zfs create -p ${ezjail_jailzfs}/basejail
268 /sbin/zfs snapshot ${ezjail_jailzfs}/basejail@`date -v -7d +"%C%y%m%d_%H:%M:%S"` 266 /sbin/zfs snapshot ${ezjail_jailzfs}/basejail@`date -v -7d +"%C%y%m%d_%H:%M:%S"`
269 fi 267 fi
270 268
@@ -283,7 +281,6 @@ ezjail_splitworld() {
283 281
284 # Try to remove the old template jail 282 # Try to remove the old template jail
285 if [ "${ezjail_use_zfs}" = "YES" ]; then 283 if [ "${ezjail_use_zfs}" = "YES" ]; then
286 echo "ZFS: cleanup old template jail"
287 [ -d "${ezjail_jailtemplate}" ] && zfs destroy -R ${ezjail_jailzfs}/newjail && rm -rf "${ezjail_jailtemplate}" 284 [ -d "${ezjail_jailtemplate}" ] && zfs destroy -R ${ezjail_jailzfs}/newjail && rm -rf "${ezjail_jailtemplate}"
288 cd ${ezjail_jaildir} 285 cd ${ezjail_jaildir}
289 zfs rename ${ezjail_jailzfs}/fulljail ${ezjail_jailzfs}/newjail 286 zfs rename ${ezjail_jailzfs}/fulljail ${ezjail_jailzfs}/newjail
@@ -421,6 +418,28 @@ check_for_zfs_exist () {
421 return ${_exit} 418 return ${_exit}
422} 419}
423 420
421ensure_jailzfs() {
422 # make sure we do have a zfs to work with, create it if necessary or exit with an error
423 # if a plain non-empty directory in the place
424
425 # ensure that the system has a working zfs
426 check_for_zpool
427
428 # if a zfs already exists, we assume it to be the one we need
429 _zfs_status=`/sbin/zfs list -H -o name ${ezjail_jailzfs} 2> /dev/null`
430 [ "${_zfs_status}" = "${ezjail_jailzfs}" ] && return
431
432 # if a directoy already exists in that place, make sure it is empty, else bump user
433 [ -d "${ezjail_jaildir}" -a -n "`ls -A ${ezjail_jaildir}`" ] && exerr "Error: Can not create zfs at ${ezjail_jaildir}.\n There is a non-empty directory in the way."
434
435 # create all parent file systems if necessary
436 case "${ezjail_jailzfs}" in */*/*) /sbin/zfs create -p ${ezjail_jailzfs%/*};; esac
437
438 # create the ezjail root zfs
439 # Note, we can not use -p here, because the -o options are ignored
440 /sbin/zfs create -o mountpoint=${ezjail_jaildir} ${ezjail_zfs_properties} ${ezjail_jailzfs}
441}
442
424############################# 443#############################
425# End of function definitions 444# End of function definitions
426# " 445# "
@@ -598,12 +617,10 @@ create)
598 ;; 617 ;;
599 zfs) 618 zfs)
600 if [ -z "${ezjail_exists}" ]; then 619 if [ -z "${ezjail_exists}" ]; then
601 echo "ZFS: create the jail filesystem" 620 [ -n "${ezjail_imagesize}" ] && ezjail_zfs_jail_properties="-o quota=${ezjail_imagesize} -o compression=lzjb"
602 if [ ${ezjail_imagesize} ]; then
603 ezjail_zfs_jail_properies="-o quota=${ezjail_imagesize} -o compression=lzjb"
604 fi
605 [ -d "${ezjail_jaildir}/${ezjail_hostname}" ] && exerr "Error: Could not create jail root mount point ${ezjail_rootdir}" 621 [ -d "${ezjail_jaildir}/${ezjail_hostname}" ] && exerr "Error: Could not create jail root mount point ${ezjail_rootdir}"
606 /sbin/zfs create -p -o mountpoint=${ezjail_rootdir} ${ezjail_zfs_jail_properies} ${ezjail_jailzfs}/${ezjail_hostname} 622
623 /sbin/zfs create -o mountpoint=${ezjail_rootdir} ${ezjail_zfs_jail_properties} ${ezjail_jailzfs}/${ezjail_hostname}
607 else 624 else
608 check_for_zfs_exist || exerr "Error: The existing destination is not a ZFS filesystem." 625 check_for_zfs_exist || exerr "Error: The existing destination is not a ZFS filesystem."
609 fi 626 fi
@@ -772,9 +789,7 @@ delete)
772 [ "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}." 789 [ "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}."
773 790
774 # check for an active ZFS zpool 791 # check for an active ZFS zpool
775 if [ "${ezjail_imagetype}" = "zfs" ]; then 792 [ "${ezjail_imagetype}" = "zfs" ] && check_for_zpool
776 check_for_zpool
777 fi
778 793
779 if [ "${ezjail_id}" ]; then 794 if [ "${ezjail_id}" ]; then
780 # if jail is still running, refuse to go any further 795 # if jail is still running, refuse to go any further
@@ -809,7 +824,6 @@ delete)
809 [ "${ezjail_image}" ] && rm -f "${ezjail_image}" "${ezjail_image%.img}.device" 824 [ "${ezjail_image}" ] && rm -f "${ezjail_image}" "${ezjail_image%.img}.device"
810 ;; 825 ;;
811 zfs) 826 zfs)
812 echo "ZFS: delete the jails ZFS"
813 /sbin/zfs destroy -r ${ezjail_jailzfs}/${ezjail_hostname} 827 /sbin/zfs destroy -r ${ezjail_jailzfs}/${ezjail_hostname}
814 ;; 828 ;;
815 esac 829 esac
@@ -870,11 +884,6 @@ setup|update)
870 # Check if some action was requested 884 # Check if some action was requested
871 [ "${ezjail_installaction}" ] || exerr "Error: No install action has been chosen.\n Please note that ezjails behaviour changed. Rebuilding the world no longer is default.\n Run '${ezjail_admin} update -b' to build and install a world from source or '${ezjail_admin} update -i' to install an already built world." 885 [ "${ezjail_installaction}" ] || exerr "Error: No install action has been chosen.\n Please note that ezjails behaviour changed. Rebuilding the world no longer is default.\n Run '${ezjail_admin} update -b' to build and install a world from source or '${ezjail_admin} update -i' to install an already built world."
872 886
873 if [ "${ezjail_use_zfs}" = "YES" ]; then
874 check_for_zpool
875 zfs create -p -o mountpoint=${ezjail_jaildir} ${ezjail_jailzfs}
876 fi
877
878 if [ "${ezjail_installaction}" = "none" ]; then 887 if [ "${ezjail_installaction}" = "none" ]; then
879 # check, whether ezjail has been setup correctly. existence of 888 # check, whether ezjail has been setup correctly. existence of
880 # ezjail_jailbase is our indicator 889 # ezjail_jailbase is our indicator
@@ -911,9 +920,8 @@ setup|update)
911 # Normally fulljail should be renamed by past ezjail-admin commands. 920 # Normally fulljail should be renamed by past ezjail-admin commands.
912 # However those may have failed 921 # However those may have failed
913 if [ "${ezjail_use_zfs}" = "YES" ]; then 922 if [ "${ezjail_use_zfs}" = "YES" ]; then
914 echo "ZFS: manage basejail and newjail" 923 ensure_jailzfs
915 [ -d "${ezjail_jailfull}" ] && /sbin/zfs destroy -R "${ezjail_jailzfs}/fulljail" && rm -rf "${ezjail_jailfull}" 924 [ -d "${ezjail_jailfull}" ] && /sbin/zfs destroy -R "${ezjail_jailzfs}/fulljail" 2>/dev/null && rm -rf "${ezjail_jailfull}"
916 [ ! -d " ${ezjail_jaildir}" ] && /sbin/zfs create -p -o mountpoint=${ezjail_jaildir} ${ezjail_zfs_properties} ${ezjail_jailzfs}
917 /sbin/zfs create "${ezjail_jailzfs}/fulljail" || exerr "Error: Cannot create temporary Jail directory." 925 /sbin/zfs create "${ezjail_jailzfs}/fulljail" || exerr "Error: Cannot create temporary Jail directory."
918 else 926 else
919 [ -d "${ezjail_jailfull}" ] && chflags -R noschg "${ezjail_jailfull}" && rm -rf "${ezjail_jailfull}" 927 [ -d "${ezjail_jailfull}" ] && chflags -R noschg "${ezjail_jailfull}" && rm -rf "${ezjail_jailfull}"
@@ -993,11 +1001,9 @@ install)
993 # Normally fulljail should be renamed by past ezjail-admin commands. 1001 # Normally fulljail should be renamed by past ezjail-admin commands.
994 # However those may have failed 1002 # However those may have failed
995 if [ "${ezjail_use_zfs}" = "YES" ]; then 1003 if [ "${ezjail_use_zfs}" = "YES" ]; then
996 check_for_zpool 1004 ensure_jailzfs
997 echo "ZFS: manage basejail and newjail" 1005 [ -d "${ezjail_jailfull}" ] && /sbin/zfs destroy -R "${ezjail_jailzfs}/fulljail" 2>/dev/null && rm -rf "${ezjail_jailfull}"
998 [ -d "${ezjail_jailfull}" ] && /sbin/zfs destroy -R "${ezjail_jailzfs}/fulljail" && rm -rf "${ezjail_jailfull}" 1006 /sbin/zfs create "${ezjail_jailzfs}/fulljail" || exerr "Error: Cannot create temporary Jail directory."
999 [ ! -d " ${ezjail_jaildir}" ] && /sbin/zfs create -p -o mountpoint=${ezjail_jaildir} ${ezjail_jailzfs}
1000 /sbin/zfs create -p "${ezjail_jailzfs}/fulljail" || exerr "Error: Cannot create temporary Jail directory."
1001 else 1007 else
1002 [ -d "${ezjail_jailfull}" ] && chflags -R noschg "${ezjail_jailfull}" && rm -rf "${ezjail_jailfull}" 1008 [ -d "${ezjail_jailfull}" ] && chflags -R noschg "${ezjail_jailfull}" && rm -rf "${ezjail_jailfull}"
1003 mkdir -p "${ezjail_jailfull}" || exerr "Error: Cannot create temporary Jail directory." 1009 mkdir -p "${ezjail_jailfull}" || exerr "Error: Cannot create temporary Jail directory."