Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

docs(agent): run the agent as a service on Linux and Windows

Dimitris Staratzis4c228e33553a
diff --git a/docs/cli/reference.mdx b/docs/cli/reference.mdx
index 32c8d99529..9f3d1cc9ef 100644
--- a/docs/cli/reference.mdx
+++ b/docs/cli/reference.mdx
@@ -47,7 +47,7 @@ Every command accepts these flags.
]}
>
-Run the [Infisical Agent](/integrations/platforms/infisical-agent), a daemon that authenticates as a machine identity and renders secrets into files for your application to read.
+Run the [Infisical Agent](/integrations/platforms/infisical-agent), a daemon that authenticates as a machine identity and renders secrets into files for your application to read. This command runs the agent in the foreground. To run the agent as a service that starts when the machine boots, use [infisical agent service install](/cli/reference#agent-service-install).
Everything is set in the YAML configuration file, including the auth method, sinks, templates, and the Infisical instance in `infisical.address`, which defaults to Infisical Cloud. The global `--domain` flag has no effect. To pass the configuration without a file, set `INFISICAL_AGENT_CONFIG_BASE64` to the base64-encoded YAML. It takes precedence over `--config`.
@@ -55,6 +55,119 @@ For a daemon that only manages certificates, use [infisical cert-manager agent](
</CLICommand>
+<CLICommand
+ id="agent-service"
+ command="agent service"
+>
+
+Install, start, stop, or remove a service that runs the agent, so the agent starts when the machine boots and restarts if it crashes. Each command takes the service's name, which defaults to `infisical-agent`. To run several agents with different configs on one machine, install each agent with its own name.
+
+- On Linux, you run the commands as root, and the service is a systemd service that logs to the systemd journal (`sudo journalctl -u <name>`)
+- On Windows, you run the commands from a terminal opened with **Run as administrator**, and the service is a Windows service that logs to `%ProgramData%\Infisical\Agent\<name>.log` (errors also go to the Windows Event Log)
+
+The commands don't run on macOS. `start`, `stop`, and `uninstall` only act on services that `install` created.
+
+</CLICommand>
+
+<CLICommand
+ id="agent-service-install"
+ command="agent service install"
+ usage="[name] [flags]"
+ args={[
+ { name: "name", usage: "[name]", description: "The service's name. Defaults to `infisical-agent`." },
+ ]}
+ flags={[
+ { name: "--config", value: "<string>", type: "string", default: "agent-config.yaml", description: "The path to the agent's YAML configuration file. The service doesn't use `INFISICAL_AGENT_CONFIG_BASE64`." },
+ ]}
+ examples={[
+ { title: "Install a service on Linux", code: "sudo infisical agent service install my-agent --config=/etc/infisical/agents/my-agent.yaml" },
+ { title: "Install a service on Windows", code: "infisical agent service install my-agent --config=C:\\infisical\\agent-config.yaml" },
+ ]}
+>
+
+Install the agent as a service that starts when the machine boots. The command doesn't start the service, so run [infisical agent service start](/cli/reference#agent-service-start) next.
+
+The service runs as root on Linux and as LocalSystem on Windows, so it runs its own copy of the config that only administrators can change. Relative paths in the copy still resolve from the directory of the original config. The copy is:
+
+- `/etc/infisical/agents/<name>.service-config.yaml` on Linux
+- `%ProgramFiles%\Infisical\Agent\<name>\service-config.yaml` on Windows, next to the service's own copy of `infisical.exe` (to upgrade the service, uninstall it and install it again)
+
+To change the config, edit the copy, then stop and start the service. You can also edit the original and install the service again.
+
+`install` refuses a config that:
+
+- Sets `infisical.exit-after-auth: true`, which would make the agent exit after its first render
+- Reads or writes files in `/home`, `/tmp`, or `/var/tmp` on Linux, because the service can't read `/home` and has its own private `/tmp` and `/var/tmp` (keep these files in a directory such as `/etc/infisical/agents`)
+
+</CLICommand>
+
+<CLICommand
+ id="agent-service-start"
+ command="agent service start"
+ usage="[name]"
+ args={[
+ { name: "name", usage: "[name]", description: "The service to start. Defaults to `infisical-agent`." },
+ ]}
+ examples={[
+ { title: "Start a service on Linux", code: "sudo infisical agent service start my-agent" },
+ { title: "Start a service on Windows", code: "infisical agent service start my-agent" },
+ ]}
+>
+
+Start an agent service and wait until the agent has loaded its config. If the agent can't start, the command fails and prints where to find the agent's logs.
+
+</CLICommand>
+
+<CLICommand
+ id="agent-service-stop"
+ command="agent service stop"
+ usage="[name]"
+ args={[
+ { name: "name", usage: "[name]", description: "The service to stop. Defaults to `infisical-agent`." },
+ ]}
+ examples={[
+ { title: "Stop a service on Linux", code: "sudo infisical agent service stop my-agent" },
+ { title: "Stop a service on Windows", code: "infisical agent service stop my-agent" },
+ ]}
+>
+
+Stop an agent service and wait for the agent to exit. If the config sets `infisical.revoke-credentials-on-shutdown: true`, the agent revokes its credentials before it exits, which can take up to five minutes. The service starts again the next time the machine boots.
+
+</CLICommand>
+
+<CLICommand
+ id="agent-service-uninstall"
+ command="agent service uninstall"
+ usage="[name]"
+ args={[
+ { name: "name", usage: "[name]", description: "The service to remove. Defaults to `infisical-agent`." },
+ ]}
+ examples={[
+ { title: "Remove a service on Linux", code: "sudo infisical agent service uninstall my-agent" },
+ { title: "Remove a service on Windows", code: "infisical agent service uninstall my-agent" },
+ ]}
+>
+
+Stop an agent service and remove it, along with the service's copy of the config. The original config and the agent's logs stay where they are.
+
+</CLICommand>
+
+<CLICommand
+ id="agent-start"
+ command="agent start"
+ usage="[flags]"
+ flags={[
+ { name: "--config", value: "<string>", type: "string", default: "agent-config.yaml", description: "The path to the agent's YAML configuration file. Can also be set with `INFISICAL_AGENT_CONFIG_PATH`." },
+ ]}
+ examples={[
+ { title: "Start the agent with a config set in the environment", code: "export INFISICAL_AGENT_CONFIG_PATH=/etc/infisical/agents/my-agent.yaml\ninfisical agent start" },
+ ]}
+>
+
+Run the agent in the foreground, as [infisical agent](/cli/reference#agent) does, with relative paths in the config resolved from the config's directory. The systemd service that [infisical agent service install](/cli/reference#agent-service-install) creates runs this command. Unlike `infisical agent`, `agent start` ignores `INFISICAL_AGENT_CONFIG_BASE64`.
+
+</CLICommand>
+
<CLICommand
id="agent-vault"
command="agent-vault"
diff --git a/docs/integrations/platforms/infisical-agent.mdx b/docs/integrations/platforms/infisical-agent.mdx
index 8f0470d1d4..dc21aa29ee 100644
--- a/docs/integrations/platforms/infisical-agent.mdx
+++ b/docs/integrations/platforms/infisical-agent.mdx
@@ -527,4 +527,35 @@ After defining the agent configuration file, run the command below pointing to t
```bash
infisical agent --config example-agent-config-file.yaml
-```
\ No newline at end of file
+```
+
+## Run the agent as a service
+
+To keep the agent running after you close the terminal, and start it again when the machine boots, install it as a service with [infisical agent service install](/cli/reference#agent-service-install). On Linux, the agent runs as a systemd service. On Windows, it runs as a Windows service.
+
+<Tabs>
+ <Tab title="Linux">
+ The service can't read `/home`, and it doesn't share `/tmp` or `/var/tmp` with the rest of the machine. Keep the config, and the files the agent reads and writes, in another directory, such as `/etc/infisical/agents`.
+
+ ```bash
+ sudo infisical agent service install my-agent --config=/etc/infisical/agents/my-agent.yaml
+ sudo infisical agent service start my-agent
+ ```
+
+ To read the agent's logs, run `sudo journalctl -u my-agent`.
+ </Tab>
+ <Tab title="Windows">
+ Open PowerShell with **Run as administrator**, then run:
+
+ ```powershell
+ infisical agent service install my-agent --config=C:\infisical\agent-config.yaml
+ infisical agent service start my-agent
+ ```
+
+ The agent logs to `C:\ProgramData\Infisical\Agent\my-agent.log` and also writes errors to the Windows Event Log. To upgrade the service, uninstall it and install it again with the new `infisical.exe`.
+ </Tab>
+</Tabs>
+
+The service runs its own copy of your config that only administrators can change, and `install` prints where the copy is. Relative paths in the copy still resolve from the directory of the original config. To change the config, edit the copy, then stop and start the service, or edit the original and install the service again.
+
+To stop the service or remove it, use [infisical agent service stop](/cli/reference#agent-service-stop) or [infisical agent service uninstall](/cli/reference#agent-service-uninstall).