Usr/local/etc/rc.d
Ninereasons (Talk | contribs) (→rc.subr: - manually starting <service> ( <service>_enable="NO")) |
Ninereasons (Talk | contribs) (→rc.subr: -) |
||
Line 23: | Line 23: | ||
==rc.subr== | ==rc.subr== | ||
− | '''rc.subr''' is a subroutine library that was developed primarily for the NetBSD system and imported into FreeBSD where it was further developed. Under FreeBSD 4.x, you may have noticed this file being installed into ''/usr/local/etc/rc.subr'', where it was increasingly used by port-installed services. Sometime after FreeBSD 4.x, this file became integral to the FreeBSD startup mechanism for both, base-installed services and port-installed services. At the same time, the directory ''/etc/rc.d'' appeared in FreeBSD, where you will find startup scripts for all base-installed services (so that, for example, ''/etc/rc.sendmail'' disappeared, and was replaced by ''/[[etc/rc.d/sendmail]]'', which uses the ''rc.subr'' mechanism) | + | '''rc.subr''' is a subroutine library that was developed primarily for the NetBSD system and imported into FreeBSD where it was further developed. See [http://www.freebsd.org/cgi/man.cgi?query=rc.subr&apropos=0&sektion=0&manpath=FreeBSD+6.0-RELEASE+and+Ports&format=html man rc.subr] |
+ | |||
+ | |||
+ | Under FreeBSD 4.x, you may have noticed this file being installed into ''/usr/local/etc/rc.subr'', where it was increasingly used by port-installed services. Sometime after FreeBSD 4.x, this file became integral to the FreeBSD startup mechanism for both, base-installed services and port-installed services. At the same time, the directory ''/etc/rc.d'' appeared in FreeBSD, where you will find startup scripts for all base-installed services (so that, for example, ''/etc/rc.sendmail'' disappeared, and was replaced by ''/[[etc/rc.d/sendmail]]'', which uses the ''rc.subr'' mechanism) | ||
Besides being a repository of some very useful and well-written functions, perhaps the chief advantage of using the file is that it ties the configuration, startup and shutdown of these services to /[[etc/rc.conf]] in a consistent way. Unless the service has an ''_enable'' line in ''rc.conf'', the ''start'' and ''stop'' commands have no effect. | Besides being a repository of some very useful and well-written functions, perhaps the chief advantage of using the file is that it ties the configuration, startup and shutdown of these services to /[[etc/rc.conf]] in a consistent way. Unless the service has an ''_enable'' line in ''rc.conf'', the ''start'' and ''stop'' commands have no effect. | ||
− | [[User:Jimbo|Some folks]] don't like starting all of their services from ''/etc/rc.conf''. ''' ''rc.subr'' ''' accommodates this preference with the | + | [[User:Jimbo|Some folks]] don't like starting all of their services from ''/etc/rc.conf''. ''' ''rc.subr'' ''' accommodates this preference with the prefixes, ''force'' and ''one''. |
− | + | ===Examples=== | |
− | + | Manually start and stop mysql, even though <code>mysql_enable</code> is set to <code>"NO"</code> (default) in ''rc.conf''. | |
− | + | ||
− | # /usr/local/etc/rc.d/mysql-server forcestop | + | * Skip all failing pre-requisite "''require''" tests (if any). |
+ | # /usr/local/etc/rc.d/mysql-server forcestart | ||
+ | # /usr/local/etc/rc.d/mysql-server forcestop | ||
+ | * Skip only the ''="YES"'' test | ||
+ | # /usr/local/etc/rc.d/mysql-server onestart | ||
+ | # /usr/local/etc/rc.d/mysql-server onestop | ||
[[Category:Important Config Files]] | [[Category:Important Config Files]] |
Revision as of 16:47, 9 May 2006
/usr/local/etc/rc.d isn't actually a config file, it's a directory. Any executable shell script in this directory will be executed (using the Bourne shell) with the argument "start" when the system boots, and again with the argument "stop" when the system is shut down.
You may find this generic rc.d script (shown as I use it to start bind9) handy for general purpose use:
#!/bin/sh case "$1" in start) /usr/sbin/named -c /etc/namedb/named.conf & echo "bind9" exit 0 ;; stop) exec killall named ;; *) echo "Usage: `basename $0` {start|stop}" >&2 exit 64 ;; esac
Note that scripts in /usr/local/etc/rc.d cannot and will not execute, at boot time or otherwise, if you do not set the permissions to allow their execution. In most cases, you will want to chmod 755 any rc.d scripts, though you may also consider 700 on root-owned rc.d scripts to make sure that unprivileged users don't mess with attempting to start or stop sensitive services.
rc.subr
rc.subr is a subroutine library that was developed primarily for the NetBSD system and imported into FreeBSD where it was further developed. See man rc.subr
Under FreeBSD 4.x, you may have noticed this file being installed into /usr/local/etc/rc.subr, where it was increasingly used by port-installed services. Sometime after FreeBSD 4.x, this file became integral to the FreeBSD startup mechanism for both, base-installed services and port-installed services. At the same time, the directory /etc/rc.d appeared in FreeBSD, where you will find startup scripts for all base-installed services (so that, for example, /etc/rc.sendmail disappeared, and was replaced by /etc/rc.d/sendmail, which uses the rc.subr mechanism)
Besides being a repository of some very useful and well-written functions, perhaps the chief advantage of using the file is that it ties the configuration, startup and shutdown of these services to /etc/rc.conf in a consistent way. Unless the service has an _enable line in rc.conf, the start and stop commands have no effect.
Some folks don't like starting all of their services from /etc/rc.conf. rc.subr accommodates this preference with the prefixes, force and one.
Examples
Manually start and stop mysql, even though mysql_enable
is set to "NO"
(default) in rc.conf.
- Skip all failing pre-requisite "require" tests (if any).
# /usr/local/etc/rc.d/mysql-server forcestart # /usr/local/etc/rc.d/mysql-server forcestop
- Skip only the ="YES" test
# /usr/local/etc/rc.d/mysql-server onestart # /usr/local/etc/rc.d/mysql-server onestop