Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Import a substantially modified service(8) command from Free...



details:   https://anonhg.NetBSD.org/src/rev/6bcc4e984963
branches:  trunk
changeset: 806966:6bcc4e984963
user:      ast <ast%NetBSD.org@localhost>
date:      Sun Mar 22 09:57:42 2015 +0000

description:
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.

diffstat:

 distrib/sets/lists/base/mi |    3 +-
 distrib/sets/lists/man/mi  |    5 +-
 usr.sbin/Makefile          |    5 +-
 usr.sbin/service/Makefile  |    9 ++
 usr.sbin/service/service   |  118 ++++++++++++++++++++++++++++++
 usr.sbin/service/service.8 |  173 +++++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 309 insertions(+), 4 deletions(-)

diffs (truncated from 381 to 300 lines):

diff -r 04d542a0e593 -r 6bcc4e984963 distrib/sets/lists/base/mi
--- a/distrib/sets/lists/base/mi        Sun Mar 22 09:45:50 2015 +0000
+++ b/distrib/sets/lists/base/mi        Sun Mar 22 09:57:42 2015 +0000
@@ -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
diff -r 04d542a0e593 -r 6bcc4e984963 distrib/sets/lists/man/mi
--- a/distrib/sets/lists/man/mi Sun Mar 22 09:45:50 2015 +0000
+++ b/distrib/sets/lists/man/mi Sun Mar 22 09:57:42 2015 +0000
@@ -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
diff -r 04d542a0e593 -r 6bcc4e984963 usr.sbin/Makefile
--- a/usr.sbin/Makefile Sun Mar 22 09:45:50 2015 +0000
+++ b/usr.sbin/Makefile Sun Mar 22 09:57:42 2015 +0000
@@ -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 @@
        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 \
diff -r 04d542a0e593 -r 6bcc4e984963 usr.sbin/service/Makefile
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/service/Makefile Sun Mar 22 09:57:42 2015 +0000
@@ -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>
diff -r 04d542a0e593 -r 6bcc4e984963 usr.sbin/service/service
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/service/service  Sun Mar 22 09:57:42 2015 +0000
@@ -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
diff -r 04d542a0e593 -r 6bcc4e984963 usr.sbin/service/service.8
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/usr.sbin/service/service.8        Sun Mar 22 09:57:42 2015 +0000
@@ -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



Home | Main Index | Thread Index | Old Index