services
Synopsis
services [<name>] [name: value]...
Description
Reading the state of system units needs no rights; start, stop, restart, enable and disable on system units need the administrator, which privilege: elevated on the last stage provides (see those commands).
services lists the services of the service manager of the system: systemd
on Linux, the service control manager on Windows and launchd on macOS. It
starts a pipeline and produces one service record per service; on Linux the
records are sorted by name.
A text name selects one service the way the manager resolves names: on
Linux nginx and nginx.service name the same unit and template instances
such as getty@tty1 are accepted; on Windows the comparison ignores case.
When the manager knows no such service, the command fails with E_NOT_FOUND.
A regular expression name keeps the services whose name matches it.
state keeps the services whose state, raw state, or one part of the raw
state separated by / equals the text, ignoring case. state: "failed"
matches the common state; state: "exited" matches the systemd raw state
active/exited.
On Linux the command merges the loaded units with the unit files that are
installed but not loaded, so a disabled service that never ran is listed as
stopped. Units of other types and unit templates are not listed. The manager
is reached over D-Bus; no external program is run. scope: user reads the
manager of the current account on the session bus.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
text | regex |
none | Service name or pattern. |
state |
text |
none | Only services in this state. |
scope |
enum(system|user) |
system |
System services or services of the current account. |
Input and output
| Form | Input | Output |
|---|---|---|
| default | none |
service |
The service record holds name, state (running, stopped, starting,
stopping, failed, paused, unknown), start_type (automatic,
manual, disabled, on_demand, static, unknown), manager, scope,
and where the manager reports them state_raw, description, pid, path,
account and os_raw.
Effect
| Property | Value |
|---|---|
| Category | source |
| Effect | read |
| Reversibility | read |
| Implementation | builtin |
| External use | system_program: launchctl; On macOS the state of services is read through the launchctl component of the operating system. |
Examples
Show one service:
services name: "cron"
List the failed services:
services state: "failed"
List the running services of the current account:
services scope: user state: "running"
Restart one service:
services name: "nginx" |> restart
A response that leaves records out ends with the hint “more: next” and carries the field
continuation; the command next returns the next part without running the
command again.
matched 230 shown 50 more: next
Errors
| Code | Meaning | Typical fix |
|---|---|---|
E_NOT_FOUND |
No service has the given name. | List the services with services and use a listed name. |
E_REGEX |
The pattern of name is not a valid regular expression. |
Correct the pattern. |
E_INVALID_VALUE |
scope is neither system nor user. |
Use scope: system or scope: user. |
E_PRIVILEGE |
The manager refused to show the service; required names the privilege. |
Run as an account with that privilege. |
E_SERVICE |
The manager reported an error or cannot be reached. os_code is no_systemd when systemd is not the service manager and no_user_bus when the account has no session bus. |
Use scope: system, or run on a system managed by systemd. |
E_UNSUPPORTED |
The scope is not available on this system. | Use scope: system. |
Related
start, restart, enable and disable act on the records of services;
stop stops them. logs unit: shows the log of a service. The administration group
page lists the other commands of the group.