Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 31 Dec 2012 08:10:20 GMT
From:      Yamagi Burmeister <yamagi@yamagi.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   ports/174856: [NEW PORT]: sysutils/jail2 - another jail rc-script, this time for jail.conf jails
Message-ID:  <201212310810.qBV8AKE2060590@red.freebsd.org>
Resent-Message-ID: <201212310820.qBV8K07l070405@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         174856
>Category:       ports
>Synopsis:       [NEW PORT]: sysutils/jail2 - another jail rc-script, this time for jail.conf jails
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Dec 31 08:20:00 UTC 2012
>Closed-Date:
>Last-Modified:
>Originator:     Yamagi Burmeister
>Release:        FreeBSD 9.1
>Organization:
>Environment:
FreeBSD happy.home.yamagi.org 9.1-RELEASE FreeBSD 9.1-RELEASE #0 r243792M: Sun Dec  2 17:53:10 CET 2012     root@happy.home.yamagi.org:/usr/obj/usr/src/sys/HAPPY  amd64
>Description:
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:
-
>Fix:
# This is a shell archive.  Save it in a file, remove anything before
# this line, and then unpack it by entering "sh file".  Note, it may
# create directories; files and directories will be owned by you and
# have default permissions.
#
# This archive contains:
#
#	jail2
#	jail2/files
#	jail2/files/jail2.in
#	jail2/pkg-descr
#	jail2/Makefile
#
echo c - jail2
mkdir -p jail2 > /dev/null 2>&1
echo c - jail2/files
mkdir -p jail2/files > /dev/null 2>&1
echo x - jail2/files/jail2.in
sed 's/^X//' >jail2/files/jail2.in << '16a6c5557e83ea0912b4b8ab95367891'
X#!/bin/sh
X
X# Alternative rc script for jails. This script relies on
X# /etc/jail.conf instead of rc.conf variables. Usage:
X#
X# jail2_enable	   -> Enables the script
X# jail2_list	   -> List of jails to be started. The names
X#				      must match the names in /etc/jail.conf
X# jail2_$name_zfs  -> List of ZFS datasets to connect to the
X#					  jail $name.
X#
X# To manage ZFS datasets within a jail the dataset must have
X# set the parameter "jailed" to 1. Additionally the jail must
X# have set the proberties "allow.mount", "allow.mount.zfs"
X# and "enforce_statfs" to value lesser than 2.
X
X# PROVIDE: jail
X# REQUIRE: LOGIN cleanvar
X# BEFORE: securelevel
X# KEYWORD: shutdown
X
X. /etc/rc.subr
X
Xname="jail2"
Xrcvar=jail2_enable
X
Xstart_cmd="jail2_start"
Xstop_cmd="jail2_stop"
X
Xjail2_start()
X{
X	echo -n "Starting jails: "
X
X	for _j in ${jail2_list}; do
X		echo -n "${_j} "
X
X		if [ -e /var/run/jail_${_j}.id ]; then
X			echo "${_j} already exists"
X			continue
X		fi
X
X		jail -c -i -J /var/run/jail_${_j}.id ${_j} > /dev/null 2>&1
X
X		eval _zfs=\"\${jail2_${_j}_zfs:-}\"
X		_jid=`jls -j ${_j} jid 2>/dev/null`
X
X		if [ -n "${_zfs}" ]; then
X			for _ds in ${_zfs}; do
X				_jailed=`zfs get -H jailed ${_ds} 2>/dev/null | awk '{ print $3 }'`
X				if [ "${_jailed}" = "on" ]; then
X					echo "zfs jail "${_jid}" ${_ds} 2>/dev/null"
X					zfs jail "${_jid}" ${_ds} 2>/dev/null
X				fi
X			done
X		fi
X	done
X
X	echo
X}
X
Xjail2_stop()
X{
X	echo -n "Stopping jails: "
X
X	for _j in ${jail2_list}; do
X     	echo -n "${_j} "
X
X		if [ ! -e /var/run/jail_${_j}.id ]; then
X			echo "${_j} doesn't exists"
X			continue
X		fi
X
X		eval _zfs=\"\${jail2_${_j}_zfs:-}\"
X		_jid=`jls -j ${_j} jid 2>/dev/null`
X
X		jail -r -q ${_j} > /dev/null 2>&1
X		rm /var/run/jail_${_j}.id
X
X		if [ -n "${_zfs}" ]; then
X			for _ds in ${_zfs}; do
X				_jailed=`zfs get -H jailed ${_ds} 2>/dev/null | awk '{ print $3 }'`
X				if [ "${_jailed}" = "on" ]; then
X					echo "zfs unjail "${_jid}" ${_ds} 2>/dev/null"
X					zfs unjail "${_jid}" ${_ds} 2>/dev/null
X				fi
X			done
X		fi
X	done
X
X	echo
X}
X
Xload_rc_config $name
X: ${jail2_enable="NO"}
X
Xcmd="$1"
Xif [ $# -gt 0 ]; then
X	shift
Xfi
Xif [ -n "$*" ]; then
X	jail2_list="$*"
Xfi
X
Xrun_rc_command "${cmd}"
16a6c5557e83ea0912b4b8ab95367891
echo x - jail2/pkg-descr
sed 's/^X//' >jail2/pkg-descr << 'ed4ba63968e8f4533a155b7c0e7567d1'
Xjail2 is an alternative rc script for jails, relying on jail.conf
Xinstead of rc.conf variables. Additionally, ZFS integration is provided.
XIn contrast to the default jail rc script this one can run inside jails,
Xallowing the configuration of hierarchical jails.
ed4ba63968e8f4533a155b7c0e7567d1
echo x - jail2/Makefile
sed 's/^X//' >jail2/Makefile << '244169e487ff8dd224c47b19f508f4f0'
X# New ports collection makefile for:	jail2
X# Date created:	   21 October 2012
X# Whom:		   Yamagi Burmeister <yamagi@yamagi.org>
X#
X# $FreeBSD$
X#
X
XPORTNAME=	jail2
XPORTVERSION=	1.0
XCATEGORIES=	sysutils
XMASTER_SITES=	#
XDISTFILES=	#
X
XMAINTAINER=	yamagi@yamagi.org
XCOMMENT=	Jail startup/shutdown script with jail.conf support
X
XNO_BUILD=	yes
XNO_INSTALL=	yes
X
XUSE_RC_SUBR=	jail2
X
X.include <bsd.port.mk>
244169e487ff8dd224c47b19f508f4f0
exit 

>Release-Note:
>Audit-Trail:
>Unformatted:



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