Skip to main content

service command

service - run a System V init script

The service command in Linux is a utility used to manage system services (e.g., start, stop, restart, or check the status of daemons like web servers or databases). It’s commonly used on systems with SysVinit or as a compatibility layer for older scripts on systemd-based systems.

Note: On modern systems using systemd, systemctl is the preferred tool, but service often works as a wrapper for backward compatibility.

Usage: service [service_name] [action]

  • service_name: The name of the service (e.g., apache2, ssh).
  • action: The command to perform (e.g., start, stop, restart).

Examples

  • Basic Usage

    Run service with a service name and an action to control it.

    service ssh start
    • Starts the SSH service (often named sshd or ssh depending on the system).
    • Requires root privileges—use sudo if not root:
      sudo service ssh start
  • Common Actions

    Here are the typical actions you can perform:

    ActionDescription
    startStart the service
    stopStop the service
    restartStop and then start the service
    reloadReload configuration without stopping
    statusCheck the service’s current state
    • Stop a service:
      sudo service apache2 stop
    • Restart a service:
      sudo service nginx restart
    • Check status:
      sudo service ssh status
      • Output might vary (e.g., [ ok ] sshd is running or systemd-style details).
  • Listing All Services

    Use service with --status-all to see the status of all services (SysVinit only).

    service --status-all
    • Output (example):
      [ + ]  apache2
      [ - ] bluetooth
      [ ? ] cron
    • +: Running, -: Stopped, ?: Unknown or no status script.

    Note: This doesn’t work reliably on systemd systems—use systemctl list-units instead.

  • Reloading Configuration

    Use reload to apply changes without interrupting the service (if supported).

    sudo service nginx reload
    • Reloads nginx configuration without dropping connections.
  • Using with Systemd

    On systemd systems, service redirects to systemctl under the hood.

    sudo service sshd restart
    • Equivalent to sudo systemctl restart sshd.
    • Output might show systemd messages (e.g., Active: active (running)).
$ service --help
Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]

For more details, check the manual with man service