Services and rc.d
NetBSD starts services through rc.d: one script
per service, and one configuration file that decides which of them run.
Makronix uses the mechanism unchanged; the services that a desktop needs
are already configured.
/etc/rc.conf
/etc/rc.conf holds one variable per service.
foo=YES starts the service at boot,
foo=NO does not. The file is read by
rc8;
the variables are documented in
rc.conf5
and in the header of each script.
# grep -v '^#' /etc/rc.conf | grep .
A local addition belongs in /etc/rc.conf, not
in a script: it survives an upgrade, and etcupdate
knows how to merge it. A single service can also be configured in
/etc/rc.conf.d/service,
which is useful when a package or an administrator owns one file.
Starting, stopping and checking a service
The scripts are in /etc/rc.d. Each takes the
verbs start, stop,
restart, status and
onestart (start it now without changing
rc.conf):
# /etc/rc.d/dhcpcd status
# /etc/rc.d/dhcpcd restart
# /etc/rc.d/sshd onestart
A service that fails at boot writes its reason to the console and
to /var/log/messages. A script that is not
executable, or a variable with a typo, is the usual cause. The order in
which the scripts run is decided by the REQUIRE and
PROVIDE lines at the top of each script, not by the
alphabetical order; rcorder8
prints the order.
The desktop services
On a Makronix desktop the relevant entries are:
dhcpcd=YES
The DHCP client, when the network is configured by
DHCP. A machine with a fixed address sets
dhcpcd=NO and configures the interface in
/etc/ifconfig.if.
sshd=YES
The Secure Shell server. The installer enables it;
the firewall lets it in.
ntpd=YES
Time synchronisation. The server list is
/etc/ntp.conf.
npf=YES
The firewall. Its rules are in
/etc/npf.conf;
explains them.
dtlogin=YES
The graphical login. Without it the machine starts
with a text console; startx is not the same
thing, and the MCDE session is started by
dtlogin.
cupsd=YES
The print service, when printing is set up
().
Adding a service
A service that comes from pkgsrc installs its own script in
/usr/pkg/share/examples/rc.d or
/etc/rc.d. Copy it into
/etc/rc.d if it is an example, make it executable,
add the variable to /etc/rc.conf, and start it once
to see whether it works before the next boot:
# cp /usr/pkg/share/examples/rc.d/foo /etc/rc.d/foo
# chmod 755 /etc/rc.d/foo
# echo 'foo=YES' >> /etc/rc.conf
# /etc/rc.d/foo start
# /etc/rc.d/foo status
If the service needs a directory or a user, its package
documentation says so; pkg_info -D foo prints the
message that came with the package.