Many users install third party software on FreeBSD from the Ports Collection and require the installed services to be started upon system initialization. Services, such as mail/postfix or www/apache22 are just two of the many software packages which may be started during system initialization. This section explains the procedures available for starting third party software.
In FreeBSD, most included services, such as cron(8), are started through the system start up scripts.
Now that FreeBSD includes rc.d
,
configuration of application startup is easier and provides
more features. Using the key words discussed in
節 11.4, “管理 FreeBSD 中的服務”, applications can be set to
start after certain other services and extra flags can be
passed through /etc/rc.conf
in place of
hard coded flags in the start up script. A basic script may
look similar to the following:
#!/bin/sh
#
# PROVIDE: utility
# REQUIRE: DAEMON
# KEYWORD: shutdown
. /etc/rc.subr
name=utility
rcvar=utility_enable
command="/usr/local/sbin/utility"
load_rc_config $name
#
# DO NOT CHANGE THESE DEFAULT VALUES HERE
# SET THEM IN THE /etc/rc.conf FILE
#
utility_enable=${utility_enable-"NO"}
pidfile=${utility_pidfile-"/var/run/utility.pid"}
run_rc_command "$1"
This script will ensure that the provided
utility
will be started after the
DAEMON
pseudo-service. It also provides a
method for setting and tracking the process ID
(PID).
This application could then have the following line placed
in /etc/rc.conf
:
utility_enable="YES"
This method allows for easier manipulation of command
line arguments, inclusion of the default functions provided
in /etc/rc.subr
, compatibility with
rcorder(8), and provides for easier configuration via
rc.conf
.
Other services can be started using inetd(8). Working with inetd(8) and its configuration is described in depth in 節 28.2, “inetd 超級伺服器”.
In some cases, it may make more sense to use cron(8) to start system services. This approach has a number of advantages as cron(8) runs these processes as the owner of the crontab(5). This allows regular users to start and maintain their own applications.
The @reboot
feature of cron(8),
may be used in place of the time specification. This causes
the job to run when cron(8) is started, normally during
system initialization.
本文及其他文件,可由此下載: ftp://ftp.FreeBSD.org/pub/FreeBSD/doc/。
若有 FreeBSD 方面疑問,請先閱讀
FreeBSD 相關文件,如不能解決的話,再洽詢
<questions@FreeBSD.org>。
關於本文件的問題,請洽詢
<doc@FreeBSD.org>。