diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index 9698137a4bb6..8a5f436cc491 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -546,6 +546,9 @@ jail_sysvipc_allow="NO" # Allow SystemV IPC use from within a jail #jail_example_ip="192.168.0.10" # Jail's IP number #jail_example_interface="" # Interface to create the IP alias on #jail_example_exec_start="/bin/sh /etc/rc" # command to execute in jail for starting +#jail_example_exec_afterstart0="/bin/sh command" # command to execute after the one for + # starting the jail. More than one can be + # specified using a trailing number #jail_example_exec_stop="/bin/sh /etc/rc.shutdown" # command to execute in jail for stopping #jail_example_devfs_enable="NO" # mount devfs in the jail #jail_example_fdescfs_enable="NO" # mount fdescfs in the jail diff --git a/etc/rc.d/jail b/etc/rc.d/jail index c2636b593d82..2e01fd89c99d 100644 --- a/etc/rc.d/jail +++ b/etc/rc.d/jail @@ -36,6 +36,14 @@ init_variables() eval _interface=\"\${jail_${_j}_interface:-${jail_interface}}\" eval _exec=\"\$jail_${_j}_exec\" eval _exec_start=\"\${jail_${_j}_exec_start:-${jail_exec_start}}\" + + i=1 + while [ true ]; do + eval _exec_afterstart${i}=\"\${jail_${_j}_exec_afterstart${i}:-\${jail_exec_afterstart${i}}}\" + [ -z "$(eval echo \"\$_exec_afterstart${i}\")" ] && break + i=$((i + 1)) + done + eval _exec_stop=\"\${jail_${_j}_exec_stop:-${jail_exec_stop}}\" if [ -n "${_exec}" ]; then # simple/backward-compatible execution @@ -84,6 +92,19 @@ init_variables() debug "$_j ruleset: $_ruleset" debug "$_j fstab: $_fstab" debug "$_j exec start: $_exec_start" + + i=1 + while [ true ]; do + eval out=\"\${_exec_afterstart${i}:-''}\" + + if [ -z "$out" ]; then + break; + fi + + debug "$_j exec after start #${i}: ${out}" + i=$((i + 1)) + done + debug "$_j exec stop: $_exec_stop" debug "$_j flags: $_flags" @@ -221,9 +242,22 @@ jail_start() _tmp_jail=${_tmp_dir}/jail.$$ eval jail ${_flags} -i ${_rootdir} ${_hostname} \ ${_ip} ${_exec_start} > ${_tmp_jail} 2>&1 + if [ "$?" -eq 0 ] ; then - echo -n " $_hostname" _jail_id=$(head -1 ${_tmp_jail}) + i=1 + while [ true ]; do + eval out=\"\${_exec_afterstart${i}:-''}\" + + if [ -z "$out" ]; then + break; + fi + + jexec "${_jail_id}" ${out} + i=$((i + 1)) + done + + echo -n " $_hostname" tail +2 ${_tmp_jail} >${_rootdir}/var/log/console.log echo ${_jail_id} > /var/run/jail_${_jail}.id else diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index cef3c219bdc4..de9b3f799776 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd May 18, 2006 +.Dd May 29, 2006 .Dt RC.CONF 5 .Os .Sh NAME @@ -3085,6 +3085,13 @@ When set, use as default value for .Va jail_ Ns Ao Ar jname Ac Ns Va _exec_start for every jail in .Va jail_list . +.It Va jail_exec_afterstart Ns Aq Ar N +.Pq Vt str +Unset by default. +When set, use as default value for +.Va jail_ Ns Ao Ar jname Ac Ns Va _exec_afterstart Ns Aq Ar N +for every jail in +.Va jail_list . .It Va jail_exec_stop Unset by default. When set, use as default value for @@ -3176,6 +3183,15 @@ Set to .Dq Li /bin/sh /etc/rc by default. This is the command executed at jail startup. +.It Va jail_ Ns Ao Ar jname Ac Ns Va _exec_afterstart Ns Aq Ar N +.Pq Vt str +Unset by default. +This is the command run as +.Ar N Ns +th command +after jail startup, where +.Ar N +is 1, 2, and so on. .It Va jail_ Ns Ao Ar jname Ac Ns Va _exec_stop .Pq Vt str Set to