Module Name:    src
Committed By:   ast
Date:           Sun Mar 22 09:57:42 UTC 2015

Modified Files:
        src/distrib/sets/lists/base: mi
        src/distrib/sets/lists/man: mi
        src/usr.sbin: Makefile
Added Files:
        src/usr.sbin/service: Makefile service service.8

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.1097 -r1.1098 src/distrib/sets/lists/base/mi
cvs rdiff -u -r1.1497 -r1.1498 src/distrib/sets/lists/man/mi
cvs rdiff -u -r1.269 -r1.270 src/usr.sbin/Makefile
cvs rdiff -u -r0 -r1.1 src/usr.sbin/service/Makefile \
    src/usr.sbin/service/service 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.1097 src/distrib/sets/lists/base/mi:1.1098
--- src/distrib/sets/lists/base/mi:1.1097	Mon Mar  2 21:55:44 2015
+++ src/distrib/sets/lists/base/mi	Sun Mar 22 09:57:42 2015
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1097 2015/03/02 21:55:44 christos Exp $
+# $NetBSD: mi,v 1.1098 2015/03/22 09:57:42 ast Exp $
 #
 # Note:	Don't delete entries from here - mark them as "obsolete" instead,
 #	unless otherwise stated below.
@@ -1687,6 +1687,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.1497 src/distrib/sets/lists/man/mi:1.1498
--- src/distrib/sets/lists/man/mi:1.1497	Sat Mar 21 19:10:43 2015
+++ src/distrib/sets/lists/man/mi	Sun Mar 22 09:57:42 2015
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.1497 2015/03/21 19:10:43 jmcneill Exp $
+# $NetBSD: mi,v 1.1498 2015/03/22 09:57:42 ast Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 #
@@ -2947,6 +2947,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
@@ -5747,6 +5748,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
@@ -8835,6 +8837,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/usr.sbin/Makefile
diff -u src/usr.sbin/Makefile:1.269 src/usr.sbin/Makefile:1.270
--- src/usr.sbin/Makefile:1.269	Sat Jul 26 19:32:37 2014
+++ src/usr.sbin/Makefile	Sun Mar 22 09:57:42 2015
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.269 2014/07/26 19:32:37 dholland Exp $
+#	$NetBSD: Makefile,v 1.270 2015/03/22 09:57:42 ast 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
--- /dev/null	Sun Mar 22 09:57:42 2015
+++ src/usr.sbin/service/Makefile	Sun Mar 22 09:57:42 2015
@@ -0,0 +1,9 @@
+# $NetBSD: Makefile,v 1.1 2015/03/22 09:57:42 ast 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.1
--- /dev/null	Sun Mar 22 09:57:42 2015
+++ src/usr.sbin/service/service	Sun Mar 22 09:57:42 2015
@@ -0,0 +1,118 @@
+#!/bin/sh
+#    $NetBSD: service,v 1.1 2015/03/22 09:57:42 ast 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
+
+. /etc/rc.subr
+load_rc_config 'XXX'
+
+usage ()
+{
+    local me=${0##*/}
+    echo "Usage: ${me} [-vel]"
+    echo "Usage: ${me} [-ve] rc_script_name [rc_script_name2 [...]]"
+    echo "Usage: ${me} [-vf] rc_script_name action"
+    echo "       -l: List all scripts in rcorder"
+    echo "       -e: List enabled scripts; check if given scripts are enabled"
+    echo "       -f: Set rc_fast=yes when running rc_script_name action"
+    echo "       -v: Verbose (mention in which directory script is found)"
+    echo "rc_directories is currently set to ${rc_directories}"
+    return 0
+}
+
+rc_files()
+{
+    local dir
+    for dir in ${rc_directories}; do
+        [ -d ${dir} ] && ls -P1 ${dir} 2>/dev/null
+    done | xargs rcorder -s nostart ${rc_rcorder_flags} 2>/dev/null
+    return 0
+}
+
+while getopts elvf o; do
+    case $o in
+        l) LIST=1 ;;
+        v) VERBOSE=1 ;;
+        e) ENABLED=1 ;;
+        f) rc_fast=yes ;;
+        *) usage ; exit 1 ;;
+    esac
+done
+shift $(( ${OPTIND} - 1 ))
+
+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 )
+            checkyesno ${rcvar} 2>/dev/null && echo ${file}
+        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
+    exit 1
+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.1
--- /dev/null	Sun Mar 22 09:57:42 2015
+++ src/usr.sbin/service/service.8	Sun Mar 22 09:57:42 2015
@@ -0,0 +1,173 @@
+.\"	$NetBSD: service.8,v 1.1 2015/03/22 09:57:42 ast 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 vel
+.Nm
+.Op Fl ve
+.Ar rc_script_name Op Ar rc_script_name2 Op Ar ...
+.Nm
+.Op Fl vf
+.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 following options are supported:
+.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.
+.It Fl f
+Set
+.Sy rc_fast=yes
+to speed up the
+.Ev rc.d script; that is, run it as it is run during
+.Sq autoboot .
+.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:
+.Pp
+.Dl "# service sshd restart"
+.Dl "Stopping sshd."
+.Dl "Starting sshd."
+.Pp
+.Dl "$ service -v inetd status"
+.Dl "inetd is located in /etc/rc.d"
+.Dl "inetd is running as pid 1713."
+.Pp
+.Dl "$ service -vfe ccd motd hostapd my_pkg"
+.Dl "rc_directories is /etc/rc.d /usr/pkg/etc/rc.d"
+.Dl "/etc/rc.d/ccd"
+.Dl "/usr/pkg/etc/rc.d/my_pkg"
+.Dl "/etc/rc.d/motd"
+.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
+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 .

Reply via email to