Commit Graph

88 Commits

Author SHA1 Message Date
Doug Barton
b004b4e45f Now that the last of the *.sh scripts are gone from the base,
emit a warning if come across one.
2009-05-30 21:41:54 +00:00
Andrew Thompson
02c7950097 Show which rc script is running since the default ^T just shows 'sh' as the
process.
2008-10-27 01:05:09 +00:00
Mike Makonnen
d7c5bf81cb Move the diagnostic output when the rc.subr(8) glue automatically starts a
service behind $rc_quiet. Instead, output a warning if the pre-command
routine or the command itself failed. Arguably, it's more useful to know when
a command failed to start than it is to have an endless list of
"Starting ...." lines[1].

[1] - This change actually helped me to discover a bug in rc.d/{lockd,statd}
      (fixed in r179941) that used to fail silently before.
2008-06-23 05:09:09 +00:00
Mike Makonnen
7d28174b91 Make quota knob conform to other rc(8) knobs. Keep older knob for
compatibility.

Requested by: Volker <volker@vwsoft.com>
2008-06-19 07:06:11 +00:00
Mike Makonnen
8717ddefb6 Move the check for enabled knobs further down in run_rc_command() so
that bogus commands cause usage information to be printed instead of
diagnostics about enabling the knob.
2008-06-19 06:11:34 +00:00
Maxim Konovalov
97752dfdc7 o Convert whitespaces to tabs. 2008-05-05 15:52:54 +00:00
Maxim Konovalov
2b30cf49b5 o Terminate "case" with "esac" not "fi".
Reported by:	Randy Bush
2008-05-05 15:50:20 +00:00
Mike Makonnen
432d4f0bce Fix improper use of checkyesno routine.
Noticed by: oliver
MFC after: 1 week
2008-05-05 07:43:48 +00:00
Mike Makonnen
a850398f3b Re-implement: do not silently fail when a command is not carried
out because the rc.conf(5) variable was not enabled. Display a
message that the command wasn't run and offer suggestions on
what the user can do.

Implement a quiet prefix, which will disable some diagnostics. The
fast prefix also implies quiet. During boot we use either fast or
quiet. For shutdown we already use 'faststop'. So, this informational
message should only appear during interactive use.

An additional benefit of having a quiet prefix is that we can start
putting some of our diagnostic messages behind this knob and start
"de-cluttering" the console during boot and shutdown.
2008-01-26 11:22:12 +00:00
Mike Makonnen
581487018d Backout previous commit. It's going to clutter the console
during boot and shutdown. I think I'll hide it behind autoboot or
maybe take brooks@ suggestion and implement a different command
prefix for booting/shutdown purposes, but in any case it needs more
thought and attention.

Noticed by: ceri
Pointyhat to: mtm
2008-01-25 16:44:34 +00:00
Mike Makonnen
0908cccf90 If the rc.conf(5) variable for a script is not enabled do not fail
silently. Display a message that the command wasn't run and make
possible suggestions for what to do.

PR:	   conf/118770
MFC after: 1 week
2008-01-25 15:06:26 +00:00
Doug Barton
416c130ca1 Remove pre-rc.d compatibility shims that were added before the 5.0 branch
for pre-5.0 variable names.

Remove two dhcp compatibility variables added after the 5.1-RELEASE.

Remove the now-unused support for these shims.

Approved by:	re (kensmith)
2007-10-09 07:20:44 +00:00
Yaroslav Tykhiy
039e8df3cf Be robust to a bogus script specification or contents
when figuring out what the real interpreter is for an
interpreted command.  That is, check whether we can read
the script file in the first place and, if so, make sure
we got a valid shebang line from it.
2007-06-04 11:39:35 +00:00
Mike Makonnen
3d03791bb4 o Implement the stop_boot subroutine [1]. This subroutine can be used by
scripts in rc.d to stop rc(8) from booting into multi-user mode when
  a critical or severe error condition is encountered.

o Modify scripts in etc/rc.d that already implemented this functionality
  independently.

o Document it.

[1] - This subroutine was implemented in FreeBSD in rc.d/fsck. I moved it
      to rc.subr(8). Our version differs slightly in that it takes an
      optional argument to stop the boot even if "autoboot" is not set.

Obtained from: NetBSD
MFC after: 2 weeks
2007-05-18 12:04:41 +00:00
Yaroslav Tykhiy
b5af060613 Prepend ${_chroot} to a pathname in a consistent and robust way:
insert a slash between ${_chroot} and the pathname if and only if
${_chroot} is set to a non-empty string.  Now the pathname is very
likely to be absolute, but we shouldn't take that for granted.
2007-03-10 13:37:44 +00:00
Yaroslav Tykhiy
c7be7e20f6 Allow for /usr/bin/env when parsing the shebang line from an
interpreted $command.  Some "portable" sofware packages use such a
line to skip the task of figuring out the absolute pathname of the
interpreter at install time, e.g.:

	#!/usr/bin/env python

It is insecure, but a popular book on Python seems to have advised
it to a wide audience.  Hence a number of such scripts in the ports,
mostly written in Python.

PR:		bin/100287
MFC after:	1 week
2006-12-31 11:07:29 +00:00
Yaroslav Tykhiy
c89572720c MFp4:
Implement the checks for required_* objects as two functions, one
to be run before precmd and the other after it.  They get the current
rc command as an argument so they can choose what requirement tests
to perform.  As of now, only "start" needs such tests.

Implement a new requirement variable, required_modules.  It can
list kernel modules that need to be loaded after start_precmd
indicated success.  Each name in the list can be just "file", or
"file:module", or "file~regex".  This will allow us to remove a lot
of duplicated code from rc.d scripts.

Perform the checks not only for the default start method, but for
any method.  This allows for more flexibility and fixes a few rc.d
scripts (namely newsyslog, pf, sendmail) that rely on a required_*
variable while providing a non-default start method.

To be able to call the new check_required* functions naturally,
remove lots of crufty duplicated code pieces from run_rc_command
and replace each of them by a call to the helper function providing
a single corrected instance of the respective code snippet.  Now
run_rc_command isn't as scary as it used to be, and it even appears
to have quite a nice logic that was obscured by the old crufty code.

In the default handler for restart, run start from a subshell to
protect global varibles, e.g., _postcmd, from modification by the
start handler.  This enables using restart_postcmd. [x]

PR:		conf/98734 [x]
Submitted by:	Rick van der Zwet <rick@wzoeterwoude.net> [x]
Reviewed by:	freebsd-rc (silence for an older version)
MFC after:	1 month
2006-12-27 13:15:33 +00:00
Florent Thoumie
80301cdc8e Teach find_processes() to use ${name}_chroot.
Obtained from:	NetBSD
X-MFC after:	6.2-RELEASE
2006-11-26 22:02:09 +00:00
Florent Thoumie
e1ad9834a0 Remove leading dollar sign in rcvar command output.
There's no dollar use in variable assignment in sh.
Assuming this is can be expected behavior for some
people, this change won't be MFC'ed to RELENG_6.

Discussed with:	yar on -rc
2006-11-26 19:03:19 +00:00
Yaroslav Tykhiy
4af42c2cb1 debug() shouldn't misidentify itself to logger(1).
Noticed by:	David Thompson <dat1965 yahoo com>
2006-10-02 08:20:37 +00:00
Florent Thoumie
3081bf98bf Backout this commit since it breaks startup and some scripts in
certain conditions. I haven't been able to find a better solution yet:

    - Set a two read-only variables (${prefix} and ${etcdir}). This is
    especially useful when using /etc/rc.d scripts with third-party
    software installed from ports.
    - Fix rc.d/sshd to work with openssh from ports using ${etcdir}
    instead of hardcoded /etc.
    - Reflect prefix/etcdir changes in rc.subr.8.

        src/etc/rc.d/sshd: rev 1.9 -> 1.10
        src/etc/rc.subr: rev 1.51 -> 1.52
        src/share/man/man8/rc.subr.8: rev 1.11 -> 1.12

Approved by:	cperciva (mentor)
2006-08-22 11:17:29 +00:00
Yaroslav Tykhiy
7293852835 Eliminate header line(s) from ps(1) output instead of skipping over them. 2006-08-18 13:07:38 +00:00
Yaroslav Tykhiy
a9a6b38f96 The ps(1) command is unfriendly to scripts by default because
it limits the width of its output to the value of $COLUMNS, or
what TIOCGWINSZ reports, or 79 columns.  We should specify -ww
to ps(1) so that it removes the limit and prints lines in full.
Otherwise very long command pathnames could be mishandled, e.g.,
by _find_processes().

MFC after:	1 week
2006-08-18 12:10:18 +00:00
Yaroslav Tykhiy
ae44d27bfd Allow for setting negative priority (niceness) when $foo_user is non-root.
The order in _doit must be "nice su", not "su nice", for that.
In addition, don't ignore the exit status from "cd $foo_chdir".

Reviewed by:	freebsd-rc (silence)
MFC after:	1 week
2006-08-17 08:04:20 +00:00
Yaroslav Tykhiy
d1b4fdece5 Back out rev. 1.63. It was a poor idea because
test(1) is built in sh(1) and it always evaluates
both sides of -a or -o, unlike && or || in sh(1).

Requested by:	dougb
2006-07-26 08:03:24 +00:00
Yaroslav Tykhiy
58138bc77d Avoid extra runs of test(1) by using its built-in logical operations. 2006-07-25 17:20:22 +00:00
Yaroslav Tykhiy
ed1f20ba5c Sync comments around _doit with the code. 2006-07-25 17:16:48 +00:00
Yaroslav Tykhiy
417ae47d51 We notify of failures with err or warn.
Messages should end in full stop unless
that can lead to confusion.
2006-07-25 17:14:38 +00:00
Yaroslav Tykhiy
e59cb1e6d4 Add diagnostics to load_kld(). 2006-07-25 17:10:35 +00:00
Yaroslav Tykhiy
1679c7f4f4 Quite a number of rc.d scripts try to load kernel modules. Many
of them do that conditionally depending on kldstat.  The code is
duplicated all over, but bugs can be uniqie.

To make the things more consistent, introduce a new rc.subr function,
load_kld, which takes care of loading a kernel module conditionally.

(Found this lying for a while in my p4 branch for various hacks.)
2006-06-21 09:42:55 +00:00
Florent Thoumie
0e5c8f9a0f Remove the require_kld function I just committed and replace with a nicer solution.
Reported by:	pjd
Approved by:	cperciva
2006-05-18 16:04:56 +00:00
Florent Thoumie
01b19d7852 Add two new scripts (mdconfig/mdconfig2) to replace old ramdisk{,-own}
scripts. These scripts handle vnode backed md(4) devices.

Old ramdisk{,-own} scripts will stay a bit in CVS to allow some time for
migration since variable names have changed (ramdisk_* -> mdconfig_*).

Two new variables have been introduced to be able to populate the md(4)
device once it has been mounted (mdconfig_*_files and mdconfig_*_cmd).

Use should be as easy as:

mdconfig_md0="-t malloc -s 10m"
mdconfig_md1="-t vnode -f /var/foo.img"

See rc.conf(5) for more information and description of the additional
variables.

Approved by:	cperciva
2006-05-18 15:29:27 +00:00
Florent Thoumie
d657eeb6bf - Move _rc_subr_loaded=: at the end of the file, to be consistent with NetBSD.
- Sync with latest version from NetBSD.

'In order to handle some perl scripts running as daemons, add a
pattern which also matches "`basename $interpreter`: $command" in the
ps listing.'

Approved by:	cperciva (mentor)
Obtained from:	NetBSD
MFC after:	1 week
2006-04-18 15:16:55 +00:00
Florent Thoumie
7b05b2c434 Use ps true power instead of tr/tail which aren't available early enough.
PR:		conf/95654
Submitted by:	Rong-En Fan <rafan@infor.org>
Noticed/Fix by:	many people on freebsd-current@
Approved by:	cperciva (mentor)
2006-04-13 08:30:43 +00:00
Florent Thoumie
ef04a10fe9 - If no pidfile has been created at startup, only stop processes
with current jid.

PR:		conf/93287
Submitted by:	anders
Approved by:	cperciva (mentor)
MFC after:	1 month
2006-04-11 09:20:47 +00:00
Florent Thoumie
56f964f063 - Oops, add a missing "then".
Approved by:	cperciva (mentor, implicit)
2006-04-11 09:14:51 +00:00
Florent Thoumie
f0a4a7a722 - Set a two read-only variables (${prefix} and ${etcdir}). This is
especially useful when using /etc/rc.d scripts with third-party
software installed from ports.
- Fix rc.d/sshd to work with openssh from ports using ${etcdir}
instead of hardcoded /etc.

Reviewed by:	brooks
Approved by:	cperciva (mentor)
MFC after:	1 week
2006-04-11 08:55:27 +00:00
Florent Thoumie
46587ab898 - Sync rc.subr with NetBSD.
- Merge some documentation bits.

Reviewed by:	brooks, simon (doc)
Approved by:	cperciva (mentor)
Obtained from:	NetBSD
MFC after:	3 days
2006-04-04 10:52:15 +00:00
Florent Thoumie
37b7942cbf Harmless typo (s/overide/override/).
Approved by:	cperciva
MFC after:	3 days
2006-03-23 16:48:32 +00:00
Ceri Davies
977cb19587 Update a comment to match functionality changed in r1.39 (allow square
brackets in process names).

MFC after:	2 days
2006-02-15 14:37:35 +00:00
Florent Thoumie
54a6effc95 Don't include geli devices in list when noauto is specified in the options field.
Approved by:	pjd
MFC after:	3 days
2006-02-12 12:57:07 +00:00
Doug Barton
0868a57db0 Silence a warning about empty directories in all the places it might
occur.

Reminded by: yar
2005-12-10 20:19:08 +00:00
Yaroslav Tykhiy
0ce3dc049a Since rc.subr is a library of functions, it should not use exit
every now and then.  It is up to the caller to choose a proper
action upon an error condition.  Therefore, use return, not exit,
except for some special cases.

Consistently return 1 to indicate an error.

Submitted by:	sem (initially)
Reviewed by:	freebsd-rc (silence)
MFC after:	2 weeks
2005-12-06 05:27:11 +00:00
Doug Barton
b37ccb58ef Change how *.sh scripts are handled. If the script is in /etc/rc.d,
source it into the shell. If not, handle it in a subshell the same
way that "real" rc.d-style scripts are handled. This will dramatically
ease the "process local scripts in the base rcorder" transition.

Add *.bak to the list of files in */rc.d that we ignore.
2005-12-05 07:04:15 +00:00
Doug Barton
0f3ce2b32c Introduce startup scripts from the local_startup directories to
the base rcorder. This is accomplished by running rcorder twice,
first to get all the disks mounted (through mountcritremote),
then again to include the local_startup directories.

This dramatically changes the behavior of rc.d/localpkg, as
all "local" scripts that have the new rc.d semantics are now
run in the base rcorder, so only scripts that have not been
converted yet will run in rc.d/localpkg.

Make a similar change in rc.shutdown, and add some functions in
rc.subr to support these changes.

Bump __FreeBSD_version to reflect this change.
2005-12-02 20:06:07 +00:00
Yaroslav Tykhiy
fd9791c1ea Avoid invoking the current script again when we need
to issue sub-commands, e.g., restart = stop + start.
By calling run_rc_command instead, we provide rc.d
scripts with full control over their configuration
variables.

For an example problem the former approach caused, see
http://lists.freebsd.org/pipermail/freebsd-rc/2005-October/000311.html

Reviewed by:	freebsd-rc
Tested by:	Dirk Engling erdgeist <at> erdgeist.org
MFC after:	2 weeks
2005-11-16 10:45:19 +00:00
Yaroslav Tykhiy
6fa3ee6c30 Override $command with $foo_program only if $command
has been set in the first place.  This should reduce
unwanted side-effects in rc.d scripts that don't mean
to use $command and rc.subr(8) methods associated with
it at all.

Discussed with:	brooks
Reviewed by:	-rc (silence)
2005-10-26 04:32:31 +00:00
Yaroslav Tykhiy
5a3c72ce8f Document that `reload' is not provided by default
yet it can be enabled when applicable.
2005-10-26 04:12:34 +00:00
Maxim Konovalov
4b401243a4 o Grammar.
Submitted by:	Ulrich Spoerlein
MFC after:	1 week
2005-10-24 08:53:21 +00:00
John Baldwin
2e169ae820 Allow the process name to be in square brackets ([]) in _find_processes().
PR:		conf/82430
Submitted by:	Pavel Volkov pol at iib dot ru
MFC after:	1 week
2005-10-17 19:01:53 +00:00