Bug 174856 - [NEW PORT]: sysutils/jail2 - another jail rc-script, this time for jail.conf jails
Summary: [NEW PORT]: sysutils/jail2 - another jail rc-script, this time for jail.conf ...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: Normal Affects Only Me
Assignee: Lars Engels
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-12-31 08:20 UTC by yamagi
Modified: 2013-01-20 15:40 UTC (History)
0 users

See Also:


Attachments
file.shar (3.70 KB, text/plain)
2012-12-31 08:20 UTC, yamagi
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description yamagi 2012-12-31 08:20:00 UTC
jail2 is an alternative rc script for jails, relying on jail.conf
instead of rc.conf variables. Additionally, ZFS integration is provided.
In contrast to the default jail rc script this one can run inside jails,
allowing the configuration of hierarchical jails.

How-To-Repeat: -
Comment 1 Lars Engels freebsd_committer freebsd_triage 2013-01-20 11:25:30 UTC
Responsible Changed
From-To: freebsd-ports-bugs->lme

I'll take it.
Comment 2 Lars Engels freebsd_committer freebsd_triage 2013-01-20 15:31:13 UTC
State Changed
From-To: open->closed

Committed. Thanks!
Comment 3 dfilter service freebsd_committer freebsd_triage 2013-01-20 15:31:17 UTC
Author: lme
Date: Sun Jan 20 15:31:04 2013
New Revision: 310695
URL: http://svnweb.freebsd.org/changeset/ports/310695

Log:
  jail2 is an alternative rc script for jails, relying on jail.conf
  instead of rc.conf variables. Additionally, ZFS integration is provided.
  In contrast to the default jail rc script this one can run inside jails,
  allowing the configuration of hierarchical jails.
  
  PR:		ports/174856

Added:
  head/sysutils/jail2/
  head/sysutils/jail2/Makefile   (contents, props changed)
  head/sysutils/jail2/files/
  head/sysutils/jail2/files/jail2.in   (contents, props changed)
  head/sysutils/jail2/pkg-descr   (contents, props changed)
Modified:
  head/sysutils/Makefile

Modified: head/sysutils/Makefile
==============================================================================
--- head/sysutils/Makefile	Sun Jan 20 15:22:12 2013	(r310694)
+++ head/sysutils/Makefile	Sun Jan 20 15:31:04 2013	(r310695)
@@ -400,6 +400,7 @@
     SUBDIR += isomd5sum
     SUBDIR += ispman
     SUBDIR += istatd
+    SUBDIR += jail2
     SUBDIR += jailadmin
     SUBDIR += jailctl
     SUBDIR += jailer

Added: head/sysutils/jail2/Makefile
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/jail2/Makefile	Sun Jan 20 15:31:04 2013	(r310695)
@@ -0,0 +1,17 @@
+# $FreeBSD$
+
+PORTNAME=	jail2
+PORTVERSION=	1.0
+CATEGORIES=	sysutils
+MASTER_SITES=	#
+DISTFILES=	#
+
+MAINTAINER=	yamagi@yamagi.org
+COMMENT=	Jail startup/shutdown script with jail.conf support
+
+NO_BUILD=	yes
+NO_INSTALL=	yes
+
+USE_RC_SUBR=	jail2
+
+.include <bsd.port.mk>

Added: head/sysutils/jail2/files/jail2.in
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/jail2/files/jail2.in	Sun Jan 20 15:31:04 2013	(r310695)
@@ -0,0 +1,104 @@
+#!/bin/sh
+
+# Alternative rc script for jails. This script relies on
+# /etc/jail.conf instead of rc.conf variables. Usage:
+#
+# jail2_enable	   -> Enables the script
+# jail2_list	   -> List of jails to be started. The names
+#				      must match the names in /etc/jail.conf
+# jail2_$name_zfs  -> List of ZFS datasets to connect to the
+#					  jail $name.
+#
+# To manage ZFS datasets within a jail the dataset must have
+# set the parameter "jailed" to 1. Additionally the jail must
+# have set the proberties "allow.mount", "allow.mount.zfs"
+# and "enforce_statfs" to value lesser than 2.
+
+# PROVIDE: jail
+# REQUIRE: LOGIN cleanvar
+# BEFORE: securelevel
+# KEYWORD: shutdown
+
+. /etc/rc.subr
+
+name="jail2"
+rcvar=jail2_enable
+
+start_cmd="jail2_start"
+stop_cmd="jail2_stop"
+
+jail2_start()
+{
+	echo -n "Starting jails: "
+
+	for _j in ${jail2_list}; do
+		echo -n "${_j} "
+
+		if [ -e /var/run/jail_${_j}.id ]; then
+			echo "${_j} already exists"
+			continue
+		fi
+
+		jail -c -i -J /var/run/jail_${_j}.id ${_j} > /dev/null 2>&1
+
+		eval _zfs=\"\${jail2_${_j}_zfs:-}\"
+		_jid=`jls -j ${_j} jid 2>/dev/null`
+
+		if [ -n "${_zfs}" ]; then
+			for _ds in ${_zfs}; do
+				_jailed=`zfs get -H jailed ${_ds} 2>/dev/null | awk '{ print $3 }'`
+				if [ "${_jailed}" = "on" ]; then
+					echo "zfs jail "${_jid}" ${_ds} 2>/dev/null"
+					zfs jail "${_jid}" ${_ds} 2>/dev/null
+				fi
+			done
+		fi
+	done
+
+	echo
+}
+
+jail2_stop()
+{
+	echo -n "Stopping jails: "
+
+	for _j in ${jail2_list}; do
+     	echo -n "${_j} "
+
+		if [ ! -e /var/run/jail_${_j}.id ]; then
+			echo "${_j} doesn't exists"
+			continue
+		fi
+
+		eval _zfs=\"\${jail2_${_j}_zfs:-}\"
+		_jid=`jls -j ${_j} jid 2>/dev/null`
+
+		jail -r -q ${_j} > /dev/null 2>&1
+		rm /var/run/jail_${_j}.id
+
+		if [ -n "${_zfs}" ]; then
+			for _ds in ${_zfs}; do
+				_jailed=`zfs get -H jailed ${_ds} 2>/dev/null | awk '{ print $3 }'`
+				if [ "${_jailed}" = "on" ]; then
+					echo "zfs unjail "${_jid}" ${_ds} 2>/dev/null"
+					zfs unjail "${_jid}" ${_ds} 2>/dev/null
+				fi
+			done
+		fi
+	done
+
+	echo
+}
+
+load_rc_config $name
+: ${jail2_enable="NO"}
+
+cmd="$1"
+if [ $# -gt 0 ]; then
+	shift
+fi
+if [ -n "$*" ]; then
+	jail2_list="$*"
+fi
+
+run_rc_command "${cmd}"

Added: head/sysutils/jail2/pkg-descr
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sysutils/jail2/pkg-descr	Sun Jan 20 15:31:04 2013	(r310695)
@@ -0,0 +1,4 @@
+jail2 is an alternative rc script for jails, relying on jail.conf
+instead of rc.conf variables. Additionally, ZFS integration is provided.
+In contrast to the default jail rc script this one can run inside jails,
+allowing the configuration of hierarchical jails.
_______________________________________________
svn-ports-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-ports-all
To unsubscribe, send any mail to "svn-ports-all-unsubscribe@freebsd.org"