summaryrefslogtreecommitdiff
path: root/ezjail-admin
diff options
context:
space:
mode:
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-xezjail-admin70
1 files changed, 53 insertions, 17 deletions
diff --git a/ezjail-admin b/ezjail-admin
index b5715c1..5b314ff 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -85,6 +85,9 @@ attach_images () {
85 85
86# define detach strategy for image jails 86# define detach strategy for image jails
87detach_images () { 87detach_images () {
88 # Avoid ending up inside mount point
89 cd /
90
88 # unmount and detach memory disc 91 # unmount and detach memory disc
89 if [ "${ezjail_imagedevice}" ]; then 92 if [ "${ezjail_imagedevice}" ]; then
90 umount "${ezjail_rootdir}" > /dev/null 2> /dev/null 93 umount "${ezjail_rootdir}" > /dev/null 2> /dev/null
@@ -131,8 +134,12 @@ fetchjailinfo () {
131 134
132 ezjail_safename=`echo -n "${ezjail_name}" | tr -c '[:alnum:]' _` 135 ezjail_safename=`echo -n "${ezjail_name}" | tr -c '[:alnum:]' _`
133 136
134 [ -e "${ezjail_jailcfgs}/${ezjail_safename}" ] && ezjail_config="${ezjail_jailcfgs}/${ezjail_safename}" 137 if [ -z "$2" ]; then
135 [ -e "${ezjail_jailcfgs}/${ezjail_safename}.norun" ] && ezjail_config="${ezjail_jailcfgs}/${ezjail_safename}.norun" 138 [ -e "${ezjail_jailcfgs}/${ezjail_safename}" ] && ezjail_config="${ezjail_jailcfgs}/${ezjail_safename}"
139 [ -e "${ezjail_jailcfgs}/${ezjail_safename}.norun" ] && ezjail_config="${ezjail_jailcfgs}/${ezjail_safename}.norun"
140 else
141 ezjail_config=$2
142 fi
136 [ "${ezjail_config}" ] || return 0 143 [ "${ezjail_config}" ] || return 0
137 144
138 . "${ezjail_config}" 145 . "${ezjail_config}"
@@ -160,8 +167,8 @@ fetchjailinfo () {
160 *) ezjail_imagedevice=${ezjail_device_geom} ;; 167 *) ezjail_imagedevice=${ezjail_device_geom} ;;
161 esac 168 esac
162 169
163 mount -p -v | grep -q -E "^${ezjail_devicelink}.${ezjail_rootdir}" && ezjail_attached="YES" 170 mount -p -v | grep -q -E "^${ezjail_devicelink}[[:space:]]+${ezjail_rootdir}" && ezjail_attached="YES"
164 mount -p -v | grep -q -E "^${ezjail_device}.${ezjail_rootdir}" && ezjail_attached="YES" 171 mount -p -v | grep -q -E "^${ezjail_device}[[:space:]]+${ezjail_rootdir}" && ezjail_attached="YES"
165 172
166 # Stale device link detected. Remove and clean. 173 # Stale device link detected. Remove and clean.
167 [ -z "${ezjail_attached}" ] && unset ezjail_device && rm -f "${ezjail_devicelink}" 174 [ -z "${ezjail_attached}" ] && unset ezjail_device && rm -f "${ezjail_devicelink}"
@@ -303,11 +310,12 @@ case "$1" in
303create) 310create)
304 # Clean variables, prevent polution 311 # Clean variables, prevent polution
305 unset ezjail_rootdir ezjail_flavour ezjail_softlink ezjail_image ezjail_imagetype ezjail_imageparams ezjail_imagesize ezjail_device ezjail_devicelink ezjail_config ezjail_attachparams ezjail_exists ezjail_attachblocking ezjail_forceblocking ezjail_sourcedevice ezjail_rootdirempty ezjail_fromarchive 312 unset ezjail_rootdir ezjail_flavour ezjail_softlink ezjail_image ezjail_imagetype ezjail_imageparams ezjail_imagesize ezjail_device ezjail_devicelink ezjail_config ezjail_attachparams ezjail_exists ezjail_attachblocking ezjail_forceblocking ezjail_sourcedevice ezjail_rootdirempty ezjail_fromarchive
306 shift; while getopts :f:r:s:xbic:C:a: arg; do case ${arg} in 313 shift; while getopts :f:r:s:xbic:C:a:A: arg; do case ${arg} in
307 x) ezjail_exists="YES";; 314 x) ezjail_exists="YES";;
308 r) ezjail_rootdir=${OPTARG};; 315 r) ezjail_rootdir=${OPTARG};;
309 f) ezjail_flavour=${OPTARG};; 316 f) ezjail_flavour=${OPTARG};;
310 a) ezjail_fromarchive=${OPTARG};; 317 a) ezjail_fromarchive=${OPTARG};;
318 A) ezjail_fromarchive_config=${OPTARG};;
311 c) ezjail_imagetype=${OPTARG};; 319 c) ezjail_imagetype=${OPTARG};;
312 C) ezjail_imageparams=${OPTARG};; 320 C) ezjail_imageparams=${OPTARG};;
313 b) ezjail_forceblocking="YES";; 321 b) ezjail_forceblocking="YES";;
@@ -823,6 +831,8 @@ archive)
823 [ "${ezjail_archivealljails}" -a -d "${ezjail_prefix}/etc/ezjail/" ] && cd "${ezjail_prefix}/etc/ezjail/" && set - `ls | xargs rcorder` 831 [ "${ezjail_archivealljails}" -a -d "${ezjail_prefix}/etc/ezjail/" ] && cd "${ezjail_prefix}/etc/ezjail/" && set - `ls | xargs rcorder`
824 832
825 for ezjail in $@; do 833 for ezjail in $@; do
834 unset ezjail_imagesize
835
826 # Jail name mandatory 836 # Jail name mandatory
827 fetchjailinfo ${ezjail%.norun} 837 fetchjailinfo ${ezjail%.norun}
828 838
@@ -830,7 +840,21 @@ archive)
830 [ "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}." 840 [ "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}."
831 841
832 # If jail is still running, refuse to go any further - unless forced 842 # If jail is still running, refuse to go any further - unless forced
833 [ "${ezjail_id}" -a -z "${ezjail_force}" ] && exerr "Error: Jail appears to be still running, stop it first or [-f]orce archiving." 843 if [ "${ezjail_id}" -a -z "${ezjail_force}" ]; then
844 echo "Warning: Jail ${ezjail_name} appears to be still running, stop it first or [-f]orce archiving."
845 continue
846 fi
847
848 # Attach non-attached jails, if they can be attached non blocking
849 if [ "${ezjail_imagetype}" -a -z "${ezjail_attached}" ]; then
850 if [ "${ezjail_attachblocking}" ]; then
851 echo "Warning: Jail ${ezjail_name} is an image jail and can not be attached automatically."
852 echo " Use ezjail-admin config -i attach ${ezjail_name} to attach it first."
853 continue
854 fi
855 $0 config -i attach ${ezjail_name} || exerr "Error: Can not attach ${ezjail_image} for ${ezjail_name}"
856 ezjail_imagesize=-`stat -f %z ${ezjail_image}`
857 fi
834 858
835 # This one goes into archive to identify jail by name and restore date 859 # This one goes into archive to identify jail by name and restore date
836 ezjail_archive_tag="${ezjail_safename}-`date +%Y%m%d%H%M.%S`" 860 ezjail_archive_tag="${ezjail_safename}-`date +%Y%m%d%H%M.%S`"
@@ -845,12 +869,11 @@ archive)
845 ezjail_hostsystem_version=$( echo -n `uname -r` | tr -c '[:alnum:].' _ ) 869 ezjail_hostsystem_version=$( echo -n `uname -r` | tr -c '[:alnum:].' _ )
846 ezjail_hostsystem_cpu=$( echo -n `uname -p` | tr -c '[:alnum:].' _ ) 870 ezjail_hostsystem_cpu=$( echo -n `uname -p` | tr -c '[:alnum:].' _ )
847 871
848 ezjail_archive_tag="${ezjail_archive_tag}-${ezjail_hostsystem_name}-${ezjail_hostsystem_version}-${ezjail_hostsystem_cpu}" 872 ezjail_archive_tag="${ezjail_archive_tag}-${ezjail_hostsystem_name}-${ezjail_hostsystem_version}-${ezjail_hostsystem_cpu}${ezjail_imagesize}"
849 echo $ezjail_archive_tag
850 873
851 # If archive location is not absolute, prepend archive directory 874 # If archive location is not absolute, prepend archive directory
852 ezjail_makeabsolute ezjail_archive ${ezjail_archivedir} 875 ezjail_makeabsolute ezjail_archive ${ezjail_archivedir}
853echo ${ezjail_archive} 876
854 # It's a tar archive, after all 877 # It's a tar archive, after all
855 case ${ezjail_archive} in 878 case ${ezjail_archive} in
856 *.tar.gz|*.tgz|-) ;; 879 *.tar.gz|*.tgz|-) ;;
@@ -870,11 +893,16 @@ echo ${ezjail_archive}
870 -s:"^\\.":ezjail: \ 893 -s:"^\\.":ezjail: \
871 "${ezjail_config}" ${ezjail_addfiles} . 894 "${ezjail_config}" ${ezjail_addfiles} .
872 895
896 ezjail_paxresult=$?
897
898 # Detach previously attached jail
899 [ "${ezjail_imagesize}" ] && cd / && $0 config -i detach ${ezjail_name}
900
873 # An error on a jail not running is bad 901 # An error on a jail not running is bad
874 [ $? -eq 0 -o "${ezjail_force}" ] || exerr "Error: Archiving jail failed. You might want to check ${ezjail_archive}." 902 [ ${ezjail_paxresult} -eq 0 -o "${ezjail_force}" ] || exerr "Error: Archiving jail failed. You might want to check ${ezjail_archive}."
875 903
876 # When archiving a running jail, some errors might occur 904 # When archiving a running jail, some errors might occur
877 [ $? -eq 0 ] || echo "Warning: Archiving jail ${ezjail_name} was not completely successful. For a running jail this is not unusual. You might want to check ${ezjail_archive}." 905 [ ${ezjail_paxresult} -eq 0 ] || echo "Warning: Archiving jail ${ezjail_name} was not completely successful. For a running jail this is not unusual. You might want to check ${ezjail_archive}."
878 906
879 unset ezjail_archive ezjail_archive_opt ezjail_addfiles 907 unset ezjail_archive ezjail_archive_opt ezjail_addfiles
880 done 908 done
@@ -895,7 +923,7 @@ restore)
895 ezjail_archivedir=${ezjail_archivedir:-`pwd -P`} 923 ezjail_archivedir=${ezjail_archivedir:-`pwd -P`}
896 924
897 for ezjail_fromarchive in $@; do 925 for ezjail_fromarchive in $@; do
898 unset ezjail_safename 926 unset ezjail_safename ezjail_imagedata ezjail_nameprop
899 927
900 # if archive location is absolute and doesn't exist, fail 928 # if archive location is absolute and doesn't exist, fail
901 [ "${ezjail_fromarchive%%[!/]*}" -a ! -f "${ezjail_fromarchive}" ] && exerr "Error: File for archive ${ezjail_fromarchive} not found." 929 [ "${ezjail_fromarchive%%[!/]*}" -a ! -f "${ezjail_fromarchive}" ] && exerr "Error: File for archive ${ezjail_fromarchive} not found."
@@ -928,7 +956,7 @@ restore)
928 956
929 # Figure out, what jail and jail enviroment archive claims to contain 957 # Figure out, what jail and jail enviroment archive claims to contain
930 TIFS=${IFS}; IFS=-; set - ${ezjail_nameprop} 958 TIFS=${IFS}; IFS=-; set - ${ezjail_nameprop}
931 ezjail_nameprop_safename=$2 ezjail_nameprop_hsname=$4 ezjail_nameprop_hsversion=$5 ezjail_nameprop_hscpu=$6 959 ezjail_nameprop_safename=$2 ezjail_nameprop_hsname=$4 ezjail_nameprop_hsversion=$5 ezjail_nameprop_hscpu=$6 ezjail_nameporp_imgagesize=$7
932 IFS=${TIFS} 960 IFS=${TIFS}
933 961
934 # Figure out current system environment 962 # Figure out current system environment
@@ -942,11 +970,19 @@ restore)
942 [ "${ezjail_hscpu}" != "${ezjail_nameprop_hscpu}" ] && exerr "Error: Archive was created on a different CPU. Can not restore. Consider using \"ezjail-admin create -a\" when migrating ezjails." 970 [ "${ezjail_hscpu}" != "${ezjail_nameprop_hscpu}" ] && exerr "Error: Archive was created on a different CPU. Can not restore. Consider using \"ezjail-admin create -a\" when migrating ezjails."
943 971
944 # Save config to tempfile and source it 972 # Save config to tempfile and source it
945 ezjail_tmpfile=`mktemp /tmp/ezjail.prop.XXXXXXXX` 973 ezjail_config=`mktemp /tmp/ezjail.prop.XXXXXXXX`
946 [ $? -ne 0 ] && exerr "Error: Can't create temporary file." 974 [ $? -ne 0 ] && exerr "Error: Can't create temporary file."
947 pax -rzn -s:${ezjail_nameprop}:${ezjail_tmpfile}: -f ${ezjail_fromarchive} ${ezjail_nameprop} 975 pax -rzn -s:${ezjail_nameprop}:${ezjail_config}: -f ${ezjail_fromarchive} ${ezjail_nameprop}
948 . "${ezjail_tmpfile}" 976 fetchjailinfo ${ezjail_safename} ${ezjail_config}
949 rm -f "${ezjail_tmpfile}" 977
978 # Now all parameters are here, invoke ezjail-admin create
979 if [ "${ezjail_imagetype}" ]; then
980 ezjail_imagedata="-c ${ezjail_imagetype} -C '${ezjail_attachparams}' -s ${ezjail_nameporp_imgagesize}"
981 fi
982
983 echo $0 create -a "${ezjail_fromarchive}" -A "${ezjail_config}" ${ezjail_imagedata} -r "${ezjail_rootdir}" "${ezjail_hostname}" "${ezjail_ip}"
984 $0 create -a "${ezjail_fromarchive}" -A "${ezjail_config}" ${ezjail_imagedata} -r "${ezjail_rootdir}" "${ezjail_hostname}" "${ezjail_ip}" || exerr "Error: create failed."
985 rm -f "${ezjail_config}"
950 986
951 done 987 done
952 ;; 988 ;;