FreeBSD Fundamentals · Module 06 of 14

Services, processes and logs

Operate rc.d services, inspect processes and sockets, and use logs as evidence rather than guessing.

Learning objectives

By the end of this module, you should be able to:

  • Start/stop/restart services intentionally.
  • Inspect processes and open sockets.
  • Locate useful base and package logs.

Service scripts and process state

service is the front end for rc.d scripts. ps, procstat and sockstat help connect service intent to actual process/socket state.

Logs are evidence

/var/log contains many base-system logs. Third-party applications may log under /var/log or application-specific paths; consult package documentation and rc scripts.

Worked examples

See the idea in practice.

Triangulate a daemon

service sshd status
pgrep -laf sshd
sockstat -4 -6 | grep ssh
tail -n 20 /var/log/auth.log
  • A service can be enabled but failed, or running but not listening where expected.
  • Use multiple signals before changing configuration.
Hands-on lab

Lab — Diagnose a service from four angles

Goal: Check configuration, rc state, process state and socket state for SSH.

Before you start

  • SSH installed in the base system.
STEP 1

Configuration

sysrc sshd_enable
sshd -t
STEP 2

Service and process

service sshd status || true
pgrep -laf sshd || true
STEP 3

Sockets and logs

sockstat -4 -6 | grep sshd || true
tail -n 30 /var/log/auth.log

Verify

  • You can tell whether SSH is configured, running and listening.

Expected outcome

  • Evidence from rc configuration, process table, sockets and logs can be reconciled.

If it fails

  • If service output and process state disagree, inspect the rc script and recent logs before restarting.
Real-world connection

Production diagnosis should connect desired state, process state, network state and logs.

Avoid these traps

Common mistakes

  • Restarting repeatedly without reading logs.
  • Assuming an enabled service is necessarily healthy.
Knowledge check

Can you explain it without looking back?

Open each answer only after you have tried to answer the question yourself.

1What does sockstat show?

Open sockets and the processes/users associated with them.

2Why use sshd -t before a restart?

It validates SSH configuration syntax and reduces the risk of locking out remote access.

3What is the role of service?

It invokes rc.d service scripts for lifecycle actions.

My Learning

Record your progress for this module.

Progress is saved in this browser immediately. When you sign in to My Learning, it can also sync across devices.

Not started

Attempt the core lab and knowledge checks before marking the module complete.