Skip to main content
gentoo fundamentals beginner 10 min

OpenRC Service Management

Managing services with OpenRC - Gentoo's init system for declarative service management without systemd

OpenRC Service Management

What It Is

OpenRC is Gentoo’s default init system - a lightweight, dependency-based init system that manages service startup, shutdown, and runlevels. It’s the alternative to systemd that many Gentoo users prefer.

Why OpenRC?

OpenRC offers:

  • Simplicity - Shell-based service scripts, easy to understand and modify
  • Speed - Parallel service startup with dependency tracking
  • UNIX Philosophy - Does one thing well, uses standard tools
  • Flexibility - Works with any kernel, no PID 1 lock-in
  • Transparency - Clear, readable init scripts

Critical Warning

Never use systemd commands on an OpenRC system:

WrongRight
systemctl start dockerrc-service docker start
systemctl enable sshdrc-update add sshd default
journalctl -xeCheck /var/log/ files
systemctl status nginxrc-service nginx status

Core Commands

Service Control

# Start a service
rc-service docker start

# Stop a service
rc-service nginx stop

# Restart a service
rc-service sshd restart

# Check service status
rc-service postgresql status

Runlevel Management

# Show all running services
rc-status

# Show services in a specific runlevel
rc-status default

# Add service to default runlevel (enable at boot)
rc-update add sshd default

# Remove service from runlevel (disable at boot)
rc-update del docker default

# Show which runlevels a service is in
rc-update show sshd

Available Runlevels

RunlevelPurpose
sysinitSystem initialization (mounting filesystems)
bootEarly boot services (networking, logging)
defaultNormal operation services
shutdownShutdown procedures

Service Script Location

OpenRC service scripts live in /etc/init.d/:

ls /etc/init.d/
# Shows: docker, nginx, sshd, postgresql, etc.

Each script supports standard actions:

  • start - Start the service
  • stop - Stop the service
  • restart - Stop then start
  • status - Show if running
  • zap - Reset crashed service state

Writing a Simple Service Script

#!/sbin/openrc-run
# /etc/init.d/myservice

name="My Service"
description="Example service for demonstration"
command="/usr/bin/myservice"
command_args="--daemon"
pidfile="/run/${RC_SVCNAME}.pid"
command_background=true

depend() {
    need net
    after logger
}

Key Variables

VariablePurpose
nameHuman-readable name
descriptionShort description
commandThe executable to run
command_argsArguments to pass
pidfilePID file location
command_backgroundRun in background

Dependency Functions

depend() {
    need net         # Hard dependency - net must be running
    use logger       # Soft dependency - use if available
    after docker     # Order - start after docker
    before nginx     # Order - start before nginx
}

Viewing Logs

OpenRC doesn’t have a centralized journal like systemd. Logs are in traditional locations:

# System messages
/var/log/messages

# Specific service logs
/var/log/nginx/error.log
/var/log/docker.log

# Boot messages
dmesg | less

# Real-time log monitoring
tail -f /var/log/messages

Common Patterns

Starting All Services

# Boot into default runlevel
openrc default

Checking What Failed

# Show services that failed to start
rc-status | grep crashed

# Reset crashed service
rc-service myservice zap

Parallel Startup

OpenRC starts independent services in parallel automatically. Dependencies ensure correct ordering.

Practical Examples

Docker Setup

# Install Docker
emerge app-containers/docker

# Start Docker
rc-service docker start

# Enable at boot
rc-update add docker default

# Verify
rc-service docker status

SSH Server

# Start SSH daemon
rc-service sshd start

# Enable at boot
rc-update add sshd default

# Check status
rc-service sshd status

Configuration

Service-specific configuration typically lives in /etc/conf.d/:

# /etc/conf.d/nginx
NGINX_CONFIGFILE="/etc/nginx/nginx.conf"

These files are sourced by the init script and can override defaults.

Compared to systemd

FeatureOpenRCsystemd
Init scriptsShell scriptsUnit files
PID 1Not requiredRequired
LoggingTraditional syslogjournald
ComplexitySimpleComplex
CustomizationEdit scriptsOverride directories
Dependenciesdepend() functionUnit file directives
  • Runlevels - System operational modes
  • Init Scripts - Service control scripts
  • Portage - Gentoo’s package manager (installs services)
openrcinit-systemservicesgentoo