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.
cd C:\laragon\www\es_ldcu
[Net.ServicePointManager]::SecurityProtocol = 3072; irm https://monitoring.example.com/install.ps1 | iexcd /c/laragon/www/es_ldcu
curl -fsSL https://monitoring.example.com/install.sh | bashcd /var/www/es_ldcu
curl -fsSL https://monitoring.example.com/install.sh | sudo bashFrom 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 sendX-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:
- 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
- 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
wwwevery 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.
- 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
- 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 onlyagent.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.
- Windows: stops any running agent first, then registers and starts the scheduled task
- Lists what it changed, then anything
.envstill 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 savestartOrReload 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:
-
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
.execannot be overwritten, so the old one is renamed to.oldand 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.
- Windows: stopping and starting the scheduled task, and ending the agent's process, since
stopping the task alone can leave it running. A running
-
Uninstall it: stops the agent and removes the scheduled task or pm2 app. The script does this itself rather than running the installed agent.
-
Cancel, which changes nothing.
Uninstalling
From the application's folder, as an administrator:
.\sync-agent\sync-agent-windows-x64.exe uninstallsudo ./sync-agent/sync-agent-linux-x64 uninstallThis 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
| Host | Where |
|---|---|
| Windows | sync-agent\agent.log, or open sync-agent\logs.bat |
| Linux | pm2 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.