Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 May 2004 20:19:32 -0500
From:      "William M. Grim" <wgrim@siue.edu>
To:        hackers@freebsd.org
Subject:   Re: Jails: An rc.d script
Message-ID:  <40AFFC24.6050501@siue.edu>
In-Reply-To: <40AFF8B3.40009@siue.edu>
References:  <40AFF8B3.40009@siue.edu>

next in thread | previous in thread | raw e-mail | index | archive | help
Very odd, my jails.sh script was not allowed to pass or something.  So, 
I'm pasting it into this email.

#!/bin/sh
#
# Start the jails at boot-up.
# The only jails it can start properly are the ones in directories labelled
# with an IP address.
 
JAILBASE=/usr/local/var/jail
 
LS="/bin/ls"
JLS="/usr/sbin/jls"
AWK="/usr/bin/awk"
GREP="/usr/bin/grep"
HOST="/usr/bin/host"
MOUNT="/sbin/mount"
UMOUNT="/sbin/umount"
SH="/bin/sh"
JAIL="/usr/sbin/jail"
KILLALL="/usr/bin/killall"

start_jails()
{
        for JAILIP in `${LS} -1 ${JAILBASE}`; do
                ${MOUNT} -t devfs devfs ${JAILBASE}/${JAILIP}/dev
                ${MOUNT} -t procfs proc ${JAILBASE}/${JAILIP}/proc
                JAILHOST=`${HOST} ${JAILIP} | ${AWK} '{ print $5; }'`
                ${JAIL} ${JAILBASE}/${JAILIP} ${JAILHOST} ${JAILIP} 
${SH} /etc/rc
        done
}
                                                                                

stop_jails()
{
        echo "Even though you are stopping the jails, the JID may show up"
        echo "when doing \`jls\`.  This is most likely because some 
connections"        echo "are waiting to timeout."
                                                                                

        for JID in `${JLS} | ${GREP} -v JID | ${AWK} '{ print $1; }'`; do
                ${KILLALL} -j ${JID}
                echo "Killing JID: ${JID}"
        done
                                                                                

        for JAILIP in `\ls -1 ${JAILBASE}`; do
                ${UMOUNT} -f ${JAILBASE}/${JAILIP}/proc
                ${UMOUNT} -f ${JAILBASE}/${JAILIP}/dev
        done
}

case "$1" in
        start)
        start_jails
        ;;
        restart)
        stop_jails
        sleep 1
        start_jails
        ;;
        stop)
        stop_jails
        ;;
esac

Thanks again, and sorry for the confusion.


William M. Grim wrote:

> Hi!
>
> I've written an rc.d script that can start/stop/restart jails, if they 
> follow a certain pattern of setup.  I'm strongly considering the 
> placement of this in ports or base (ports seems most appropriate).
>
> Basically, if you have jails in /usr/local/var/jail/<IP>, my script 
> can start it up automatically, as long as the IP is reachable by 
> `host` (I know, it requires a little more work to remove this 
> dependency for 192.168. addresses, etc).
>
> However, I was wondering if anyone would want to test it?  All you 
> have to do is take my attached script and place it in 
> /usr/local/etc/rc.d/.  If you have your jails located somewhere else, 
> then edit the JAILBASE= line in the script.
>
> I would appreciate any constructive criticism about this script so 
> that I can make it better.  If you have any improvements you make, 
> feel free to send them to me as well.  I'll attempt to make it better 
> over time and to write a man page for it.
>
> Many thanks.
>
>------------------------------------------------------------------------
>
>_______________________________________________
>freebsd-hackers@freebsd.org mailing list
>http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
>To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
>  
>


-- 
William Michael Grim
Student, Southern Illinois University at Edwardsville
Unix Network Administrator, SIUE, Computer Science dept.
Phone: (217) 341-6552
Email: wgrim@siue.edu




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?40AFFC24.6050501>