From owner-freebsd-jail@freebsd.org Mon Feb 8 22:57:42 2016 Return-Path: Delivered-To: freebsd-jail@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 30788AA2A8F for ; Mon, 8 Feb 2016 22:57:42 +0000 (UTC) (envelope-from jamie@gritton.org) Received: from gritton.org (gritton.org [162.220.209.3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "www.gritton.org", Issuer "StartCom Class 1 Primary Intermediate Server CA" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id EEB3B178F for ; Mon, 8 Feb 2016 22:57:41 +0000 (UTC) (envelope-from jamie@gritton.org) Received: from gritton.org (gritton.org [162.220.209.3]) by gritton.org (8.15.2/8.15.2) with ESMTPS id u18MvTAR036199 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Mon, 8 Feb 2016 15:57:29 -0700 (MST) (envelope-from jamie@gritton.org) Received: (from www@localhost) by gritton.org (8.15.2/8.15.2/Submit) id u18MvSTw036198; Mon, 8 Feb 2016 15:57:28 -0700 (MST) (envelope-from jamie@gritton.org) X-Authentication-Warning: gritton.org: www set sender to jamie@gritton.org using -f To: freebsd-jail@freebsd.org Subject: Re: exec_poststart X-PHP-Originating-Script: 0:rcube.php MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Mon, 08 Feb 2016 15:57:28 -0700 From: James Gritton Cc: markham breitbach In-Reply-To: <56B529AF.90901@ssimicro.com> References: <56B529AF.90901@ssimicro.com> Message-ID: <484049c61c523206507e2b06e6a0c948@gritton.org> X-Sender: jamie@gritton.org User-Agent: Roundcube Webmail/1.1.2 X-BeenThere: freebsd-jail@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "Discussion about FreeBSD jail\(8\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Feb 2016 22:57:42 -0000 On 2016-02-05 16:01, markham breitbach wrote: > I am trying to figure out how to get a script to figure out the > hostname > of the jail that is starting without having to manual set that as a > command line parameter (as illustrated). It seems that the script is > getting executed in a clean environment, regardless of the exec.clean > setting. Is this a bug? The man pages aren't particularly clear on > the > expected behaviour of this. I am running FreeBSD 10.2. > > I would like to be able to set exec.poststart as a global default so it > doesn't need to be defined per jail. > > Thanks, > -Markham > > ####################JAIL.CONF######################### > exec.clean = 0 ; > > # HOW TO PASS THE JAILNAME TO THIS SCRIPT? > exec.poststart += "/path/to/script.sh"; > > # My test jail > testjail_example_com { > # THIS WORKS > exec.poststart += "/path/to/script.sh testjail.example.com"; > exec.clean = 0 ; > host.hostname = "testjail.example.com"; > path = "/usr/jails/testjail.example.com"; > ip4.addr += "net0|192.0.2.1/24"; > exec.system_user = "root"; > exec.jail_user = "root"; > exec.start += "/bin/sh /etc/rc"; > exec.stop = ""; > exec.consolelog = "/var/log/jail_testjail_example_com_console.log"; > mount.fstab = "/etc/testjail_example_com"; > mount.devfs; > devfs_ruleset = "5"; > mount.fdescfs; > mount.procfs; > allow.mount; > allow.set_hostname = 0; > allow.sysvipc = 0; > allow.raw_sockets=1; > } You can reference jail parameters within other parameters, much like you'd use shell variables. In the global part of the definition, you can set: exec.poststart = "/path/to/script.sh ${host.hostname}" Then you won't need to define a separate exec.poststart within each jail. Note you can also do this with the path parameter, since your path is based on the hostname. And exec.consolelog and mount.fstab are based on the jail name, so you can similarly globally set something like mount.fstab = "/etc/$name". exec.clean=0 should indeed avoid scrubbing the environment, but note that if your jail starts by running /etc/rc, the top of rc will reset at least the path on its own, probably other stuff as well. - Jamie