From 758872381cb689901c55ee10158cbf06fb7bb46d Mon Sep 17 00:00:00 2001 From: jamie Date: Sat, 30 Apr 2016 15:06:18 +0000 Subject: [PATCH] MFC r295471: Add new rc.conf parameter "jail_reverse_stop" When a user defines "jail_list" in rc.conf the jails are started in the order defined. Currently the jails are not are stopped in reverse order which may break dependencies between jails/services and prevent a clean shutdown. The new parameter "jail_reverse_stop" will shutdown jails in "jail_list" in reverse order when set to "YES". Please note that this does not affect manual invocation of the jail rc script. If a user runs the command # service jail stop jail1 jail2 jail3 the jails will be stopped in exactly the order specified regardless of jail_reverse_stop being defined in rc.conf. MFC r295568: Document the new jail_reverse_stop parameter While here clean up the documentation for jail_list PR: 196152 Submitted by: feld git-svn-id: svn://svn.freebsd.org/base/stable/10@298852 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- etc/defaults/rc.conf | 1 + etc/rc.d/jail | 10 ++++++++-- share/man/man5/rc.conf.5 | 28 +++++++++++++++------------- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/etc/defaults/rc.conf b/etc/defaults/rc.conf index ddaf657eb..cafdd2e8f 100644 --- a/etc/defaults/rc.conf +++ b/etc/defaults/rc.conf @@ -700,6 +700,7 @@ rctl_rules="/etc/rctl.conf" # rctl(8) ruleset. See rctl.conf(5). jail_enable="NO" # Set to NO to disable starting of any jails jail_parallel_start="NO" # Start jails in the background jail_list="" # Space separated list of names of jails +jail_reverse_stop="NO" # Stop jails in reverse order ############################################################## ### Define source_rc_confs, the mechanism used by /etc/rc.* ## diff --git a/etc/rc.d/jail b/etc/rc.d/jail index b2fd452a2..f8fd4aa83 100755 --- a/etc/rc.d/jail +++ b/etc/rc.d/jail @@ -517,7 +517,11 @@ jail_stop() command=$jail_program rc_flags=$jail_flags command_args="-f $jail_conf -r" - $jail_jls name | while read _j; do + if checkyesno jail_reverse_stop; then + $jail_jls name | tail -r + else + $jail_jls name + fi | while read _j; do echo -n " $_j" _tmp=`mktemp -t jail` || exit 3 $command $rc_flags $command_args $_j >> $_tmp 2>&1 @@ -532,6 +536,7 @@ jail_stop() return ;; esac + checkyesno jail_reverse_stop && set -- $(reverse_list $@) for _j in $@; do _j=$(echo $_j | tr /. _) _jv=$(echo -n $_j | tr -c '[:alnum:]' _) @@ -567,5 +572,6 @@ jail_warn() load_rc_config $name case $# in 1) run_rc_command $@ ${jail_list:-_ALL} ;; -*) run_rc_command $@ ;; +*) jail_reverse_stop="no" + run_rc_command $@ ;; esac diff --git a/share/man/man5/rc.conf.5 b/share/man/man5/rc.conf.5 index f354c7c7b..62399c672 100644 --- a/share/man/man5/rc.conf.5 +++ b/share/man/man5/rc.conf.5 @@ -3938,20 +3938,22 @@ for every jail in .Va jail_list . .It Va jail_list .Pq Vt str -A space separated list of names for jails. -If this variable is empty, -all of +A space-delimited list of jail names. +When left empty, all of the .Xr jail 8 -instances in the configuration file will be configured. -This is purely a configuration aid to help identify and -configure multiple jails. -The names specified in this list will be used to -identify settings common to an instance of a jail, -and should contain alphanumeric characters only. -The literal jail name of -.Dq Li 0 -.Pq zero -is not allowed. +instances defined in the configuration file are started. +The names specified in this list control the jail startup order. +.Xr jail 8 +instances missing from +.Va jail_list +must be started manually. +.It Va jail_reverse_stop +.Pq Vt bool +When set to +.Dq Li YES , +all configured jails in +.Va jail_list +are stopped in reverse order. .It Va jail_* variables Note that older releases supported per-jail configuration via .Xr rc.conf 5 -- 2.45.0