Re: Jails: An rc.d script

From: William M. Grim (wgrim_at_siue.edu)
Date: 05/23/04

  • Next message: M. Warner Losh: "Re: Pthread_create and memory issues."
    Date: Sat, 22 May 2004 20:19:32 -0500
    To: hackers@freebsd.org
    
    

    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
    _______________________________________________
    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"
    

  • Next message: M. Warner Losh: "Re: Pthread_create and memory issues."

    Relevant Pages

    • Re: Using read-only NULLFS leads to panic. gdb output included, easy toreproduce.
      ... Also a few jails were running at the time, ... was just to disable the script that does the 'find' / locate. ... I don't like getting panics ... This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean. ...
      (freebsd-stable)
    • Re: jlogin.sh - a small nice jails helper!
      ... standard shell. ... here's another useful script that displays ... This is intended to complement the standard jlscommand. ... Run the jlscommand to get a list of jails and JIDs. ...
      (freebsd-stable)
    • Running jail on 5.2.1
      ... Im experiencing huge problems running jails on FreeSBD 5.2.1-RELEASE on ... First of all - not clear documentation for devfs rules and rc files ... Running this script from rc.local or even manually form ...
      (comp.unix.bsd.freebsd.misc)
    • Problem with jails after upgrading to 6.1-STABLE
      ... Worst thing is that i can't stop them using rc.d/jail script: ... PID JID TT STAT TIME COMMAND ... Stopping jails: clamsmtpd.blurp.pl. ... with killall which is used to in rc.d/jail script: ...
      (freebsd-hackers)
    • Re: devfs and jails
      ... > I want to apply devfs rules to a jails /dev. ... Since I am running my stuff inside an rc.d style script, ...
      (freebsd-questions)