Relay

One-command install

Install, upgrade or remove an agent from the school's machine with one command.

Do this on the school's machine, from the application's folder (the one with its .env). It downloads the agent from the monitoring server and starts it, set to start again at boot.

Windows: PowerShell as Administrator
cd C:\laragon\www\es_ldcu
[Net.ServicePointManager]::SecurityProtocol = 3072; irm https://monitoring.example.com/install.ps1 | iex
Windows: Git Bash
cd /c/laragon/www/es_ldcu
curl -fsSL https://monitoring.example.com/install.sh | bash
Linux
cd /var/www/es_ldcu
curl -fsSL https://monitoring.example.com/install.sh | sudo bash

From Git Bash, the installer opens a PowerShell window as Administrator, in the same folder, and carries on there. Accept the Windows prompt that asks to allow it.

Use your monitoring server's address. The dashboard shows both commands ready to copy, under Download agent on the school's page.

Before you start

  • You have the school's code and sync token.
  • The monitoring server is reached over HTTPS. Over plain HTTP the scripts refuse to run, except from localhost: the token would cross the network readable, and anyone on it could swap the agent. Behind a reverse proxy that ends TLS, have it send X-Forwarded-Proto: https.
  • The monitoring server has the current agent release published. If it doesn't, the installer says so. See Publishing a release.

What it does

It needs the school code and sync token to download the agent. When the application's .env already has SCHOOL_CODE and SYNC_TOKEN it uses those, and otherwise it asks. A wrong pair stops it there. Then it:

  1. Downloads the agent for this machine and checks its SHA-256 checksum:
    • Windows 10 1809+ or Server 2019+: the Windows binary
    • older Windows, such as Server 2016: the Node.js build, which needs Node.js 22 or later installed system-wide
    • Linux x64: the Linux binary
  2. Puts the agent in sync-agent/.
    • Windows: first locks that folder down. Administrators become its owner and, with SYSTEM, the only accounts that can change it; everyone else can read and run it. Under Laragon's www every signed-in user can usually change the application's files, and the scheduled task runs what is in this folder, so otherwise anyone could swap it for their own program.
    • Linux: everything is written as the user who owns the application folder, not as root. With sudo, the script switches to that user first. As root it would be writing into a folder another user controls, where a planted symlink could aim root's writes elsewhere.
  3. Sets it up to run:
    • Windows: stops any running agent first, then registers and starts the scheduled task sync-agent-<folder>, which runs at boot as LOCAL SERVICE, a low-privilege account, rather than SYSTEM. It can read the application's folder and write only agent.log.
    • Linux: writes sync-agent/ecosystem.config.cjs. It doesn't run pm2: it doesn't start, stop or save anything there, and doesn't set pm2 to start at boot. A running agent keeps running the old version until pm2 restarts it.
  4. Lists what it changed, then anything .env still needs, and on Linux the pm2 commands to start the agent.

That is all. It changes nothing in the database or in .env.

Starting it on Linux

As the user who owns the application folder, with pm2 installed (npm install -g pm2), once .env has its settings:

cd /var/www/es_ldcu/sync-agent
pm2 startOrReload ecosystem.config.cjs
pm2 save

startOrReload also restarts an agent that's already running, so it's the same command after an upgrade. To have pm2 bring it back after a reboot, run pm2 startup once for that user and run the command it prints with sudo.

After installing

The agent reads its settings from the application's .env and waits until they are there. The installer prints the lines missing from it: the server URL, school code and token it was given, the side (SYNC_SOURCE: LOCAL on the school's own database, ONLINE on the online one), and a database login if .env has none. Add them, and on Windows the agent starts syncing within a minute. On Linux, add them before starting it with pm2.

The database also needs the outbox table and capture triggers. Get the setup SQL from the school's Sync tables page in the dashboard and run it as a user with the TRIGGER privilege. Run it again whenever tables are added or changed. To check everything without syncing, run sync-agent --check from the application's folder (see Command line).

On Windows the installer also warns if MySQL is not a service that starts automatically, since then nothing syncs after a reboot until someone opens Laragon.

Upgrading

Run the same command again. When it finds an agent in the folder, it says which build it is (the binary or the Node.js sync-agent-node.mjs) and whether it is running, with its process IDs, then asks what to do:

  1. Update it to the latest version, the default. It keeps the build that is installed, even where a fresh install would pick the other. The code and token come from .env, so there is nothing to type. The file is swapped without stopping the agent, which carries on with the old version, and once the update succeeds the installer prints the command that restarts it:

    • Windows: stopping and starting the scheduled task, and ending the agent's process, since stopping the task alone can leave it running. A running .exe cannot be overwritten, so the old one is renamed to .old and removed on the next update.
    • Linux: pm2 startOrReload ecosystem.config.cjs, as the folder's owner.

    If it was not started by this installer's task or pm2 app, the command stops it by process ID, and you start it again the way you normally do.

  2. Uninstall it: stops the agent and removes the scheduled task or pm2 app. The script does this itself rather than running the installed agent.

  3. Cancel, which changes nothing.

Uninstalling

From the application's folder, as an administrator:

Windows
.\sync-agent\sync-agent-windows-x64.exe uninstall
Linux
sudo ./sync-agent/sync-agent-linux-x64 uninstall

This stops the agent and stops it starting at boot. On Linux it removes the pm2 app and saves pm2's list, and leaves ecosystem.config.cjs in place. The sync-agent/ folder, the settings you added to .env and the capture triggers are left in place.

Logs

HostWhere
Windowssync-agent\agent.log, or open sync-agent\logs.bat
Linuxpm2 logs sync-agent-<folder>, as the folder's owner

Already downloaded the agent?

You can run the installer without the one-liner. From the application's folder, run sync-agent install: on Windows as an administrator, on Linux as the folder's owner, such as sudo -u www-data ./sync-agent/sync-agent-linux-x64 install. It then can't fill in the server URL, code and token for you in the lines it prints for .env.

On this page