Module Name: src Committed By: snj Date: Tue Apr 21 05:22:58 UTC 2015
Modified Files: src/distrib/sets/lists/base [netbsd-7]: mi src/distrib/sets/lists/man [netbsd-7]: mi src/doc [netbsd-7]: CHANGES src/usr.sbin [netbsd-7]: Makefile Added Files: src/usr.sbin/service [netbsd-7]: Makefile service service.8 Log Message: Pull up following revision(s) (requested by ast in ticket #636): distrib/sets/lists/base/mi: revision 1.1098 distrib/sets/lists/man/mi: revision 1.1498 doc/CHANGES: patch usr.sbin/Makefile: revision 1.270 usr.sbin/service/Makefile: revision 1.1 usr.sbin/service/service: revision 1.1-1.7 usr.sbin/service/service.8: revisions 1.1-1.4 Import a substantially modified service(8) command from FreeBSD to manage rc.d scripts. This command is well known on most other Unixes and should help soften the learning curve for Unix admins coming to NetBSD. -- Make the usage appear more standard. -- Sort options. Use An -nosplit in AUTHORS section. -- Remove -f option as rc_fast is not set in invocation mode. Do the load_rc_config *after* option parsing. Catch conflicting -e + -l option specs. -- Integrate some feedback gleened from tech-userle...@netbsd.org Avoid ls -P so that script can also run pre-netbsd-7. Make sure /etc/rc.conf.d configurations are supported. -- cosmetic change in man 8 service use shell quoting in a safe way as suggested by Alan Barrett -- More shell quoting. /etc/rc.d/* file names with embedded spaces are not expected to work, but let's quote them anyway. To generate a diff of this commit: cvs rdiff -u -r1.1087.2.3 -r1.1087.2.4 src/distrib/sets/lists/base/mi cvs rdiff -u -r1.1485.2.6 -r1.1485.2.7 src/distrib/sets/lists/man/mi cvs rdiff -u -r1.1967.2.11 -r1.1967.2.12 src/doc/CHANGES cvs rdiff -u -r1.269 -r1.269.2.1 src/usr.sbin/Makefile cvs rdiff -u -r0 -r1.1.2.2 src/usr.sbin/service/Makefile cvs rdiff -u -r0 -r1.7.2.2 src/usr.sbin/service/service cvs rdiff -u -r0 -r1.4.2.2 src/usr.sbin/service/service.8 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/base/mi diff -u src/distrib/sets/lists/base/mi:1.1087.2.3 src/distrib/sets/lists/base/mi:1.1087.2.4 --- src/distrib/sets/lists/base/mi:1.1087.2.3 Wed Jan 28 19:00:28 2015 +++ src/distrib/sets/lists/base/mi Tue Apr 21 05:22:58 2015 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1087.2.3 2015/01/28 19:00:28 martin Exp $ +# $NetBSD: mi,v 1.1087.2.4 2015/04/21 05:22:58 snj Exp $ # # Note: Don't delete entries from here - mark them as "obsolete" instead, # unless otherwise stated below. @@ -1673,6 +1673,7 @@ ./usr/sbin/scriptdump base-obsolete obsolete ./usr/sbin/sdpd base-sysutil-bin ./usr/sbin/sendmail base-mailwrapper-bin +./usr/sbin/service base-sysutil-bin ./usr/sbin/services_mkdb base-sysutil-bin ./usr/sbin/sesd base-sysutil-bin ./usr/sbin/setencstat base-sysutil-bin Index: src/distrib/sets/lists/man/mi diff -u src/distrib/sets/lists/man/mi:1.1485.2.6 src/distrib/sets/lists/man/mi:1.1485.2.7 --- src/distrib/sets/lists/man/mi:1.1485.2.6 Thu Mar 26 10:54:35 2015 +++ src/distrib/sets/lists/man/mi Tue Apr 21 05:22:58 2015 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1485.2.6 2015/03/26 10:54:35 martin Exp $ +# $NetBSD: mi,v 1.1485.2.7 2015/04/21 05:22:58 snj Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -2943,6 +2943,7 @@ ./usr/share/man/cat8/sdpd.0 man-sysutil-catman .cat ./usr/share/man/cat8/security.0 man-obsolete obsolete ./usr/share/man/cat8/sendmail.0 man-obsolete obsolete +./usr/share/man/cat8/service.0 man-sysutil-catman .cat ./usr/share/man/cat8/services_mkdb.0 man-sysutil-catman .cat ./usr/share/man/cat8/sesd.0 man-sysutil-catman .cat ./usr/share/man/cat8/setencstat.0 man-sysutil-catman .cat @@ -5739,6 +5740,7 @@ ./usr/share/man/html8/scsictl.html man-sysutil-htmlman html ./usr/share/man/html8/sdpd.html man-sysutil-htmlman html ./usr/share/man/html8/security.html man-obsolete obsolete +./usr/share/man/html8/service.html man-sysutil-htmlman html ./usr/share/man/html8/services_mkdb.html man-sysutil-htmlman html ./usr/share/man/html8/sesd.html man-sysutil-htmlman html ./usr/share/man/html8/setencstat.html man-sysutil-htmlman html @@ -8821,6 +8823,7 @@ ./usr/share/man/man8/sdpd.8 man-sysutil-man .man ./usr/share/man/man8/security.8 man-obsolete obsolete ./usr/share/man/man8/sendmail.8 man-obsolete obsolete +./usr/share/man/man8/service.8 man-sysutil-man .man ./usr/share/man/man8/services_mkdb.8 man-sysutil-man .man ./usr/share/man/man8/sesd.8 man-sysutil-man .man ./usr/share/man/man8/setencstat.8 man-sysutil-man .man Index: src/doc/CHANGES diff -u src/doc/CHANGES:1.1967.2.11 src/doc/CHANGES:1.1967.2.12 --- src/doc/CHANGES:1.1967.2.11 Wed Mar 25 16:44:34 2015 +++ src/doc/CHANGES Tue Apr 21 05:22:58 2015 @@ -1,4 +1,4 @@ -# LIST OF CHANGES FROM LAST RELEASE: <$Revision: 1.1967.2.11 $> +# LIST OF CHANGES FROM LAST RELEASE: <$Revision: 1.1967.2.12 $> # # # [Note: This file does not mention every change made to the NetBSD source tree. @@ -21,7 +21,7 @@ # # See htutils/changes/changes2html script for more details. # -LIST OF CHANGES FROM PREVIOUS RELEASES: <$Revision: 1.1967.2.11 $> +LIST OF CHANGES FROM PREVIOUS RELEASES: <$Revision: 1.1967.2.12 $> Changes from NetBSD 6.0 to NetBSD 7.0: @@ -523,3 +523,4 @@ Changes from NetBSD 6.0 to NetBSD 7.0: processed sooner. [tls 20141026] viornd(4): Add driver for VirtIO entropy source available on QEMU, KVM, and Google Compute Engine. From OpenBSD. + service(8): Import adapted script from FreeBSD [ast 20150322] Index: src/usr.sbin/Makefile diff -u src/usr.sbin/Makefile:1.269 src/usr.sbin/Makefile:1.269.2.1 --- src/usr.sbin/Makefile:1.269 Sat Jul 26 19:32:37 2014 +++ src/usr.sbin/Makefile Tue Apr 21 05:22:58 2015 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.269 2014/07/26 19:32:37 dholland Exp $ +# $NetBSD: Makefile,v 1.269.2.1 2015/04/21 05:22:58 snj Exp $ # from: @(#)Makefile 5.20 (Berkeley) 6/12/93 .include <bsd.own.mk> @@ -24,7 +24,8 @@ SUBDIR= ac accton acpitools altq apm apm quot quotacheck quotaon quotarestore \ rarpd rbootd rdate repquota rmt rpc.bootparamd rpc.lockd \ rpc.pcnfsd rpc.statd rpcbind rwhod \ - sa screenblank sdpd services_mkdb sesd schedctl sliplogin spray \ + sa screenblank sdpd service services_mkdb sesd schedctl \ + sliplogin spray \ srtconfig sti sunlabel sup sysinst syslogd \ tadpolectl tcpdchk tcpdmatch tcpdrop timed tpctl tprof traceroute trpt \ unlink usbdevs user \ Added files: Index: src/usr.sbin/service/Makefile diff -u /dev/null src/usr.sbin/service/Makefile:1.1.2.2 --- /dev/null Tue Apr 21 05:22:59 2015 +++ src/usr.sbin/service/Makefile Tue Apr 21 05:22:58 2015 @@ -0,0 +1,9 @@ +# $NetBSD: Makefile,v 1.1.2.2 2015/04/21 05:22:58 snj Exp $ + +FILES= service +MAN= service.8 + +FILESDIR= /usr/sbin +FILESMODE= ${BINMODE} + +.include <bsd.prog.mk> Index: src/usr.sbin/service/service diff -u /dev/null src/usr.sbin/service/service:1.7.2.2 --- /dev/null Tue Apr 21 05:22:59 2015 +++ src/usr.sbin/service/service Tue Apr 21 05:22:58 2015 @@ -0,0 +1,126 @@ +#!/bin/sh +# $NetBSD: service,v 1.7.2.2 2015/04/21 05:22:58 snj Exp $ +# service -- run or list system services +# +# Taken from FreeBSD: releng/10.1/usr.sbin/service/service.sh 268098 +# Modified for NetBSD by Adrian Steinmann in March, 2015 +# +# Copyright (c) 2009 Douglas Barton +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. + +export PATH=/sbin:/bin:/usr/sbin:/usr/bin + +usage () +{ + local me="${0##*/}" + echo "usage: ${me} [-elv]" + echo " ${me} [-ev] rc_script_name [rc_script_name2 [...]]" + echo " ${me} [-v] rc_script_name action" + echo " -e: List enabled scripts; check if given scripts are enabled" + echo " -l: List all scripts in rcorder" + echo " -v: Verbose (mention in which directory script is found)" + echo "rc_directories is currently set to ${rc_directories}" + exit 1 +} + +# list all files in rc_directories with absolute pathnames +# written to be compatible with ls(1) from pre netbsd-7 +_rc_files() +{ + local _d _f + for _d in ${rc_directories}; do + if [ -d "$_d" ]; then + for _f in "$_d"/*; do + [ -f "$_f" -a -x "$_f" ] && echo "$_f" + done + fi + done | xargs rcorder -s nostart ${rc_rcorder_flags} 2>/dev/null + return 0 +} + +while getopts elv o; do + case "$o" in + e) ENABLED=1 ;; + l) LIST=1 ;; + v) VERBOSE=1 ;; + *) usage ;; + esac +done +shift $( expr $OPTIND - 1 ) + +[ -n "${ENABLED}" -a -n "${LIST}" ] && usage + +. /etc/rc.subr +load_rc_config : + +if [ -n "${ENABLED}" ]; then + [ -n "${VERBOSE}" ] && echo "rc_directories is ${rc_directories}" >&2 + flt=cat + if [ $# -gt 0 ] + then + flt=$( echo $* | sed -e 's; ;|;g' -e 's;^;egrep /(;' -e 's;$;)$;' ) + fi + _rc_files | $flt | while read file + do + if grep -q ^rcvar "$file"; then + eval $( grep ^name= "$file" ) + eval $( grep ^rcvar "$file" ) + if [ -n "${rcvar}" ]; then + load_rc_config ${rcvar} + checkyesno ${rcvar} 2>/dev/null && echo ${file} + fi + fi + done + exit 0 +fi + +if [ -n "${LIST}" ]; then + [ -n "${VERBOSE}" ] && echo "rc_directories is ${rc_directories}" >&2 + _rc_files + exit 0 +fi + +if [ $# -eq 2 ]; then + script=$1 + arg=$2 +else + usage +fi + +for dir in ${rc_directories}; do + if [ -x "${dir}/${script}" ]; then + [ -n "${VERBOSE}" ] && echo "${script} is located in ${dir}" >&2 + # run as in /etc/rc + cd / + umask 022 + exec env -i \ + HOME=/ PATH=/sbin:/bin:/usr/sbin:/usr/bin \ + "${dir}/${script}" "${arg}" + echo "Failed to exec ${dir}/${script} ${arg}" >&2 + exit 255 + fi +done + +echo "${script} does not exist in ${rc_directories}" >&2 +exit 1 Index: src/usr.sbin/service/service.8 diff -u /dev/null src/usr.sbin/service/service.8:1.4.2.2 --- /dev/null Tue Apr 21 05:22:59 2015 +++ src/usr.sbin/service/service.8 Tue Apr 21 05:22:58 2015 @@ -0,0 +1,173 @@ +.\" $NetBSD: service.8,v 1.4.2.2 2015/04/21 05:22:58 snj Exp $ +.\" +.\" Copyright (c) 2009 Douglas Barton +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.Dd March 20, 2015 +.Dt SERVICE 8 +.Os +.Sh NAME +.Nm service +.Nd run or list system services +.Sh SYNOPSIS +.Nm +.Op Fl elv +.Nm +.Op Fl ev +.Ar rc_script_name1 Op Ar rc_script_name2 Op Ar ... +.Nm +.Op Fl v +.Ar rc_script_name action +.Sh DESCRIPTION +The +.Nm +command is a simple interface to the services startup system. +.Pp +Its purpose is to list the services or invoke actions on them +as provided by the +.Ev rc.d +scripts. +When used to invoke +.Ev rc.d +scripts, +.Nm +will set the same environment that is used at boot time. +.Pp +The options are as follows: +.Bl -tag -width F1 +.It Fl e +List services that are enabled. +The list of scripts is compiled using +.Xr rcorder 8 +the same way as is done in +.Xr rc 8 ; +each script is first checked for an +.Qq rcvar +assignment and if present, +checked to see if it is enabled. +If one or more +.Ar rc_script_name +are specified, only those are checked. +The +.Ar rc_script_name +arguments are always specified without a path prefix. +.It Fl l +List all files in +.Pa /etc/rc.d +(the default of +.Ev rc_directories as defined in +.Xr rc.conf 5 ) . +A script will be listed unless it has the +.Qq nostart +keyword enabled. +.It Fl v +Report what +.Ev rc_directories +are defined or in which directory the +.Ev rc.d script +was found when an +.Ar action +is invoked. +.El +.Sh ENVIRONMENT +When used to invoke +.Ev rc.d scripts, the +.Nm +command sets +.Ev umask +to +.Fa 022 , +.Ev HOME +to +.Pa / , +and +.Ev PATH +to +.Pa /sbin:/bin:/usr/sbin:/usr/bin +which is how they are set in +.Pa /etc/rc +at boot time. +The +.Ar action +is typically one of +.Ar start , +.Ar restart , +.Ar status , +or any other argument supported by the +.Fa rc_script_name . +.Sh EXIT STATUS +.Ex -std +.Sh EXAMPLES +These are typical usages of the +.Nm +command: +.Bd -literal +# service sshd restart +Stopping sshd. +Starting sshd. +.Ed +.Bd -literal +$ service -v inetd status +inetd is located in /etc/rc.d +inetd is running as pid 1713. +.Ed +.Bd -literal +$ service -ve ccd motd hostapd my_pkg +rc_directories is /etc/rc.d /usr/pkg/etc/rc.d +/etc/rc.d/ccd +/usr/pkg/etc/rc.d/my_pkg +/etc/rc.d/motd +.Ed +.Pp +In the last example, +.Xr hostapd 8 +was apparently left disabled and the additional directory +.Pa /usr/pkg/etc/rc.d +was configured by redefining the variable +.Ev rc_directories +in +.Pa rc.conf ; +further, +.Sy my_pkg=yes +must have also been set. +.Sh SEE ALSO +.Xr rc.conf 5 , +.Xr rc 8 , +.Xr rcorder 8 +.Sh HISTORY +The +.Nm +utility first appeared in +.Nx 7.0 . +.Sh AUTHORS +.An -nosplit +Written for +.Fx +by +.An Douglas Barton Aq Mt do...@freebsd.org . +.Pp +Adapted and extended to +.Nx +by +.An Adrian Steinmann Aq Mt a...@marabu.ch .