From owner-freebsd-doc Tue Jul 18 9: 2:29 2000 Delivered-To: freebsd-doc@freebsd.org Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (Postfix) with ESMTP id 0484D37BF8B for ; Tue, 18 Jul 2000 09:02:18 -0700 (PDT) (envelope-from ben@scientia.demon.co.uk) Received: from strontium.scientia.demon.co.uk ([192.168.91.36] ident=exim) by scientia.demon.co.uk with esmtp (Exim 3.15 #1) id 13EZnw-000DCJ-00; Tue, 18 Jul 2000 17:01:08 +0100 Received: (from ben) by strontium.scientia.demon.co.uk (Exim 3.15 #1) id 13EZnw-000LFA-00; Tue, 18 Jul 2000 17:01:08 +0100 Date: Tue, 18 Jul 2000 17:01:08 +0100 From: Ben Smithurst To: Alexander Langer Cc: Sheldon Hearn , "Daniel C. Sobral" , freebsd-doc@FreeBSD.org Subject: Re: rc.d and rc.local Message-ID: <20000718170108.A4668@strontium.scientia.demon.co.uk> References: <20000718131849.L4668@strontium.scientia.demon.co.uk> <49493.963925685@axl.ops.uunet.co.za> <20000718150155.T4668@strontium.scientia.demon.co.uk> <20000718164301.A23930@cichlids.cichlids.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-md5; protocol="application/pgp-signature"; boundary="ELawpaRm0uGyL1wg" Content-Disposition: inline User-Agent: Mutt/1.2i In-Reply-To: <20000718164301.A23930@cichlids.cichlids.com> Sender: owner-freebsd-doc@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org --ELawpaRm0uGyL1wg Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Alexander Langer wrote: > Thus spake Ben Smithurst (ben@FreeBSD.org): >=20 >> I thought I'd leave it saying 5.0 until it does get merged, then I can >> change it to 4.2 or whatever. That seems better, since it wasn't in 4.0 >> and almost certainly won't be in 4.1. I guess the risk here is that >> I'll forget to update it. :-) >=20 > No, better change it right now and make Sheldon MFC right now :) Well, as I'm probably adding it to rc(8), I don't think I'll bother with a HISTORY section, as that page doesn't have one at the moment. Anyway, here's the latest patch for HEAD. I'll do the RELENG_4 version soon (hopefully in time for 4.1). One problem, which I'm not sure how to fix: At shutdown time, the directories are processed by =2ENm rc.shutdown . The following key points apply to the scripts within each directory: This only gives one space after "rc.shutdown." :-( Hardly a major problem, but how would I fix that? Index: rc.8 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /usr/cvs/src/share/man/man8/rc.8,v retrieving revision 1.10 diff -u -r1.10 rc.8 --- rc.8 2000/06/20 10:30:50 1.10 +++ rc.8 2000/07/18 15:48:57 @@ -42,6 +42,7 @@ .Nm rc .Nm rc.conf .Nm rc.conf.local +.Nm rc.d .Nm rc.serial .Nm rc.pccard .Nm rc.network @@ -67,6 +68,72 @@ .Nm rc.conf.local contains the local system configuration. See rc.conf(5) .Pp +The +.Nm rc.d +directories contain scripts which will be automatically +executed at boot time and shutdown time. +At boot time, +the specified directories are processed immediately after +.Nm rc.local +is executed. +(See below for details on how to specify directories to check.) +At shutdown time, +the directories are processed by +.Nm rc.shutdown . +The following key points apply to the scripts within each directory: +.Pp +.Bl -bullet -compact +.It +Scripts are only executed if their +.Xr basename 1 +matches the shell globbing pattern +.Pa *.sh , +and they are executable. +Any other files or directories present within the directory are silently +ignored. +.It +When a script is executed at boot time, it is passed the string +.Dq start +as its first and only argument. +At shutdown time, it is passed the string +.Dq stop +as its first and only argument. +All +.Nm rc.d +scripts expected to handle these arguments appropriately. +If no action needs to be taken at a given time +(either boot time or shutdown time) +the script should exit successfully and without producing an error message. +.It +The scripts within each directory are executed in lexicographical order. +If a specific order is required, +numbers may be used as a prefix to the existing filenames, +so for example +.Pa 100.foo +would be executed before +.Pa 200.bar ; +without the numeric prefixes the opposite would be true. +.El +.Pp +The output from each script is traditionally a space character, +followed by the name of the software package being started or shut down, +.Em without +a trailing newline character (see the +.Sx EXAMPLES +section). +.Pp +The system initialization scripts can execute scripts from multiple +.Nm rc.d +directories. +The default locations are +.Pa /usr/local/etc/rc.d +and +.Pa /usr/X11R6/etc/rc.d , +but these may be overriden with the +.Va local_startup +.Xr rc.conf 5 +variable. +.Pp .Nm Rc.shutdown is the command script which contains any necessary commands to be executed as the system is shut down. @@ -155,7 +222,37 @@ .Pp Following tradition, the startup files reside in .Pa /etc . +.Sh EXAMPLES +The following is a simple, hypothetical example of an +.Nm rc.d +script, +which would start a daemon at boot time, +and kill it at shutdown time. +.Bd -literal -offset indent +#!/bin/sh - +# +# initialization/shutdown script for foobar package + +case "$1" in +start) + /usr/local/sbin/foo -d && echo -n ' foo' + ;; +stop) + kill `cat /var/run/foo.pid` && echo -n ' foo' + ;; +*) + echo "unknown option: $1 - should be 'start' or 'stop'" >&2 + ;; +esac +.Ed +.Pp +As all processes are killed by +.Xr init 8 +at shutdown, the explicit +.Xr kill 1 +is unnecessary, but is often included. .Sh SEE ALSO +.Xr kill 1 , .Xr rc.conf 5 , .Xr init 8 , .Xr reboot 8 , --=20 Ben Smithurst / ben@FreeBSD.org / PGP: 0x99392F7D FreeBSD Documentation Project / --ELawpaRm0uGyL1wg Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: PGPfreeware 5.0i for non-commercial use MessageID: ZJ3Q1MLMzJXr8eFZRoNDBiqvlgYObqNP iQCVAwUBOXR/QisPVtiZOS99AQETEQP+LJZ//0MzzDehJpSjwfW5EDJwG9Rzdq9A IdSVMfPGV55m0m06mAI+ei+pWEuG2xkhbSGnU7rvGTLjqwznu1ByUH4iPskE1D7i uUnCJFo1OJ8rteb7NwuFszAJ+MMr4e1lq1RbEpXkmZkRNA+AqU7FG+i2/IK53qRU aiOq2WNngDQ= =pqCZ -----END PGP SIGNATURE----- --ELawpaRm0uGyL1wg-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-doc" in the body of the message