[PC-BSD Commits] r17374 - in pcbsd/current/src-sh/warden: bin scripts/backend

svn at pcbsd.org svn at pcbsd.org
Thu Jun 21 09:36:03 PDT 2012


Author: kris
Date: 2012-06-21 16:36:00 +0000 (Thu, 21 Jun 2012)
New Revision: 17374

Modified:
   pcbsd/current/src-sh/warden/bin/warden
   pcbsd/current/src-sh/warden/scripts/backend/importjail.sh
   pcbsd/current/src-sh/warden/scripts/backend/startjail.sh
   pcbsd/current/src-sh/warden/scripts/backend/stopjail.sh
Log:

Add framework for starting / stopping a Linux jail
Fix a bug importing jails
Make sure we can't change type on linux jails



Modified: pcbsd/current/src-sh/warden/bin/warden
===================================================================
--- pcbsd/current/src-sh/warden/bin/warden	2012-06-21 16:18:30 UTC (rev 17373)
+++ pcbsd/current/src-sh/warden/bin/warden	2012-06-21 16:36:00 UTC (rev 17374)
@@ -505,6 +505,10 @@
          fi
 
 	 set_warden_metadir
+	 if [ -e "${JMETADIR}/linuxjail" ] ; then
+           echo "ERROR: Cannot change type on Linux jail!"
+           exit 1
+	 fi
 	 case $TYPE in
 	   portjail) mkportjail "${JDIR}/${IP}" ;;
 	   standard) rm ${JMETADIR}/xjail >/dev/null 2>/dev/null ;;

Modified: pcbsd/current/src-sh/warden/scripts/backend/importjail.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/importjail.sh	2012-06-21 16:18:30 UTC (rev 17373)
+++ pcbsd/current/src-sh/warden/scripts/backend/importjail.sh	2012-06-21 16:36:00 UTC (rev 17374)
@@ -145,6 +145,7 @@
 
 # Make the new directory
 mkdir -p "${JDIR}/${IP}"
+set_warden_metadir
 
 # Extract the jail contents
 tail +${SKIP} ${IFILE} | tar xpf - -C "${JDIR}/${IP}" 2>/dev/null

Modified: pcbsd/current/src-sh/warden/scripts/backend/startjail.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/startjail.sh	2012-06-21 16:18:30 UTC (rev 17373)
+++ pcbsd/current/src-sh/warden/scripts/backend/startjail.sh	2012-06-21 16:36:00 UTC (rev 17374)
@@ -39,7 +39,6 @@
 
 if [ -e "${JMETADIR}/linuxjail" ] ; then
    LINUXJAIL="YES"
-   exit 0
 fi
 
 HOST="`cat ${JMETADIR}/host`"
@@ -50,14 +49,24 @@
    mount -t devfs devfs "${JDIR}/${IP}/dev"
 fi
 
-if is_symlinked_mountpoint ${JDIR}/${IP}/proc; then
-   echo "${JDIR}/${IP}/proc has symlink as parent, not mounting"
+if [ "$LINUXJAIL" = "YES" ] ; then
+  # Linux Jail
+  if is_symlinked_mountpoint ${JDIR}/${IP}/proc; then
+     echo "${JDIR}/${IP}/proc has symlink as parent, not mounting"
+  else
+     mount -t linprocfs linproc "${JDIR}/${IP}/proc"
+  fi
 else
-   mount -t procfs proc "${JDIR}/${IP}/proc"
+  # FreeBSD Jail
+  if is_symlinked_mountpoint ${JDIR}/${IP}/proc; then
+     echo "${JDIR}/${IP}/proc has symlink as parent, not mounting"
+  else
+     mount -t procfs proc "${JDIR}/${IP}/proc"
+  fi
+
+  if [ -e "${JMETADIR}/xjail" ] ; then mountjailxfs ${IP} ; fi
 fi
 
-if [ -e "${JMETADIR}/xjail" ] ; then mountjailxfs ${IP} ; fi
-
 IPS="${IP}"
 if [ -e "${JMETADIR}/ip-extra" ] ; then
   while read line
@@ -80,9 +89,10 @@
 done
 
 jail -c name=${HOST} path=${JDIR}/${IP} host.hostname=${HOST} ${_ipflags} persist
-jexec ${HOST} /bin/sh /etc/rc 2>&1
 
-# Get the JailID for this new jail
-JID="`jls | grep ${JDIR}/${IP} | tr -s " " | cut -d " " -f 2`"
-echo "$JID" >"${JDIR}/${IP}/var/run/warden.jid"
+if [ "$LINUXJAIL" = "YES" ] ; then
+  jexec ${HOST} /bin/sh /etc/rc 3 2>&1
+else
+  jexec ${HOST} /bin/sh /etc/rc 2>&1
+fi
 

Modified: pcbsd/current/src-sh/warden/scripts/backend/stopjail.sh
===================================================================
--- pcbsd/current/src-sh/warden/scripts/backend/stopjail.sh	2012-06-21 16:18:30 UTC (rev 17373)
+++ pcbsd/current/src-sh/warden/scripts/backend/stopjail.sh	2012-06-21 16:36:00 UTC (rev 17374)
@@ -82,15 +82,16 @@
   echo -e ".\c"
 done
 
+if [ -e "${JMETADIR}/linuxjail" ] ; then LINUXJAIL="YES" ; fi
 
-# Create our shutdown script and run it in the jail
-echo "#!/bin/sh
-sh /etc/rc.shutdown
-umount -f /dev" > "${JDIR}/${IP}/.shutdown"
-chmod 755 "${JDIR}/${IP}/.shutdown"
-chroot "${JDIR}/${IP}" "/.shutdown" >/dev/null 2>/dev/null
-rm "${JDIR}/${IP}/.shutdown"
+if [ "$LINUXJAIL" = "YES" ] ; then
+  jexec ${JID} /bin/sh /etc/rc.d/rc 0 >/dev/null 2>/dev/null
+else
+  jexec ${JID} /bin/sh /etc/rc.shutdown >/dev/null 2>/dev/null
+fi
 
+umount -f ${JDIR}/${IP}/dev >/dev/null 2>/dev/null
+
 echo -e ".\c"
 
 # Skip the time consuming portion if we are shutting down
@@ -140,12 +141,15 @@
   umount -f "${JDIR}/${IP}/proc"
 fi
 
+if [ -e "${JMETADIR}/xjail" ] ; then
+  umountjailxfs
+fi
+
 fi # End of FAST check
 
 echo -e ".\c"
 
 jail -r ${JID}
-rm ${JDIR}/${IP}/var/run/warden.jid 2>/dev/null
 
 echo -e "Done"
 



More information about the Commits mailing list