LinuxCommandLibrary

rc-service

Manage services (start, stop, restart, status)

TLDR

Show a service's status

$ rc-service [service_name] status
copy

Start a service
$ sudo rc-service [service_name] start
copy

Stop a service
$ sudo rc-service [service_name] stop
copy

Restart a service
$ sudo rc-service [service_name] restart
copy

Simulate running a service's custom command
$ sudo rc-service [[-Z|--dry-run]] [service_name] [command_name]
copy

Actually run a service's custom command
$ sudo rc-service [service_name] [command_name]
copy

Resolve the location of a service definition on disk
$ sudo rc-service [[-r|--resolve]] [service_name]
copy

SYNOPSIS

rc-service <service_name> [<command>]
rc-service [options]

PARAMETERS

<service_name>
    The name of the service to manage (e.g., sshd, net.eth0, cronie).

<command>
    The action to perform on the service. Common commands include: start, stop, restart, reload, status, condrestart, zap (remove PID file), crashed (check if service crashed).

-l, --list
    Lists all available services located in /etc/init.d/.

-s, --status-all
    Displays the status of all services currently known to OpenRC.

-i, --info <service_name>
    Shows detailed information about a specific service, including its description, dependencies, and runlevels it belongs to.

--if-exists <service_name> [<command>]
    Executes the specified command only if the service exists. Useful in scripts where a service might not always be present.

-q, --quiet
    Suppresses output for status commands. Useful for scripting.

-V, --version
    Displays the version of OpenRC being used.

-h, --help
    Shows a help message with usage information.

DESCRIPTION

rc-service is a fundamental command-line utility within the OpenRC init system, primarily used for managing services on Linux distributions that utilize OpenRC (such as Gentoo, Alpine Linux, or Artix Linux). It provides a user-friendly interface to interact with service scripts located in /etc/init.d/.

Unlike traditional SysVinit scripts where users might directly execute /etc/init.d/service_name start, rc-service offers a consistent and abstracted way to perform common actions like starting, stopping, restarting, reloading, or checking the status of a service. It acts as a wrapper around the core rc command and leverages OpenRC's dependency-based service management.

The command simplifies service interaction by handling the underlying complexities, making it easier for administrators to control system daemons and processes. It is essential for daily system administration tasks on OpenRC-based systems.

CAVEATS

rc-service is specific to systems using OpenRC as their init system. It is not available or functional on systems primarily using other init systems like systemd, SysVinit (standalone), or runit. Most service management actions (e.g., start, stop, restart) typically require superuser (root) privileges.

COMMON USAGE EXAMPLES

To start a service: rc-service sshd start
To stop a service: rc-service cronie stop
To restart a network interface: rc-service net.eth0 restart
To check the status of a service: rc-service nginx status
To list all available services: rc-service -l
To get information about a service: rc-service -i dnsmasq

SERVICE STATES

OpenRC services can be in various states: started (running), stopped (not running), inactive (not configured to start), or report a crashed status if a process associated with it unexpectedly terminated. rc-service status provides the current state.

INTEGRATION WITH RUNLEVELS

While rc-service manages immediate service actions, OpenRC uses runlevels to define which services start automatically at boot. The rc-update command is used to add or remove services from specific runlevels (e.g., default, boot, shutdown).

HISTORY

OpenRC, and by extension rc-service, originated within the Gentoo Linux project in the mid-2000s. It was developed as a more modular, dependency-aware, and flexible alternative to traditional SysVinit. Its design emphasizes simplicity, parallelization of service startup, and clear separation of concerns. Over time, it has been adopted by other Linux distributions like Alpine Linux, Artix Linux, and Debian's Devuan fork, offering a non-systemd init system option.

SEE ALSO

rc(8), rc-update(8), init.d(8), openrc(8), systemctl(1) (on systemd systems)

Copied to clipboard