From skv@FreeBSD.org  Mon Jun 12 11:30:21 2006
Return-Path: <skv@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id F3A2316A4D6
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 12 Jun 2006 11:30:20 +0000 (UTC)
	(envelope-from skv@FreeBSD.org)
Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 6AAF043D8C
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 12 Jun 2006 11:30:15 +0000 (GMT)
	(envelope-from skv@FreeBSD.org)
Received: from freefall.freebsd.org (skv@localhost [127.0.0.1])
	by freefall.freebsd.org (8.13.4/8.13.4) with ESMTP id k5CBUFIq003078
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 12 Jun 2006 11:30:15 GMT
	(envelope-from skv@freefall.freebsd.org)
Received: (from skv@localhost)
	by freefall.freebsd.org (8.13.4/8.13.4/Submit) id k5CBUEAE003076;
	Mon, 12 Jun 2006 11:30:14 GMT
	(envelope-from skv)
Message-Id: <200606121130.k5CBUEAE003076@freefall.freebsd.org>
Date: Mon, 12 Jun 2006 11:30:14 GMT
From: skv@freebsd.org
Reply-To: skv@freebsd.org
To: FreeBSD-gnats-submit@freebsd.org
Subject: Templatize 'jail_rootdir' in /etc/rc.d/jail 
X-Send-Pr-Version: 3.2

>Number:         98846
>Category:       conf
>Synopsis:       [jail] [patch] Templatize 'jail_rootdir' in /etc/rc.d/jail
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    bz
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Mon Jun 12 11:40:18 GMT 2006
>Closed-Date:    Sat Nov 29 17:43:15 UTC 2008
>Last-Modified:  Sat Nov 29 17:43:15 UTC 2008
>Originator:     Sergey Skvortsov
>Release:        FreeBSD 6.1-STABLE i386
>Organization:
<Organization of PR author (multiple lines)>
>Environment:

	<Relevant environment information (multiple lines)>

>Description:

Allow define common template for all jail's rootdir.

>How-To-Repeat:

/etc/rc.conf.d/jail:
jail_rootdir="/data/jails/%%JAIL_IP%%"		# TEMPLATE 0
#jail_rootdir="/data/jails/%%JAIL_HOSTNAME%%"	# TEMPLATE 1
#jail_rootdir="/data/jails/%%JAIL_ID%%"		# TEMPLATE 2
jail_list="host1 host2"

jail_host1_hostname="host1.mydomain.com"
jail_host1_ip="192.168.6.1"

jail_host2_hostname="host2.mydomain.com"
jail_host2_ip="192.168.6.2"

after expanding:

jail_host1_rootdir="/data/jails/192.168.6.1"		# TEMPLATE 0
#jail_host1_rootdir="/data/jails/host1.mydomain.com"	# TEMPLATE 1
#jail_host1_rootdir="/data/jails/host1"			# TEMPLATE 2

>Fix:

Note that this patch is efficient enough, because global template
$jail_rootdir is applied only if relevant $jail_<JID>_rootdir is missed.

--- jail.orig	Fri Jun  9 20:04:50 2006
+++ jail	Mon Jun 12 15:11:32 2006
@@ -27,12 +27,28 @@
 		return
 	fi
 
+	eval _hostname=\"\$jail_${_j}_hostname\"
+	if [ -z "${_hostname}" ]; then
+		err 3 "$name: No hostname has been defined for ${_j}"
+	fi
+
+	eval _ip=\"\$jail_${_j}_ip\"
+	if [ -z "${_ip}" ]; then
+		err 3 "$name: No IP address has been defined for ${_j}"
+	fi
+
 	eval _rootdir=\"\$jail_${_j}_rootdir\"
+	if [ -z "${_rootdir}" ]; then
+		if [ -z "${jail_rootdir}" ]; then
+			err 3 "$name: No root directory has been defined for ${_j}"
+		fi
+		_rootdir=$(echo "${jail_rootdir}" |
+			sed -e "s=%%JAIL_ID%%=${_j}=;s=%%JAIL_IP%%=${_ip}=;s=%%JAIL_HOSTNAME%%=${_hostname}=")
+	fi
+
 	_devdir="${_rootdir}/dev"
 	_fdescdir="${_devdir}/fd"
 	_procdir="${_rootdir}/proc"
-	eval _hostname=\"\$jail_${_j}_hostname\"
-	eval _ip=\"\$jail_${_j}_ip\"
 	eval _interface=\"\${jail_${_j}_interface:-${jail_interface}}\"
 	eval _exec=\"\$jail_${_j}_exec\"
 	eval _exec_start=\"\${jail_${_j}_exec_start:-${jail_exec_start}}\"
@@ -86,16 +102,6 @@
 	debug "$_j exec start: $_exec_start"
 	debug "$_j exec stop: $_exec_stop"
 	debug "$_j flags: $_flags"
-
-	if [ -z "${_hostname}" ]; then
-		err 3 "$name: No hostname has been defined for ${_j}"
-	fi
-	if [ -z "${_rootdir}" ]; then
-		err 3 "$name: No root directory has been defined for ${_j}"
-	fi
-	if [ -z "${_ip}" ]; then
-		err 3 "$name: No IP address has been defined for ${_j}"
-	fi
 
 }
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-rc 
Responsible-Changed-By: skv 
Responsible-Changed-When: Mon Jun 12 11:41:26 UTC 2006 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98846 

From: Florent Thoumie <flz@FreeBSD.org>
To: bug-followup@FreeBSD.org
Cc: skv@FreeBSD.org
Subject: Re: conf/98846
Date: Mon, 26 Jun 2006 14:58:21 +0100

 --=-UDW39REALJLDeLy4u53n
 Content-Type: text/plain
 Content-Transfer-Encoding: quoted-printable
 
 I'd rather like something like this patch being committed :
 
 http://people.freebsd.org/~flz/local/jail-rootdir-tpl.diff
 
 Then just use in rc.conf:
 
 jail_rootdir=3D"/path/to/jails/\${_name}/" or
 jail_rootdir=3D"/path/to/jails/\${_hostname}/" or
 jail_rootdir=3D"/path/to/jails/\${_ip}/"
 
 I'm not overly excited in using %%FOO%% (either in rc.conf or fstab)
 like we do in ports. I'll try to find a cleaner solution for your fstab
 templating proposal. I definitely like the idea though.
 
 --=20
 Florent Thoumie
 flz@FreeBSD.org
 FreeBSD Committer
 
 --=-UDW39REALJLDeLy4u53n
 Content-Type: application/pgp-signature; name=signature.asc
 Content-Description: This is a digitally signed message part
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.3 (FreeBSD)
 
 iD8DBQBEn+f7MxEkbVFH3PQRAsFhAJ98c6fh0Dq94HT1uaNvKIRc8Xvs8gCeOEvl
 4zDw27Ee2KHb8tz5uNr7wOY=
 =PBke
 -----END PGP SIGNATURE-----
 
 --=-UDW39REALJLDeLy4u53n--
 
Responsible-Changed-From-To: freebsd-rc->flz 
Responsible-Changed-By: flz 
Responsible-Changed-When: Mon Jun 26 18:58:07 UTC 2006 
Responsible-Changed-Why:  
Grab. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98846 
Responsible-Changed-From-To: flz->freebsd-rc 
Responsible-Changed-By: flz 
Responsible-Changed-When: Mon Sep 25 23:02:27 UTC 2006 
Responsible-Changed-Why:  
Submitter refused my patch. I'll let somebody else handle it. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98846 
State-Changed-From-To: open->closed 
State-Changed-By: bz 
State-Changed-When: Sat Nov 29 17:42:51 UTC 2008 
State-Changed-Why:  
Our startup scripts are no template system or management  
framework. Please use something from ports or elsewhere 
to manage jails if you want features like this. 


Responsible-Changed-From-To: freebsd-rc->bz 
Responsible-Changed-By: bz 
Responsible-Changed-When: Sat Nov 29 17:42:51 UTC 2008 
Responsible-Changed-Why:  
I'll track possible follow-ups. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=98846 
>Unformatted:
