From owner-svn-src-stable-11@freebsd.org Tue Jan 30 19:16:39 2018 Return-Path: Delivered-To: svn-src-stable-11@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 47858EDD15B; Tue, 30 Jan 2018 19:16:39 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id D91487C75E; Tue, 30 Jan 2018 19:16:38 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C52081B5D0; Tue, 30 Jan 2018 19:16:38 +0000 (UTC) (envelope-from kevans@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w0UJGcBg054368; Tue, 30 Jan 2018 19:16:38 GMT (envelope-from kevans@FreeBSD.org) Received: (from kevans@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0UJGc18054366; Tue, 30 Jan 2018 19:16:38 GMT (envelope-from kevans@FreeBSD.org) Message-Id: <201801301916.w0UJGc18054366@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: kevans set sender to kevans@FreeBSD.org using -f From: Kyle Evans Date: Tue, 30 Jan 2018 19:16:38 +0000 (UTC) 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 X-SVN-Group: stable-11 X-SVN-Commit-Author: kevans X-SVN-Commit-Paths: stable/11/usr.sbin/service X-SVN-Commit-Revision: 328599 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-11@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for only the 11-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 30 Jan 2018 19:16:39 -0000 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 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] start|stop|etc." + echo "${0##*/} [-j ] -e" + echo "${0##*/} [-j ] -R" + echo "${0##*/} [-j ] [-v] -l | -r" + echo "${0##*/} [-j ] [-v] 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"