Skip to content

FreeBSD basics – 3 – Services

This is the third post in the series about getting started with FreeBSD. We’ve looked at the first steps here, and users and groups here. Today we’re looking at how FreeBSD handles services. For those who still don’t like systemd the good news is: There is nothing like systemd in FreeBSD. For those who do like systemd the maybe bad news is: This is not Linux, do not expect things to work the same way in FreeBSD. This is more or less the same when it comes to comparing PostgreSQL to other database systems: They are not the same. Some things might work the same, some features might be the same, but still they are separate systems and you need to adapt what you already know to the specific product. Using and working with FreeBSD as a Linux user is the same story.

We’ve already used the “service” command to restart the network stack in the first post. This is the tool on FreeBSD to interact with services and if you don’t know which services are enabled on a FreeBSD system, the service command can answer that question:

root@freebsd14:~ $ service -e
/etc/rc.d/hostid
/etc/rc.d/zpool
/etc/rc.d/zpoolupgrade
/etc/rc.d/zpoolreguid
/etc/rc.d/zvol
/etc/rc.d/hostid_save
/etc/rc.d/kldxref
/etc/rc.d/zfsbe
/etc/rc.d/zfs
/etc/rc.d/devmatch
/etc/rc.d/cleanvar
/etc/rc.d/rctl
/etc/rc.d/ip6addrctl
/etc/rc.d/mixer
/etc/rc.d/netif
/etc/rc.d/resolv
/etc/rc.d/devd
/etc/rc.d/motd
/etc/rc.d/os-release
/etc/rc.d/virecover
/etc/rc.d/dmesg
/etc/rc.d/gptboot
/etc/rc.d/newsyslog
/etc/rc.d/syslogd
/etc/rc.d/savecore
/etc/rc.d/ntpd
/etc/rc.d/utx
/etc/rc.d/sendmail
/etc/rc.d/sshd
/etc/rc.d/cron
/etc/rc.d/bgfsck

The list of services which is printed here, is already in the right order. That means the first service in that list, is the first one which is started when the system is booting. The question is where that is defined, and how the rc system knows how to order those scripts for a startup, but also for a shutdown of the system. This information comes out of the header of those scripts, e,g, if we take SSH as an example:

root@freebsd14:~ $ head /etc/rc.d/sshd 
#!/bin/sh
#
#

# PROVIDE: sshd
# REQUIRE: LOGIN FILESYSTEMS
# KEYWORD: shutdown

. /etc/rc.subr

The “REQUIRE” directive defines what needs to be there before sshd can be started and this is how the order is determined. Internally this is done by rcorder (there are additional directives, not just REQUIRE). When the system is starting up “/etc/rc” checks what needs to be started and then calls the corresponding scripts in “/etc/rc.d” and “/usr/local/etc/rc.d”.

Starting, stopping, restarting and, depending on the service, other tasks are all done with the “service” command. An easy way to get all the options for a specific service is to give a command you know is not existing:

root@freebsd14:~ $ service sshd a
/etc/rc.d/sshd: unknown directive 'a'.
Usage: /etc/rc.d/sshd [fast|force|one|quiet](start|stop|restart|rcvar|enable|disable|delete|enabled|describe|extracommands|configtest|keygen|reload|status|poll)

“describe” is quite good if you don’t know what a service is about:

Questions about your own setup? A dbi services consultant can look at your case.

Talk to an expert (opens in a new tab)
root@freebsd14:~ $ service sshd describe
Secure Shell Daemon

What we also have already seen in first post is, how a service gets enabled. Either you do it using the sysrc utility (what is recommended):

root@freebsd14:~ $ sysrc ssh_enable=yes
ssh_enable:  -> yes

… or directly in “/etc/rc.conf”:

root@freebsd14:~ $ grep enable /etc/rc.conf | egrep -v "^#"
sshd_enable="YES"
ntpd_enable="YES"
moused_nondefault_enable="NO"
zfs_enable="YES"
ssh_enable="yes"

The prefix is always the name of the service (or the name of the rc script) followed by an underline and “enable”. Quite easy and simple.

In the next post we’ll look into Jails, which provide a lightweight virtualization layer we then use for installing PostgreSQL instances in a later post.

Let’s work together

Ready to operate at
the next level?

Tell us about your challenge. We’ll bring the depth, the expertise, and the Swiss precision.

Open source Team

Open source Team

Posts published under the Open source Team account are collective contributions by the dbi services open infrastructure consultants. The practice covers open-source databases and platforms, PostgreSQL first of all, along with MySQL, MariaDB, and Linux, from architecture, replication, and high availability to performance tuning and operations under service level agreements, and contributes actively to the PostgreSQL community.View Author posts

721 posts since September 2011

Most read in Operating System

The Operating System posts our readers open most: the all-time favourites, and what is trending right now.

Leave a Comment

Your email address will not be published. Required fields are marked *