summaryrefslogtreecommitdiff
path: root/ezjail-admin
diff options
context:
space:
mode:
authorerdgeist <erdgeist@erdgeist.org>2006-05-09 02:00:04 +0000
committererdgeist <erdgeist@erdgeist.org>2006-05-09 02:00:04 +0000
commit6cdc848308f1b1fcad9c653c77411c16f41deedf (patch)
treed73ed2070a6cc1cbdb6d026f04a5b6ece7528f21 /ezjail-admin
parent7df9c70879bb431592fa20a395ad29e70abb1180 (diff)
attaching and detaching image jails now works.
Diffstat (limited to 'ezjail-admin')
-rwxr-xr-xezjail-admin54
1 files changed, 29 insertions, 25 deletions
diff --git a/ezjail-admin b/ezjail-admin
index 5dfb143..ce29ca5 100755
--- a/ezjail-admin
+++ b/ezjail-admin
@@ -49,7 +49,7 @@ exerr () { echo -e "$*" >&2 ; exit 1; }
49# define detach strategy for image jails 49# define detach strategy for image jails
50detach_images () { 50detach_images () {
51 # unmount and detach memory disc 51 # unmount and detach memory disc
52 if [ "${ezjail_imagedevice}" ]; then 52 if [ -n "${ezjail_imagedevice}" ]; then
53 umount ${ezjail_rootdir} > /dev/null 53 umount ${ezjail_rootdir} > /dev/null
54 case ${ezjail_imagetype} in 54 case ${ezjail_imagetype} in
55 bde) gbde detach /dev/${ezjail_imagedevice} > /dev/null;; 55 bde) gbde detach /dev/${ezjail_imagedevice} > /dev/null;;
@@ -67,7 +67,7 @@ fetchjailinfo () {
67 ezjail_name=$1 67 ezjail_name=$1
68 68
69 # Clean variables, prevent polution 69 # Clean variables, prevent polution
70 unset ezjail_config ezjail_running ezjail_hostname ezjail_rootdir ezjail_image ezjail_imagetype ezjail_ip ezjail_id 70 unset ezjail_config ezjail_running ezjail_hostname ezjail_rootdir ezjail_image ezjail_imagetype ezjail_ip ezjail_id ezjail_attached ezjail_device
71 71
72 ezjail_safename=`echo -n "${ezjail_name}" | tr -c [:alnum:] _` 72 ezjail_safename=`echo -n "${ezjail_name}" | tr -c [:alnum:] _`
73 73
@@ -87,6 +87,13 @@ fetchjailinfo () {
87 eval ezjail_passphraseurl=\"\$jail_${ezjail_safename}_passphraseurl\" 87 eval ezjail_passphraseurl=\"\$jail_${ezjail_safename}_passphraseurl\"
88 88
89 ezjail_softlink=${ezjail_jaildir}/`basename -- ${ezjail_rootdir}` 89 ezjail_softlink=${ezjail_jaildir}/`basename -- ${ezjail_rootdir}`
90
91 if [ -n "${ezjail_image}" -a -L "${ezjail_rootdir}.device" ]; then
92 # Fetch destination of soft link
93 ezjail_device=`stat -f "%Y" ${ezjail_rootdir}.device`
94 [ -e "${ezjail_device}" ] && ezjail_attached="YES"
95 fi
96
90 [ -f /var/run/jail_${ezjail_safename}.id ] && ezjail_id=`cat /var/run/jail_${ezjail_safename}.id` || return 97 [ -f /var/run/jail_${ezjail_safename}.id ] && ezjail_id=`cat /var/run/jail_${ezjail_safename}.id` || return
91 jls | grep -q -E "^ +${ezjail_id} " || unset ezjail_id 98 jls | grep -q -E "^ +${ezjail_id} " || unset ezjail_id
92} 99}
@@ -390,10 +397,13 @@ delete)
390 fetchjailinfo $1 397 fetchjailinfo $1
391 398
392 # check for existence of jail in our records 399 # check for existence of jail in our records
393 [ "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}." 400 [ -n "${ezjail_config}" ] || exerr "Error: Nothing known about jail ${ezjail_name}."
394 401
395 # if jail is still running, refuse to go any further 402 # if jail is still running, refuse to go any further
396 [ "${ezjail_id}" ] && exerr "Error: Jail appears to be still running, stop it first." 403 [ -n "${ezjail_id}" ] && exerr "Error: Jail appears to be still running, stop it first."
404
405 # if jail is attached, refuse to go any further
406 [ -n "${ezjail_attached}" ] && exerr "Error: Jail image file ${ezjail_image} is attached as ${ezjail_device}. '`basename -- $0` config -i detach' it first."
397 407
398 # now we know everything we need to let the jail be gone remove entry 408 # now we know everything we need to let the jail be gone remove entry
399 # from ezjail resource structure, delete fstab.JAILNAME 409 # from ezjail resource structure, delete fstab.JAILNAME
@@ -420,7 +430,11 @@ list)
420 for ezjail in ${ezjail_list}; do 430 for ezjail in ${ezjail_list}; do
421 fetchjailinfo ${ezjail%.norun} 431 fetchjailinfo ${ezjail%.norun}
422 case ${ezjail_imagetype} in simple) ezjail_state="I";; bde) ezjail_state="B";; eli) ezjail_state="E";; *) ezjail_state="D";; esac 432 case ${ezjail_imagetype} in simple) ezjail_state="I";; bde) ezjail_state="B";; eli) ezjail_state="E";; *) ezjail_state="D";; esac
423 [ "${ezjail_id}" ] && ezjail_state=${ezjail_state}R || ezjail_state=${ezjail_state}S 433 if [ "${ezjail_id}" ]; then
434 ezjail_state=${ezjail_state}R
435 else
436 [ -n "${ezjail_attached}" ] && ezjail_state=${ezjail_state}A || ezjail_state=${ezjail_state}S
437 fi
424 [ "${ezjail_safename}" != "${ezjail}" ] && ezjail_state=${ezjail_state}N 438 [ "${ezjail_safename}" != "${ezjail}" ] && ezjail_state=${ezjail_state}N
425 439
426 printf "%-3s %-5s %-15s %-28s %s\\n" "${ezjail_state}" "${ezjail_id:-N/A}" "${ezjail_ip}" "${ezjail_hostname}" "${ezjail_rootdir}" 440 printf "%-3s %-5s %-15s %-28s %s\\n" "${ezjail_state}" "${ezjail_id:-N/A}" "${ezjail_ip}" "${ezjail_hostname}" "${ezjail_rootdir}"
@@ -550,7 +564,7 @@ config)
550 # Clean variables, prevent polution 564 # Clean variables, prevent polution
551 unset ezjail_setrunnable ezjail_imageaction 565 unset ezjail_setrunnable ezjail_imageaction
552 566
553 shift; while getopts :r: arg; do case ${arg} in 567 shift; while getopts :r:i: arg; do case ${arg} in
554 i) ezjail_imageaction=${OPTARG};; 568 i) ezjail_imageaction=${OPTARG};;
555 r) ezjail_setrunnable=${OPTARG};; 569 r) ezjail_setrunnable=${OPTARG};;
556 ?) exerr ${ezjail_usage_config};; 570 ?) exerr ${ezjail_usage_config};;
@@ -570,20 +584,15 @@ config)
570 case ${ezjail_setrunnable} in 584 case ${ezjail_setrunnable} in
571 run) [ "${ezjail_config}" = "${ezjail_config%.norun}" ] || mv ${ezjail_config} ${ezjail_config%.norun};; 585 run) [ "${ezjail_config}" = "${ezjail_config%.norun}" ] || mv ${ezjail_config} ${ezjail_config%.norun};;
572 norun) [ "${ezjail_config}" = "${ezjail_config%.norun}" ] && mv ${ezjail_config} ${ezjail_config}.norun ;; 586 norun) [ "${ezjail_config}" = "${ezjail_config%.norun}" ] && mv ${ezjail_config} ${ezjail_config}.norun ;;
573 *) echo "Warning: Unknow runnable option specified.";;
574 esac 587 esac
575 588
576 [ -n "${ezjail_imageaction}" -a -z "${ezjail_image}" ] && exerr "Error: Jail ${ezjail_name} not an image jail." 589 [ -n "${ezjail_imageaction}" -a -z "${ezjail_image}" ] && exerr "Error: Jail ${ezjail_name} not an image jail."
577 590
578 case ${ezjail_imageaction} in 591 case "${ezjail_imageaction}" in
579 attach) 592 attach)
580 # Check, if image already attached 593 # Check, if image already attached
581 if [ -L "${ezjail_root}.device" ]; then 594 [ -n "${ezjail_attached}" ] && exerr "Error: Jail image file ${ezjail_image} already attached as ${ezjail_device}."
582 # Fetch destination of soft link 595 rm -f ${ezjail_rootdir}.device
583 ezjail_device=`stat -f "%Y" ${ezjail_root}.device`
584 [ -b "${ezjail_device}" ] && exerr "Error: Jail image file ${ezjail_name} already attached as ${ezjail_device}."
585 rm -f ${ezjail_root}.device
586 fi
587 596
588 # Create a memory disc from jail image 597 # Create a memory disc from jail image
589 ezjail_imagedevice=`mdconfig -a -t vnode -f ${ezjail_image}` || exerr "Error: Could not attach memory disc." 598 ezjail_imagedevice=`mdconfig -a -t vnode -f ${ezjail_image}` || exerr "Error: Could not attach memory disc."
@@ -600,7 +609,7 @@ config)
600 ;; 609 ;;
601 eli) 610 eli)
602 echo "Attaching eli device for image jail ${ezjail}..." 611 echo "Attaching eli device for image jail ${ezjail}..."
603 echo geli attach ${ezjail_attachparams} /dev/${ezjail_device} | /bin/sh 612 echo geli attach ${ezjail_attachparams} /dev/${ezjail_imagedevice} | /bin/sh
604 [ $? -eq 0 ] || detach_images keep || exerr "Error: Attaching eli device failed." 613 [ $? -eq 0 ] || detach_images keep || exerr "Error: Attaching eli device failed."
605 # Device to mount is not md anymore 614 # Device to mount is not md anymore
606 ezjail_device=${ezjail_imagedevice}.eli 615 ezjail_device=${ezjail_imagedevice}.eli
@@ -609,18 +618,14 @@ config)
609 618
610 mount /dev/${ezjail_device} ${ezjail_rootdir} || detach_images keep || exerr "Error: Could not mount /dev/${ezjail_device} to ${ezjail_root}." 619 mount /dev/${ezjail_device} ${ezjail_rootdir} || detach_images keep || exerr "Error: Could not mount /dev/${ezjail_device} to ${ezjail_root}."
611 # relink image device 620 # relink image device
612 ln -s /dev/${ezjail_device} ${ezjail_root}.device 621 ln -s /dev/${ezjail_device} ${ezjail_rootdir}.device
613 622
614 ;; 623 ;;
615 detach) 624 detach)
625 # Check, if image really attached or running
616 [ -n "${ezjail_id}" ] && exerr "Error: Jail ${ezjail_name} still running. Can not detach." 626 [ -n "${ezjail_id}" ] && exerr "Error: Jail ${ezjail_name} still running. Can not detach."
617 627 [ -n "${ezjail_attached}" ] || exerr "Error: Jail image file ${ezjail_name} is not attached."
618 # Check, if image really attached 628 ezjail_device=${ezjail_device#/dev/}
619 if [ -L "${ezjail_root}.device" ]; then
620 # Fetch destination of soft link
621 ezjail_device=`stat -f "%Y" ${ezjail_root}.device`
622 [ -b "${ezjail_device}" ] || exerr "Error: Jail image file ${ezjail_name} is not attached."
623 fi
624 629
625 # Add this device to the list of devices to be unmounted 630 # Add this device to the list of devices to be unmounted
626 case ${ezjail_imagetype} in 631 case ${ezjail_imagetype} in
@@ -633,9 +638,8 @@ config)
633 detach_images keep 638 detach_images keep
634 639
635 # Remove soft link (which acts as a lock) 640 # Remove soft link (which acts as a lock)
636 rm -f ${ezjail_root}.device 641 rm -f ${ezjail_rootdir}.device
637 ;; 642 ;;
638 *) echo "Warning: Unknow image action specified.";;
639 esac 643 esac
640 ;; 644 ;;
641 645