Ignition
ReferenceResources

service

Manage systemd services.

The service resource manages systemd services. States started and stopped are declarative (check first), while restarted and reloaded are imperative (always execute).

Input

FieldTypeDefaultRequiredDescription
namestringYesService name (e.g. "nginx")
state"started" | "stopped" | "restarted" | "reloaded"NoTarget service state
enabledbooleanNoWhether the service should start at boot

At least one of state or enabled should be provided.

Output

FieldTypeDescription
namestringService name
activestringCurrent active state (e.g. "active", "inactive")
enabledstringCurrent enabled state (e.g. "enabled", "disabled")
changedbooleanWhether the service was modified

Behavior

Check phase

  1. Queries systemctl is-active <name> for the running state.
  2. Queries systemctl is-enabled <name> for the boot state.
  3. For state: "started" — in desired state if active.
  4. For state: "stopped" — in desired state if inactive.
  5. For state: "restarted" / "reloaded" — always returns not in desired state (imperative).
  6. For enabled — checks independently of state.

Apply phase

StateCommand
startedsudo systemctl start <name>
stoppedsudo systemctl stop <name>
restartedsudo systemctl restart <name>
reloadedsudo systemctl reload <name>
EnabledCommand
truesudo systemctl enable <name>
falsesudo systemctl disable <name>

state and enabled are applied independently.

Annotations

PropertyValue
NatureMixed — started/stopped are declarative; restarted/reloaded are imperative
IdempotentPartial — started/stopped are idempotent; restarted/reloaded always execute
DestructiveNo
Read-onlyNo
Required capabilitiesexec

Examples

Start and enable

await service({ name: "nginx", state: "started", enabled: true })

Restart after config change

await file({
  path: "/etc/nginx/nginx.conf",
  template: nginxConf,
  mode: "0644",
})
await service({ name: "nginx", state: "restarted" })

restarted always runs systemctl restart, regardless of current state.

Stop and disable

await service({ name: "apache2", state: "stopped", enabled: false })

Reload configuration

await service({ name: "nginx", state: "reloaded" })

Like restarted, reloaded always executes — it doesn't check current state first.

Enable at boot without changing state

await service({ name: "nginx", enabled: true })

Only affects the boot behavior. Doesn't start or stop the service.

Gotchas

  • started and stopped are declarative — they check current state before acting. restarted and reloaded are imperative — they always execute.
  • In check mode, restarted and reloaded always show as "would change".
  • enabled is independent of state. You can enable a stopped service or disable a running one.
  • Requires sudo on the remote host for systemctl operations.
  • Only works with systemd. Doesn't support other init systems.

On this page