Date: Tue, 30 Jan 2018 19:16:38 +0000 (UTC) From: Kyle Evans <kevans@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r328599 - stable/11/usr.sbin/service Message-ID: <201801301916.w0UJGc18054366@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kevans Date: Tue Jan 30 19:16:38 2018 New Revision: 328599 URL: https://svnweb.freebsd.org/changeset/base/328599 Log: MFC r328032,r328060,r328243: service(8): Support services in jails MFC r328032: service(8): Add support for interfacing with services in jails Provide a -j option that can take a jail name or id. If -j is specified, check that the jail exists and proxy the service request through to service(8) in the jail. This allows for cleaner workflows when updating services in a jail, turning the following: pkg -j dns upgrade jexec dns service named restart into: pkg -j dns upgrade service -j dns named restart MFC r328060: service(8): Reset OPTIND properly now that we parse args twice r328032 introduced a second round of argument parsing to proxy the request through to a jail as needed, but failed to reset OPTIND before getting to the second round of parsing to allow other flags to be set. MFC r328243: usr.sbin/service: Fix -j to not be order dependant The introduced -j option is highly dependant on the ordering of arguments, and it exhibited broken behavior in some other circumstances. Fix these issues, and simplify the feature by removing the unneessary double parsing of options. PR: 223325 Modified: stable/11/usr.sbin/service/service.8 stable/11/usr.sbin/service/service.sh Directory Properties: stable/11/ (props changed) Modified: stable/11/usr.sbin/service/service.8 ============================================================================== --- stable/11/usr.sbin/service/service.8 Tue Jan 30 18:29:38 2018 (r328598) +++ stable/11/usr.sbin/service/service.8 Tue Jan 30 19:16:38 2018 (r328599) @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd December 11, 2012 +.Dd January 15, 2018 .Dt SERVICE 8 .Os .Sh NAME @@ -32,13 +32,17 @@ .Nd "control (start/stop/etc.) or list system services" .Sh SYNOPSIS .Nm +.Op Fl j Ao jail name or id Ac .Fl e .Nm +.Op Fl j Ao jail name or id Ac .Fl R .Nm +.Op Fl j Ao jail name or id Ac .Op Fl v .Fl l | r .Nm +.Op Fl j Ao jail name or id Ac .Op Fl v .Ar <rc.d script> start|stop|etc. .Sh DESCRIPTION @@ -54,6 +58,8 @@ the scripts using various criteria. .Pp The options are as follows: .Bl -tag -width F1 +.It Fl j Ao jail name or id Ac +Perform the given actions under the named jail. .It Fl e List services that are enabled. The list of scripts to check is compiled using @@ -107,6 +113,7 @@ The following are examples of typical usage of the command: .Pp .Dl "service named status" +.Dl "service -j dns named status" .Dl "service -rv" .Pp The following programmable completion entry can be use in Modified: stable/11/usr.sbin/service/service.sh ============================================================================== --- stable/11/usr.sbin/service/service.sh Tue Jan 30 18:29:38 2018 (r328598) +++ stable/11/usr.sbin/service/service.sh Tue Jan 30 19:16:38 2018 (r328599) @@ -32,12 +32,13 @@ load_rc_config 'XXX' usage () { echo '' echo 'Usage:' - echo "${0##*/} -e" - echo "${0##*/} -R" - echo "${0##*/} [-v] -l | -r" - echo "${0##*/} [-v] <rc.d script> start|stop|etc." + echo "${0##*/} [-j <jail name or id>] -e" + echo "${0##*/} [-j <jail name or id>] -R" + echo "${0##*/} [-j <jail name or id>] [-v] -l | -r" + echo "${0##*/} [-j <jail name or id>] [-v] <rc.d script> start|stop|etc." echo "${0##*/} -h" echo '' + echo "-j Perform actions within the named jail" echo '-e Show services that are enabled' echo "-R Stop and start enabled $local_startup services" echo "-l List all scripts in /etc/rc.d and $local_startup" @@ -46,8 +47,9 @@ usage () { echo '' } -while getopts 'ehlrRv' COMMAND_LINE_ARGUMENT ; do +while getopts 'j:ehlrRv' COMMAND_LINE_ARGUMENT ; do case "${COMMAND_LINE_ARGUMENT}" in + j) JAIL="${OPTARG}" ;; e) ENABLED=eopt ;; h) usage ; exit 0 ;; l) LIST=lopt ;; @@ -58,6 +60,22 @@ while getopts 'ehlrRv' COMMAND_LINE_ARGUMENT ; do esac done shift $(( $OPTIND - 1 )) + +if [ -n "${JAIL}" ]; then + # We need to rebuild the command line before passing it on. + # We do not send the -j argument into the jail. + args="" + [ -n "${ENABLED}" ] && args="${args} -e" + [ -n "${LIST}" ] && args="${args} -l" + [ -n "${RCORDER}" ] && args="${args} -r" + [ -n "${RESTART}" ] && args="${args} -R" + [ -n "${VERBOSE}" ] && args="${args} -v" + + # Call jexec(8) with the rebuild args and any positional args that + # were left in $@ + /usr/sbin/jexec -l "${JAIL}" /usr/sbin/service $args "$@" + exit $? +fi if [ -n "$RESTART" ]; then skip="-s nostart"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201801301916.w0UJGc18054366>