Skip to main content

Agent Installation

The agent is a single static Go binary. It runs as a service on every host you want to monitor - a systemd unit on Linux, an OpenRC service on Alpine, an upstart job on Synology DSM 6, a Windows service on Windows - looks at the host once every 30 seconds and posts what it found to the dashboard's webhook. It opens no ports and needs no inbound access.

This page covers getting one onto a host and confirming it works. What it then collects is on Agent Collectors; the tokens and logins some collectors need are on Agent Settings.

Two things that surprise people​

The host exists before the agent reports, one way or another. Either you create it in the dashboard and install the agent with its key, or the host registers itself with a customer's enrollment token (see Enrollment tokens), which creates the host under that customer. A host with neither has nowhere to report to. Created by hand, a host comes from Hosts → Add host → With agent. See Customers and Hosts.

The API key is shown once. It is created with the host, shown in the dialog that follows, and stored only as a hash — the dashboard cannot show it again. If you lose it before the install, regenerate it: Regenerate key (Manage key in the host's ⋯ menu). It replaces the host's key and shows the new one.

Regenerating does not disturb an agent that is already running, despite the warning the dialog shows. The key is only used for the one-time configuration fetch during installation; everything afterwards is authenticated with the webhook secret. You need the new key only if you install, or re-fetch the configuration, on a host.

Requirements​

Everything up to Windows hosts at the end of this page describes a Linux host: the paths, the unit and the install.sh command are that installer's.

On the hostWhy
Linux on amd64 or arm64the architectures the dashboard serves a Linux binary for
systemdthe agent is installed as a systemd unit. Alpine, which has OpenRC, and Synology DSM 6, which has upstart, are the exceptions, see Alpine Linux and Synology DSM 6. With none of the three the installer stops and says so
bashthe installer is a bash script. Debian, Ubuntu, RHEL and Synology have it; on Alpine the install command adds it
curlused to download the binary and the configuration. On Alpine the install command adds it; elsewhere a host without it gets a message that names the package to install
root (or sudo)the installer writes to /opt and the service manager's directory; the service itself also runs as root
outbound HTTPS to the dashboardreports, settings and update checks all go outward from the host

The installer installs no packages of its own.

Where the install command comes from​

Creating a host hands it to you straight away: the Host created – install the agent dialog shows the key and the finished command.

The install dialog and the enrollment token dialog first ask for the operating system with two buttons, Linux and Windows. There is one Linux command for every distribution, Alpine and Synology DSM 6 included, with the host's key and this dashboard's address filled in:

[ -x /sbin/apk ] && apk add -q bash curl; curl -sSL https://<your-dashboard>/api/agent/install.sh | $([ "$(id -u)" = 0 ] || echo sudo) bash -s -- \
--api-key <key> --endpoint https://<your-dashboard>

Run it on the host. As root it runs as is; as anyone else it asks for sudo. The first part only does something on Alpine, where it installs bash and curl. The --endpoint is always required, including on updates; the script does not remember it.

Settings → Agents → Install shows no command, because the key is only known when the host is created. It lists the steps for the chosen operating system, the current agent version, downloads of the binaries (Linux amd64 and arm64, Windows amd64) and of the installer script, and the manual steps, requirements and service commands. To get a command for an existing host later, regenerate its key as described above. To create many hosts, add them on the Hosts page one by one, or let them register themselves with a customer's enrollment token.

What the installer does​

  1. Checks the ground. Refuses without root, without bash, without a service manager it knows (systemd at /run/systemd/system, OpenRC, or DSM 6's upstart) or without curl, and each refusal says what to install or use instead. Maps uname -m to amd64 or arm64 and stops on anything else.
  2. Downloads the binary from /api/agent/download?arch=<amd64|arm64> to /opt/selvara-agent/selvara-agent.new and runs it with -version. A binary that does not run is deleted and the install aborts, so a bad download cannot leave the host without a working agent.
  3. Fetches the configuration from /api/agent/config?key=<key> and writes it to /opt/selvara-agent/config.yaml with mode 600. The dashboard looks the key up, and returns that host's id, the webhook URL and the webhook secret. A fresh configuration also deletes /opt/selvara-agent/server-url, so the host reports to the server the new file names. Without --api-key this step is skipped and the existing files are kept.
  4. Swaps the binary in. Stops a running agent, moves .new over /opt/selvara-agent/selvara-agent.
  5. Writes and starts the unit. /etc/systemd/system/selvara-agent.service, then daemon-reload, enable, restart. The unit joins the group of every PHP-FPM pool socket it finds at that moment — see What the agent needs to see. After two seconds it checks the unit is active and prints the version, or exits non-zero and points you at the journal.

Where everything lives​

PathContents
/opt/selvara-agent/selvara-agentthe binary
/opt/selvara-agent/config.yamlthe configuration, mode 600
/opt/selvara-agent/host-policy.jsononly on a host that follows the dashboard for its actions: the signed policy it last accepted, checked again at every start; see Agent Settings
/opt/selvara-agent/host-key.pemthe host's own key for the live link, mode 600, created on first start. It never leaves the host
/opt/selvara-agent/server-urlonly on a host that was moved to another server: the server it reports to now, which outranks webhook_url — see Backup and Restore
/etc/systemd/system/selvara-agent.servicethe unit
journal, identifier selvara-agentall output; the agent writes no log files

The configuration file​

The file holds only how to reach the dashboard. Which services run on the host is detected, and the tokens and logins they need come from the dashboard.

system_id: "<the system's id in the dashboard>"
webhook_url: "https://<your-dashboard>/api/webhook/metrics"
webhook_secret: "<this system's own secret>"
agent_key: "<this system's install key>"
interval: 30
KeyRequiredDefaultMeaning
system_idyes–which host this host reports as
webhook_urlyes–where reports go. The settings endpoint is derived from it: same host, /api/agent/settings
webhook_secretyes–signs every request. The dashboard derives it from its WEBHOOK_SECRET and the host id, so it proves this host and no other; the installer's download writes it for you. A file written by Selvara 2.x holds the instance-wide secret. The dashboard still accepts it for monitoring until the host updates to agent 3.0.0, which writes its own secret into the file by itself; see Upgrading. The WEBHOOK_SECRET environment variable on the host overrides the file
agent_keyfor the live link–this host's own install key, which the installer's download writes for you; a host installed before the live link receives it from the dashboard with its settings and adds it to the file. The live link presents it once, with the host's own key, so that another host cannot enrol a key for this host first. Without it the live link stays off and reports go on. Regenerating the key on the host's page makes the old one useless for enrolment and cuts off the host that held it: its recorded host key is cleared and its link closed, and it enrols again once the new file is installed
actionsnononethe kinds of change this host lets the dashboard make (accounts, agent 3.3.5 and later, lets it create, change and remove server accounts and their sudo rules, see SSH Keys; it is in no default set and has to be named): patch, script, service, reboot, ssh-ca, ssh-keys, accounts, discovery, defender, terminal, tunnel, desktop. Empty means the host is only watched. desktop (agent 3.2.0 and later) lets the dashboard open the RDP, VNC, SSH and web ports that listen on this host through its own agent; it is in no default set and has to be named; see Agent Settings. The file decides: a list here, even an empty one (actions: []), is never changed from the dashboard. Only where the key is absent altogether, and the operator of the gateway has switched remote actions on, may the dashboard supply the list; see Agent Settings. Set it with --actions at install or with selvara-agent configure, below. An unknown name is logged and ignored
discovery.snmp_communitiesnononethe SNMP v2c communities a network discovery scan tries on the devices it finds. They are read from this file only and never travel in a job. Without any, a scan does not ask over SNMP
job_keyfor the live linkpinned on first usethe dashboard's Ed25519 public key (base64), pinned here. Jobs and sessions signed by any other key are refused. A host that has none asks the dashboard for it once, with its own secret, writes it here and keeps it; see The job key
tunnel.allownononeCIDR networks a tunnel through this host may lead to, for example 192.168.1.0/24. The dashboard's own list of named targets is a second bound; a target must pass both. With no entry, or an unreadable one (logged), tunnel is switched off. A tunnel to the host itself, which is what selvara proxy opens for SSH, needs 127.0.0.1/32. The desktop action does not read it. See Tunnels
intervalno30seconds between collection cycles
auto_update.enablednotrueset to false to stop this host updating itself
auto_update.check_intervalno5minutes between update checks
service_namenodetectedthe unit the updater restarts. Leave it out: the agent reads its own unit from /proc/self/cgroup
collectors––ignored. Dashboards before agent 2.0 wrote a full collector list into every host's file. Detection decides now; the agent logs once at start that it is ignoring the list
docker.socketno/var/run/docker.sockwhere the Docker daemon listens
patroni.url, garage.admin_url, garage.admin_token, nginx.status_url, caddy.admin_url, zfs.poolsnodetectedpin an address detection got wrong. GARAGE_ADMIN_TOKEN in the environment overrides the token

The pins in the last row exist for hosts where detection cannot see the service. Prefer the dashboard for these: a value set there wins over the same value in the file, applies without touching the host, and can be set once for a whole cluster. See Agent Settings.

The agent refuses to start without system_id, webhook_url and webhook_secret, and says which one is missing.

Changing what a host allows​

The host decides what the dashboard may do on it, and actions in its configuration file is where it says so. Three ways to set it, none of which needs a hand-edited file:

  • At install. --actions on Linux, -Actions on Windows, a comma list checked against the known actions. It is written into the configuration on a first install and on an update alike, so one command opts a host in:

    curl -sSL https://<your-dashboard>/api/agent/install.sh | sudo bash -s -- \
    --endpoint https://<your-dashboard> --actions patch,script
    & ([scriptblock]::Create((irm https://<your-dashboard>/api/agent/install.ps1))) `
    -Endpoint https://<your-dashboard> -Actions patch,script
  • On an existing host, with the agent's own command, which rewrites only the actions line, keeps every other line and comment, and restarts the service:

    /opt/selvara-agent/selvara-agent configure --actions patch,script
    /opt/selvara-agent/selvara-agent configure --show

    --show prints what the file says, whether the host follows the dashboard instead, and what is allowed now. An empty value (--actions "") writes actions: []: the host is watched only, and the dashboard cannot change that. --no-restart writes the file and leaves the service alone. The command runs the same way from Ansible or a loop over ssh; on Windows it is & "C:\Program Files\Selvara\selvara-agent.exe" configure --actions patch,script.

  • From the dashboard, for hosts whose file has no actions key, when the gateway's operator allows it: Agent Settings.

The job key​

A host that was installed by Selvara 3.0.0 has job_key from the start. A host that updated itself from 2.x has none. It asks for it: with its next settings request, signed with the host's own secret, the dashboard offers the public key of its gateway. The agent writes it into config.yaml, logs Pinned the dashboard's job key sha256:…, and opens the live link without a restart.

It trusts the key on first use. After that it never replaces it by itself: a different key offered later is refused and logged (Refusing the job key the dashboard offers), so a dashboard that is taken over cannot hand the hosts a key of its own. The trade-off is the first contact: whoever answers the first settings request of a host that has no key could name a key of their own, so install over HTTPS to a dashboard you control.

If the gateway's keys were lost and recreated (see Gateway), every host refuses the new key. On each host, forget the old one and let the agent take the new one:

/opt/selvara-agent/selvara-agent configure --repin-job-key

Besides its reports, an agent that has job_key set keeps one WebSocket open to the dashboard, outbound only, at /api/agent/link on the host of webhook_url (wss:// for https://). Jobs, their output, and terminal and tunnel sessions travel over it as they happen, and the host's page shows whether it is up, since when, which actions the host allows and which job types its agent runs.

Each host has a key pair of its own. On first start the agent creates host-key.pem next to config.yaml and presents the public half once, together with agent_key, to /api/agent/identity. The dashboard records the first key a host presents and refuses a different one later. The link is then authenticated with a short-lived token signed by that key, which no other host can produce. Each token is good for one connection: it carries a single-use id, so a copy taken off the wire cannot be presented again. A host that was rebuilt, or whose host-key.pem was lost, needs Reset host key on its page; see Troubleshooting.

Messages about a job (started, output, finished) are numbered, and the dashboard acknowledges them once it has taken them over. The agent keeps what is not acknowledged and sends it again after a reconnect, so a result is not lost with a link that died while it was being written, and a reconnect after a long break replays at a steady pace rather than in one burst. The first message of every link lists the jobs the host still runs or has yet to report; the dashboard ends a job it holds as running that is not on that list, for example one that died with a reboot of the host, as failed ("the host no longer runs this job").

The link reconnects by itself with growing pauses from one second to a minute, follows HTTPS_PROXY like the reports do, and warns in the log when the host's clock is more than two minutes off the dashboard's. HTTP reports remain the fallback and are unchanged: a host without a link, or with the link down, is still monitored in full (for a managed customer; a not managed customer only has live state); it cannot be acted on until the link returns. With several dashboard instances behind a load balancer the link works through any of them, using Redis.

The agent also keeps jobs-seen.json next to the configuration. It lists the job and session grant ids the host has accepted until they expire, so that a signed job saved by someone cannot run a second time after the agent restarts, whether by a reboot job, an update or a crash. Deleting the file re-opens that window for every envelope that has not yet expired. The agent refuses jobs whose validity window is longer than 24 hours, and clamps a job's own timeout to the same limit.

A host that was moved to another server, or to a new name of the same one, records the new address in a file named server-url next to the binary. On every start that file replaces the scheme and host of webhook_url, and the log says so (Server URL overridden by …). From agent 2.8.0 the start also writes the new address into config.yaml (Wrote … into …), so the old one is gone from the host even if server-url is lost; where config.yaml cannot be written, server-url alone carries the move. To send one host elsewhere, re-run the installer against that server. See Moving to a new server.

Check that it works​

On the host:

systemctl status selvara-agent
journalctl -u selvara-agent -f
/opt/selvara-agent/selvara-agent -version

A healthy start logs the version, the host id, the webhook URL and the interval, then Agent started successfully. After that the log is quiet by design: it carries changes only — a new detection result, an applied settings revision, a collector that started or stopped failing, an unreachable webhook.

In the dashboard, the host turns online within a cycle or two and its Details tab lists the detected services, the state of every collector, and the agent's version against the one being rolled out. The Hosts list marks an agent that is behind.

If the unit is running but the host stays offline, the problem is between the agent and the webhook: the URL in config.yaml, the secret (it must be the one the dashboard wrote into the file, see below), or a proxy in front of the dashboard answering with something other than 2xx. The log line for a rejected report carries the status and body the dashboard answered with. More in Troubleshooting.

What the agent needs to see​

The unit runs the agent as root and puts no sandbox around it, the way the Windows agent runs as SYSTEM. That is not incidental: fail2ban's socket, WireGuard, HAProxy's stats socket, the certificate files under /etc/letsencrypt, the journal, every user's home directory and everything a job does to the host (a patch run, a script, SSH certificates, a terminal) need the full rights of root. A sandbox that withheld them kept breaking those actions (apt could not drop privileges, /var/lib/apt and /etc/ssh were read-only, /root was hidden) and was worked around so often that it protected little. The unit is therefore only what keeps a service running: User=root, Restart=always, and the journal for logging.

What limits the agent is not the unit:

  • every job and terminal session arrives signed, and the agent checks the signature against the job key pinned in config.yaml, the host, the expiry and that it has not run before;
  • the host decides which actions it allows in its own config.yaml (Agent Settings), and the fixed list of job types is all the agent runs;
  • every job, session and tunnel lands in the audit log.

A host installed by an earlier release has a unit with a sandbox. The agent removes it itself, see Upgrading.

Beyond the host's own files it talks to local service endpoints — the Docker socket, Patroni's REST API, etcd, PgBouncer, PostgreSQL, Garage's admin API, Traefik's metrics page, Caddy's admin API, CrowdSec's Local API — on loopback or on the host's own addresses. Whatever you firewall between the agent and a service on the same host, the collector for that service will not work.

If you run the agent under something other than this unit, give the process group membership for every socket it must read (docker, fail2ban's socket group, and so on). Collectors whose input it cannot read will report an error rather than fail the whole agent.

Updating an existing installation​

Run the same command without --api-key:

curl -sSL https://<your-dashboard>/api/agent/install.sh | sudo bash -s -- \
--endpoint https://<your-dashboard>

The binary is replaced, the configuration is kept. In normal operation you do not need this: agents update themselves. See Agent Rollout.

Uninstalling​

After Remove agent on the dashboard (see Hosts and Access Entries) the installed agent is turned away: its own secret and the instance's no longer prove the host. Uninstall it on the machine as below; until then it keeps trying every report interval and writes nothing.

curl -sSL https://<your-dashboard>/api/agent/install.sh | sudo bash -s -- --uninstall

This disables and stops the unit, removes /etc/systemd/system/selvara-agent.service, reloads systemd and deletes /opt/selvara-agent including the configuration. By hand it is the same four steps:

systemctl disable --now selvara-agent
rm /etc/systemd/system/selvara-agent.service
systemctl daemon-reload
rm -rf /opt/selvara-agent

The host stays registered in the dashboard with all its history until you delete it there. It will go offline, and unless you silence or delete it, that is an alert. A host that is going away for good should be deleted in the dashboard as well; a host going down for maintenance belongs in a Maintenance Window.

Alpine Linux​

Alpine runs OpenRC and a minimal userland, and the installer supports it. It has neither bash nor sudo, so the command differs: run it as root, and let the command install the two prerequisites first. It is the Linux command from above: the part before curl installs bash and curl when apk exists, and sudo is left out because Alpine's user is root.

The installer recognises OpenRC by rc-service, rc-update and openrc-run. What is different on Alpine:

Alpine
Install path/opt/selvara-agent, as on systemd hosts
Service/etc/init.d/selvara-agent, supervised by supervise-daemon: the agent is restarted ten seconds after it exits, without limit. A self-update restarts the agent in place under the same supervisor
Start at bootrc-update add selvara-agent default, done by the installer. The service waits for the network
Log/var/log/selvara-agent.log, rotated at 8 MB with three old files kept: there is no journal
Run asplain root, as on systemd hosts

Checking on it:

rc-service selvara-agent status
tail -f /var/log/selvara-agent.log
rc-service selvara-agent restart

Running the command again updates the agent and keeps its configuration. install.sh --uninstall stops the service, removes it from the default runlevel, deletes /etc/init.d/selvara-agent, the log files and /opt/selvara-agent. The agent needs OpenRC 0.21 or newer for supervise-daemon, which every Alpine release since 3.8 has.

Synology DSM 6​

DSM 7 runs systemd, so the agent installs there exactly as described above. DSM 6 predates systemd on Synology and uses upstart. The same install.sh command, with the same key, recognises it by /etc.defaults/VERSION and initctl.

What is different on DSM 6:

DSM 6
Install path/volume1/@selvara-agent (the first data volume). DSM rewrites its small host partition on updates; the volume keeps the agent, and the @ keeps the directory out of the shares.
Servicethe upstart job /etc/init/selvara-agent.conf, with respawn
Start at boot/usr/local/etc/rc.d/selvara-agent.sh, which DSM runs once the volumes are mounted. If a DSM update removed the upstart job, it puts it back from upstart.conf next to the agent.
Log/volume1/@selvara-agent/agent.log, rotated at 8 MB with three old files kept: there is no journal
Run asplain root, as on systemd hosts

Checking on it:

initctl status selvara-agent
tail -f /volume1/@selvara-agent/agent.log
initctl restart selvara-agent

The agent reports its platform as Synology DSM with the version and update, for example 6.2.4-25556 Update 8. It updates itself like on any other host, restarting in place; if that fails, it exits and the job's respawn starts the new binary. Agents before 2.11.2 could not restart after an update on DSM 6 and have to be brought to the current version once with the install command, see Agent Rollout. Uninstalling is the same install.sh --uninstall; it removes the job, the boot script and the directory on the volume.

What DSM 6 does not have, the agent does without: the journal (so no SSH or sudo login events), timedatectl and apt. Software RAID health is read from /proc/mdstat as on any Linux host, see Agent Collectors.

After a major DSM update, check that the agent came back. If the update removed the boot script as well, run the install command again with --endpoint only; the configuration on the volume is kept.

Enrollment tokens​

An enrollment token lets a host create its own host. Use it where creating every host by hand and carrying its key to the host is impractical: a disk image, a script that rolls out a whole office. The token belongs to one customer, and every host that presents it becomes a host of that customer. A host that is already known to the customer as a host without an agent gets its agent in place, when exactly one such host answers to the hostname the installer reports (by name or hostname, or by an address together with a name): the host keeps its name, access entries, notes, tags and folder, and the enrollment is recorded as having adopted it. Any other host creates a new host; a host that should keep a host that already has an agent is installed with that host's install key instead.

Creating a token​

Open the customer, then the Enrollment tab (administrators and managers). Create token asks for:

FieldMeaning
Nametells the tokens apart in the list and in the audit log
Valid for7, 30, 90 or 365 days; a token always ends
Maximum hostsoptional; how many hosts may enroll before the token is used up
Require approvalenrolled hosts wait for an operator, see Approval

The token value is shown once, together with the install command for Linux and for Windows with the token filled in. Only a hash is stored, so a lost value cannot be shown again: revoke the token and create another. The list shows each token's state (active, expired, revoked, used up), how many hosts enrolled with it, and Revoke for an active one. Revoking stops further enrollments at once and leaves the hosts that already enrolled in place.

A leaked token can only add hosts to its customer until it expires or is revoked; it reads nothing. Give each rollout its own short-lived token, and use Maximum hosts where the number of hosts is known.

Installing with a token​

Linux, including Alpine and Synology DSM 6:

[ -x /sbin/apk ] && apk add -q bash curl; curl -sSL https://<your-dashboard>/api/agent/install.sh | $([ "$(id -u)" = 0 ] || echo sudo) bash -s -- --token <token> --endpoint https://<your-dashboard>

Windows, in an elevated PowerShell:

& ([scriptblock]::Create((irm https://<your-dashboard>/api/agent/install.ps1))) -Token <token> -Endpoint https://<your-dashboard>

The installer downloads the agent and runs it once with -enroll, which

  1. creates the host's own key beside the configuration file (host-key.pem),
  2. sends the token, the hostname, what it knows about the host and the public half of the key to /api/agent/enroll,
  3. writes the config.yaml the dashboard answers with, readable only by the owner (on Windows by SYSTEM and the administrators), and exits.

Then the installer starts the service as usual. The file is the one the configuration file describes. Where the instance has a gateway configured (GATEWAY_URL), it also carries its job_key, so the host accepts only jobs the gateway signed; without a gateway there is no such line.

The host is named after the host's hostname. A hostname that is already taken at that customer gets the suffix -2, then -3, and so on; names are compared without regard to case. Rename the host afterwards if you want something else.

Running the same command on a host that already has a configuration keeps the configuration and only updates the binary, and the agent itself refuses to enroll over an existing configuration, so a reinstall cannot create a second host for the same host. To enroll a host again, remove the agent first (see Uninstalling) and delete the old host in the dashboard.

Enrollment is rate limited per address (30 attempts a minute). The agent waits and retries when it is told to slow down, so a whole office enrolling at once drains through the limit. The token is part of the command line while the installer runs, so let it expire soon.

The existing path - create the host first, install with its key - keeps working unchanged, and so do hosts installed that way.

Approval​

With Require approval, a host enrolls and reports like any other, and its host appears with the name and platform it reported, but no job and no session reaches it. The Enrollment tab of the customer lists these hosts under Waiting for approval:

  • Approve lets jobs and sessions reach the host from then on.
  • Reject deletes the host. The agent on the host keeps trying to report until it is removed there.

Use it where the token travels widely, for instance on an image that anybody at the customer can boot, and an operator should look at a host before the dashboard can act on it.

Windows hosts​

On Windows the agent is a service named SelvaraAgent, installed by a PowerShell script that does what install.sh does on Linux. The dashboard serves one Windows binary, 64-bit x86; there is no 32-bit and no ARM build.

On the hostWhy
Windows on 64-bit x86the only Windows build the dashboard serves
PowerShell 5.1, which ships with Windows, or newerthe installer is a PowerShell script
an elevated shellit writes to Program Files and ProgramData and registers a service
outbound HTTPS to the dashboardreports, settings and update checks all go outward from the host

Installing​

The install command needs the key and the dashboard's address, and iex cannot pass arguments to what it runs, so the script is fetched and called as a script block. In an elevated PowerShell:

& ([scriptblock]::Create((irm https://<your-dashboard>/api/agent/install.ps1))) -ApiKey <key> -Endpoint https://<your-dashboard>

The key is the same key a Linux host uses and comes from the same two places: the dialog that follows a new host, or Settings -> Agents -> Install.

exit inside a script block ends the shell that runs it, so a refused install closes the window and takes its own error message with it. Where that matters - an unattended install, or a first attempt with an argument likely to be wrong - download the script and run the file instead, where exit ends only the script:

irm https://<your-dashboard>/api/agent/install.ps1 -OutFile $env:TEMP\selvara-install.ps1
powershell -ExecutionPolicy Bypass -File $env:TEMP\selvara-install.ps1 -ApiKey <key> -Endpoint https://<your-dashboard>

The execution policy is what the second line works around: a script file is subject to it and is refused outright on a default Windows Server, while a script block built from a string never was.

What the installer does​

  1. Checks the ground. Refuses outside an elevated shell, without -Endpoint, on anything but 64-bit x86, and without -ApiKey unless a configuration file is already there.
  2. Downloads the binary from /api/agent/download?arch=amd64&os=windows to selvara-agent.exe.new and runs it with -version. A binary that does not run is deleted and the install aborts, so a bad download cannot leave the host without a working agent. An os the dashboard has no binary for is answered with 404 rather than the nearest match.
  3. Fetches the configuration from /api/agent/config?key=<key> into C:\ProgramData\Selvara\config.yaml and takes every account but SYSTEM and the local administrators off the file with icacls. That file holds the webhook secret; the restriction is the counterpart of mode 600 on Linux. A fresh configuration also deletes C:\Program Files\Selvara\server-url, as on Linux. Without -ApiKey the step is skipped and the existing files kept.
  4. Swaps the binary in. Stops a running service first - Windows locks the image file of a running process - and moves .new over C:\Program Files\Selvara\selvara-agent.exe.
  5. Registers and starts the service. sc.exe create SelvaraAgent binPath= "<exe> -config <config>" start= auto obj= LocalSystem, then sc.exe failure SelvaraAgent reset= 86400 actions= restart/5000 and sc.exe failureflag SelvaraAgent 1, then starts it and waits for it to report Running. It also registers SelvaraAgent as a source in the Application event log, so the agent's service events arrive there with their text rather than as bare numbers.

The recovery action is not only there for crashes. The agent cannot restart itself: to the service control manager a process that exits on its own looks like a failure, and a process it spawns is not a service. After it has installed an update of itself it exits with a failure code, and this action is what starts the new binary. Without it a host would update itself once and stay down. The failure flag belongs to it: without it Windows runs recovery actions only for a process that dies outright, never for a service that stops and reports a failure code, which is exactly what the agent does after an update.

LocalSystem is needed because the agent replaces its own binary under Program Files when it updates, which nothing below an administrator may write to.

Where everything lives​

PathContents
C:\Program Files\Selvara\selvara-agent.exethe binary
C:\ProgramData\Selvara\config.yamlthe configuration, readable only by SYSTEM and the administrators
C:\ProgramData\Selvara\host-key.pemthe host's own key for the live link, with the same restricted access. It never leaves the host
C:\Program Files\Selvara\server-urlonly on a host that was moved to another server: the server it reports to now, which outranks webhook_url
C:\ProgramData\Selvara\logs\agent.logthe log, rotated at 8 MiB with three generations kept - this is where the output goes that a Linux host writes to the journal
service SelvaraAgent, display name Selvara Agentthe service itself, started automatically at boot

The contents of the configuration file are the same as on Linux; the table under The configuration file above applies unchanged.

Check that it works​

sc query SelvaraAgent
Get-Content C:\ProgramData\Selvara\logs\agent.log -Tail 50 -Wait
Get-EventLog -LogName Application -Source SelvaraAgent -Newest 20
& "C:\Program Files\Selvara\selvara-agent.exe" -version

In the dashboard the host turns online within a cycle or two, exactly as a Linux host does.

To watch a collection cycle directly, run the binary with -foreground: it then runs in the console instead of under the service control manager, which is the quickest way to see what it reports. Stop the service first, or the two report as the same host.

Updating and uninstalling​

Run the same command without -ApiKey to replace the binary and keep the configuration:

& ([scriptblock]::Create((irm https://<your-dashboard>/api/agent/install.ps1))) -Endpoint https://<your-dashboard>
& ([scriptblock]::Create((irm https://<your-dashboard>/api/agent/install.ps1))) -Uninstall

Uninstalling stops and deletes the service and removes both C:\Program Files\Selvara and C:\ProgramData\Selvara, the configuration and its webhook secret with them. By hand it is the same three steps:

Stop-Service SelvaraAgent
sc.exe delete SelvaraAgent
Remove-Item -Recurse -Force "C:\Program Files\Selvara", "C:\ProgramData\Selvara"

The host stays registered in the dashboard with all its history until you delete it there, and it will go offline - which, unless you silence or delete it, is an alert. The same applies as on Linux: see Uninstalling above.

The Windows binary is not signed​

Nothing in the build signs it, so Windows treats it as software from an unknown publisher. SmartScreen warns when someone downloads the .exe from the dashboard and starts it by hand, and Defender or another endpoint product may quarantine it - in which case the service will not start and the log stays empty. Allowing it is a decision for whoever runs the host. Signing would need a code-signing certificate, which this project does not have.