Commit Graph

55 Commits

Author SHA1 Message Date
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
Yaroslav Tykhiy
85a65c57e3 Fix the usage of rc_usage. The rc_usage function takes
a list of possible keywords, not all them in a single argument.
This also fixes the issue of extra delimiter characters appearing
on the help line from rc.d scripts not setting $extra_commands.
2005-10-01 20:58:03 +00:00
Yaroslav Tykhiy
4986c6d8e2 Stop hard-coding an -M flag to mdmfs(8) in /etc/rc.subr.
Now this flag can be set, or not set, for memory-backed
file systems on individual basis, as illustrated by the
rc.conf(5) variables tmpmfs_flags and varmfs_flags.  The
flag is set for those FS'en by default, in /etc/defaults/rc.conf,
in order to stay compatible with the old rc.subr behaviour.

Submitted by:	marck
MFC after:	3 days
2005-08-24 16:25:47 +00:00
Pawel Jakub Dawidek
b12cfed25c Add scripts for GELI device configuration on boot.
rc.d/geli - configures encryption (ask for passphrases, etc.);
rc.d/geli2 - is called after file systems are mounted and mark devices for
             detach on last close.

Sponsored by:	Wheel Sp. z o.o.
		http://www.wheel.pl
MFC after:	3 days
2005-08-14 18:02:22 +00:00
Pawel Jakub Dawidek
b3d1f1fce9 Move 'local_tr' function to rc.subr and change its name to 'ltr'.
MFC after:	3 days
2005-08-14 17:28:15 +00:00
Jens Schweikhardt
e67132b9ed Style: mostly tabs vs blanks, and semicolon placement. 2005-05-22 16:22:23 +00:00
Giorgos Keramidas
2853698951 Cosmetic typo in check_pidfile()
PR:		bin/75946
Submitted by:	zero@gddn.org (Finn)
2005-01-09 23:46:37 +00:00
Giorgos Keramidas
8cfaa2f1f1 Add two new rc.conf options: tmpmfs_flags and varmfs_flags.
These can be used to pass extra options to the mdmfs(8) utility,
to customize the finer details of the md file system creation
(i.e. to turn on/off softupdates, to specify a default owner for md
filesystem, etc).

Use these two new flags to mount tmpmfs and varmfs without
softupdates, since it doesn't make much sense to use SU on
malloc-backed file systems.

Reviewed by:	mtm
Inspired by:	J. D. Bronson, jbronson at wixb dot com
2004-11-09 10:03:17 +00:00
Mike Makonnen
83f00c3c07 Finish cleanup of rc.d/netif. It's now possible to start/stop more
than one interface from the command line:
	# /etc/rc.d/netif start bfe0 xl0
It's also possible to restart an interface(s):
	# /etc/rc.d/netif restart bfe0

This required some changes to rc.subr(8) so that if the start/stop commands
are overidden the rest of the command line (after the start/stop/etc... cmd)
is passed through to the subroutines.
2004-07-30 17:19:35 +00:00
Colin Percival
f5e16e6131 Wrap rc.subr inside
if [ -z "${_rc_subr_loaded}" ]; then
_rc_subr_loaded="YES"
...
fi

in order to avoid re-interpreting rc.subr every time an rc.d
script is run.  In my tests, this speeds up rc time by about
8-10%.
2004-07-04 07:21:18 +00:00
Mike Makonnen
3621fa11d7 Make the stop command respect the 'fast' prefix.
Most notably, this cleans up messages when shutting down from
single user. In such a case there are usually no daemons running,
but their pid files are still in /var/run. This causes rc.d to
output diagnostics about daemons with pidfiles, but that are
not running.
2004-06-26 09:27:30 +00:00
Mike Makonnen
0247998d45 Fix typo.
Submitted by: kuriyama
2004-06-24 16:57:49 +00:00
Mike Makonnen
30e2462c71 Restore pre-rcNG behaviour:
SIGINT (Ctrl-c) kills the current script
SIGQUIT (Ctrl-\) kills /etc/rc (dropping you into single-user)

Prodded by:	harti
2004-06-06 18:06:09 +00:00
Brooks Davis
3e091039ee Overhaul the /etc/rc.d/diskless script by splitting it out into
hostname, resolve, tmp, and var scripts.  The latter three are new and
were repo copied.  These scripts no longer depend on being booted with
and NFS root instead attempt to automaticly create mfs /tmp and /var
volumes if the they are not writable.  This behavior can be overridden
in /etc/rc.conf.

Reviewed by:    luigi, pjd
2004-03-23 23:22:35 +00:00
Mike Makonnen
52c9f8bc70 Some (most?) processes don't cleanup their pid files when
they exit. Sometimes they simply can't (core-dump, for example).
So, when searching for a running program send standard error
output from ps(1) to never-never land.

	# This should quite those
	# ps: kvm_getprocs: No such user
	# errors. Since ports use a duplicate rc.subr(8) you might
	# still see this error from ports startup scripts.
2004-03-03 15:28:44 +00:00
Mike Makonnen
c608fcc5fa NetBSD rev. 1.61
Implement ``one'' prefix to allow a "one shot" operation as if
  ${rcvar}=yes yet all the other prerequisite tests are still performed.
  The existing ``force'' prefix is a sledgehammer that ignores all the
  prerequisite checks and always returns a zero exit status; this is a
  more gentle approach to the problem of "manipulate this disabled
  service without editing rc.conf(5)".

Obtained From:	NetBSD

	# We have a work-around in our version of rc.subr that
	# makes force* return a non-zero exit status if the
	# command/service could not be acted upon. The work-around
	# is no longer necessary and should be removed.
2004-02-27 09:58:50 +00:00
Mike Makonnen
27ab4cabc4 o NetBSD rev. 1.60
Add "*,v" to the list of scratch files to skip.
  Suggested by Johnny Lam / Alistair Crooks

o Update NetBSD rcsid

Obtained From:	NetBSD
2004-02-26 12:43:43 +00:00
Mike Makonnen
30cb2617ac NetBSD rev. 1.57
run_rc_command(): when checking if ${command} exists before executing it,
  be sure to check under ${name_chroot} (if set).
  Fix from Ed Ravin in [bin/18523]

Obtained From:	NetBSD
2004-02-26 12:35:58 +00:00
Mike Makonnen
42477cdb78 NetBSD rev. 1.56
Use more concise shell syntax:
  1. for i in $* -> for i
  2. foo=$* -> foo="$@"

Obtained From:	NetBSD
2004-02-26 12:30:38 +00:00
Mike Makonnen
4585b18227 NetBSD rev. 1.53, 1.54 and 1.55:
Change how internal boolean variables are used to:
	if ! ${_somevar:-false}; then
		_somevar=true
	fi
  (Consisent, slightly quicker, and slightly cleaner)

Obtained from:	NetBSD
2004-02-26 12:19:48 +00:00
Mike Makonnen
a039fbbf8c Since id(1) is in /usr, it may not be available until after filesystem
mounting.

Reminded by: bde
2004-01-22 08:46:03 +00:00
Colin Percival
b991815bc0 After setting a ruleset on a new devfs mount, apply it.
Approved by: phk, rwatson (mentor)
PR: bin/61047
2004-01-21 16:36:17 +00:00
Mike Makonnen
ed0bd3657c o Rename devfs_link() to make_symlink() and turn it into a generic
symlinking routine.
o Modify rc.d/jail to create its own symlink relative to the jail's
  filesystem
2003-12-09 08:51:11 +00:00
Mike Makonnen
4541e3ecc6 o Reduce rc(8) startup clutter by turning the informational messages
off by default.
o Apparently the routine displaying the informational messages wasn't
  checking its knob in rc.conf, so fix that as well.

Requested by:	obrien
2003-08-20 06:50:34 +00:00
Mike Makonnen
130112f793 Add a general mechanism for creating and applying
devfs(8) rules in rc(8). It is most useful for applying
rules to devfs(5) mount points in /dev or inside jails.
The following line of script is sufficient to
mount a relatively useful+secure devfs(5) in a jail:

	devfs_mount_jail /some/jail/dev

Some new shell routines available to scripts that source
rc.subr(5):
	o devfs_link		- Makes it a little easier to create symlinks
	o devfs_init_rulesets	- Create devfs(8) rulesets from devfs.rules
	o devfs_set_ruleset	- Set a ruleset to a devfs(5) mount
	o devfs_apply_ruleset	- Apply a ruleset to a devfs(5) mount
	o devfs_domount		- Mount devfs(5) and apply some ruleset
	o devfs_mount_jail	- Mount devfs(5) and apply a ruleset
				  appropriate to jails.

Additional rulesets can be specified in /etc/devfs.rules.
If the devfs_system_ruleset variable is defined in rc.conf
and it contains the name of a ruleset defined in /etc/defaults/devfs.rules
or user supplied rulesets in /etc/devfs.rules then that ruleset will
be applied to /dev at startup by the /etc/rc.d/devfs script. It can
also be applied post-startup:

	/etc/rc.d/devfs start

This is a more flexible mechanism than the previous method of using
/etc/devfs.conf. However, that method is still available.

Note: since devfs(8) doesn't provide any way for creating symlinks
as part of a ruleset, anyone wishing to create symlinks in a devfs(5)
as part of the bootup sequence will still have to rely on /etc/devfs.conf.
2003-08-20 06:15:18 +00:00
Mike Makonnen
22b4909430 Missing quotes around a variable. In this case we are only
evaluating the $_precmd command as a string. We're not actually
trying to evaluate the contents of the command.

Reported by:	Glenn Johnson <gjohnson@srrc.ars.usda.gov>
2003-07-24 18:17:21 +00:00
Mike Makonnen
7d25d82513 Previously, a "forced" command always exited successfully (with the
exception of the default 'status' command) regardless of whether the
executed command was actually successfull or not. Forced scripts should
always correctly reflect the outcome of the command.

NOTE: exit values are treated as booleans. We don't care what
      the actual exit value was, only whether it was successfull or not.
2003-06-09 17:31:06 +00:00
Mike Makonnen
d679c13014 The dhcp_program and dhcp_flags variables have to be renamed to
take advantage of the rc.subr(8) glue. They are renamed dhclient_program
and dhclient_flags.
	o Rename them in rc.conf(5)
	o Rename them in /etc/defaults/rc.conf
	o Add the deprecated variables to /etc/rc.subr
	o Isolate the use  of the 'command' variable to the
	  NetBSD specific parts in /etc/rc.d/dhclient.
	o Now that dhcp_flags has also been renamed it will
	  be applied properly by rc.subr(8) glue code.

Reported by:	John Nielsen <john@jnielsen.net>
2003-06-07 10:31:17 +00:00
Mike Makonnen
3d9556ddc0 This particular debugging statement is very verbose, making the rest
of the debug output hard to follow. Comment it out. It's commented out
in NetBSD's version as well.

Approved by:	markm (mentor)(implicit)
2003-04-30 03:03:47 +00:00
Mike Makonnen
03891d9007 Write out the debug messages (from the previous commit) only if
the evaluated command exists.

Approved by: markm (mentor)(implicit)
2003-01-20 19:30:15 +00:00
Mike Makonnen
276ae160e6 Make the debug messages, for when a script rolls its own start routine,
more usefull. Currently it just says 'xxx_cmd'; whereas with this
change it will name the routine that's being run.

Approved by: markm (mentor)
2003-01-18 05:25:59 +00:00
Gordon Tetlow
59de601c12 By popular demand, make the debug log to syslog.
Remove an extraneous return too.
2002-11-09 17:34:21 +00:00
Gordon Tetlow
fd750dbd4c Diff reduction to NetBSD:
Fix a minor grammer nit.
Get rid of _echo that uses logger and just call logger in the 3 routines
that need it.
Add a comment referencing rc.conf(5) in the case of an incorrectly set
variable.

This pulls rc.subr up to 1.51 of rc.subr. I skipped 1.49 (systrace support)
since I don't have systrace.

Obtained from:	NetBSD
2002-11-08 17:06:15 +00:00
Gordon Tetlow
0d8441a9fe Remove the sourceing of rc.conf from the debug subroutine. This caused
problems when you try to override variables locally.
2002-09-12 17:27:36 +00:00