Daemon
A Daemon is a long-lived process that runs once on every eligible machine or Kubernetes node. It fits work that belongs to the machine: a log or metrics collector, a node agent, a per-host connector, or a loader that supervises a native process.
import * as alien from "@alienplatform/core"
const cluster = new alien.ComputeCluster("compute")
.pool("general", {
requirements: { cpu: 4, memory: "16Gi" },
scale: { type: "autoscale", min: 2, max: 10 },
})
.build()
const collector = new alien.Daemon("collector")
.code({ type: "image", image: "ghcr.io/acme/collector:2.1.0" })
.cluster("compute")
.cpu(0.25)
.memory("256Mi")
.commandsEnabled(true)
.permissions("execution")
.build()
export default new alien.Stack("acme")
.add(cluster, "frozen")
.add(collector, "live")
.permissions({ profiles: { execution: {} } })
.build().permissions("execution") names the Daemon's permission profile, the set of cloud permissions it runs with. execution grants nothing here, because the Daemon uses no other resource. The ComputeCluster is "frozen": the customer's admin creates it during initial setup, and Alien manages the machines inside it.
| Platform | Runs as |
|---|---|
| AWS | One instance per EC2 machine in a ComputeCluster |
| Google Cloud | One instance per Compute Engine machine in a ComputeCluster |
| Azure | One instance per VM in a ComputeCluster |
| Kubernetes | DaemonSet |
| Machines | One instance per joined host |
| Local | Supervised local process from the image |
On AWS, Google Cloud, and Azure, a Daemon must name its cluster with .cluster(). See Behavior and limits for how each platform runs it.
A Daemon is always "live": Alien creates and updates it on every release (see Frozen and live). It runs your process directly.
- Without
.cpu()and.memory(), each instance gets 0.1 vCPU and128Mi. - Without
.permissions(), it gets no cloud identity. - The API reference lists every builder method.
Use a Container instead when you want a number of replicas that scales with load.
Commands
With .commandsEnabled(true), the process starts a pull receiver, so your backend can call it:
import { createCommandReceiver } from "@alienplatform/commands"
const receiver = createCommandReceiver()
receiver.command("flush", async () => ({ flushed: true }))
await receiver.run()The receiver leases commands addressed to this daemon over outbound HTTPS, so the host needs no inbound access.
Host access
const loader = new alien.Daemon("loader")
.code({ type: "image", image: "ghcr.io/acme/loader:1.0.0" })
.cluster("compute")
.runtime({
privileged: true,
networkMode: "host",
pidNamespace: "host",
user: "0:0",
mounts: [{ source: "/var/run", target: "/host/var/run" }],
})
.permissions("execution")
.build()Use .runtime() only for daemons that need the host. It applies on AWS, Google Cloud, and Azure. Kubernetes and Local don't apply it today.
Use it in code
Linked resources are available through the same SDK functions as other workloads, for example storage("files"). To receive commands, start a pull receiver as shown in Commands.
Permissions
| Set | Grants |
|---|---|
daemon/provision | Public endpoint infrastructure. Used by initial setup or live provisioning. |
daemon/management, daemon/heartbeat | Inspecting and managing the daemon. |
compute-cluster/execute | Runtime access the machines need. Granted with the cluster. |