GuidesModules
service.enabled
Ensures a service is enabled to start at boot. Does not affect whether the service is currently running.
Source: pkg/state/modules/service.go
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
name | string | No | State ID | The service name. If omitted, the state ID is used. |
All states also accept the full set of requisite parameters and Salt-parity state attributes — see Dependencies & Requisites.
Check Behavior
- Calls
systemctl is-enabled --quiet <service>(via the injected ServiceExec). - Reports no changes needed if the service is already enabled.
- Reports
NeedsChange: trueif the service is not enabled.
Apply Behavior
- Calls
Enableon the service manager. - Returns
Changed: true.
Revert Behavior
- Calls
Disableon the service manager. - Returns
Changed: true.
Details Returned
| Key | Description |
|---|---|
service | The service name |
manager | The service manager name (e.g., "systemd") |
Examples
Ensure sshd starts at boot
sshd:
service.enabled:
- require:
- pkg.installed:openssh-serverEnable after installation
openssh-server:
pkg.installed: []
sshd:
service.enabled:
- require:
- pkg.installed:openssh-serverExplicit name
enable-nginx-boot:
service.enabled:
- name: nginxservice.running
Ensures a service is started on the target system. When triggered via a watch requisite (e.g., a config file changed), it restarts the service rather than starting it.
service.dead
Ensures a service is stopped on the target system. Optionally also disables the service at boot when enable: false is set.