LinuxCommandLibrary

service

Manage system services

TLDR

List the name and status of all services

$ service --status-all
copy

Start/Stop/Restart/Reload service (start/stop should always be available)
$ service [service_name] [start|stop|restart|reload]
copy

Do a full restart (runs script twice with start and stop)
$ service [service_name] --full-restart
copy

Show the current status of a service
$ service [service_name] status
copy

SYNOPSIS

service script command
service --status-all
service script --full-restart

PARAMETERS

script
    The name of the service's init script, e.g., apache2 or sshd.

command
    The action to perform on the service, typically one of start, stop, restart, status, reload, or force-reload.

--status-all
    Displays the status of all available System V init services.

--full-restart
    Forces a complete restart of the service, often equivalent to stopping and then starting.

--help
    Displays a help message and usage information for the command.

--version
    Shows the version information of the service command.

DESCRIPTION

The service command provides a standardized interface for interacting with System V init scripts located in /etc/init.d/.
It allows users to start, stop, restart, or check the status of services managed by these scripts. Prior to systemd, service was the primary method for controlling daemon processes on many Linux distributions (like Red Hat, Fedora, and Debian-based systems). It abstracts away the need to manually navigate to /etc/init.d/ and execute scripts directly, offering a cleaner and more user-friendly syntax.
While still available on most modern Linux distributions, its functionality is often a wrapper around systemctl for compatibility, as systemd has become the default init system.

CAVEATS

The service command is primarily designed for System V init systems.
On modern Linux distributions that use systemd (such as CentOS 7+, Ubuntu 15.04+, Debian 8+), service acts largely as a compatibility layer. Commands issued via service are often translated and executed by systemctl internally. This means that while service still works, systemctl is the native and more powerful way to manage services on these systems. Its capabilities for complex service management (like dependency handling, cgroup management) are limited compared to systemctl.

COMPATIBILITY LAYER

On systemd powered systems, the service command typically calls the appropriate systemctl command behind the scenes. For instance, service sshd start often translates internally to systemctl start sshd. This ensures backward compatibility for older scripts and user habits.

SERVICE STATUS OUTPUT

The output of service --status-all can vary. Services managed by systemd might show their status using systemd's conventions, while truly init.d managed services might show a [ + ] for running, [ - ] for stopped, or [ ? ] for unknown status.

HISTORY

The service command emerged as a simplification tool for administering services managed by System V init scripts. Before service, users often had to manually execute scripts like /etc/init.d/apache2 start.
service provided a cleaner, more standardized interface, improving usability. It was widely adopted across various Linux distributions. With the advent of alternative init systems like Upstart and especially systemd in the 2010s, the direct role of service diminished. While still included for backward compatibility, its significance is largely overshadowed by systemctl on contemporary systems.

SEE ALSO

Copied to clipboard