# Running and status

> Check, start and stop the X-Edge Vision services on the device, and find their logs.

Two services make up the appliance. Run these commands on the device, over `ssh`.

| | Backend (and the detection pipeline it supervises) | Video relay |
|---|---|---|
| Is it running | `systemctl is-active edgevision-api` | `docker ps --filter name=edge-relay` |
| Start | `sudo systemctl start edgevision-api` | `docker start edge-relay` |
| Stop | `sudo systemctl stop edgevision-api` | `docker stop edge-relay` |
| Log | `~/backend.log` | `docker logs edge-relay` |

The backend log is a file in the login's home folder. `journalctl -u edgevision-api`
shows nothing, by design.

## Two behaviours that look like faults but are not

- **A stopped relay stays stopped.** Its restart policy brings it back after a
  reboot or a Docker restart, but deliberately not after an explicit
  `docker stop`. In the same way, the backend being *enabled* means it starts at
  boot, not that it is running now.
- **The backend can run with no video.** The two are independent. A missing
  relay shows as camera tiles with no picture, not as a failed service. When the
  relay is back, the backend restores its camera paths at its next check, which
  runs every 30 seconds by default, with no restart.

## Check a device

```bash
# The appliance answers.
curl -s -o /dev/null -w '%{http_code}\n' http://<address>:5080/health/live      # 200

# It starts again after a reboot.
ssh <login>@<address> 'systemctl is-enabled edgevision-api'                      # enabled

# Which version it runs.
ssh <login>@<address> 'cat ~/edgevision/VERSION'
```

Then open the console and watch **Live View**: the boxes should sit on the
objects, and the reported rate should hold.

## Where things are

| Path on the device | What it is |
|---|---|
| `~/edgevision/EdgeVision.Api` | The backend program |
| `~/edgevision/wwwroot/` | The operator console |
| `~/edgevision/edgevision.db` | The database (SQLite) |
| `~/edgevision/appliance.json` | Seeds the first camera and the built-in models |
| `~/edgevision/models/` | Uploaded models and the engines built from them |
| `~/edgevision/install.log` | Everything the installer printed |
| `~/backend.log` | The backend log |

After the first start, the database is the authority for cameras and models,
not `appliance.json`.

## Back up the database

The installer snapshots the database before each update and keeps three. To take
one by hand, stop the service first. A copy taken while the service holds the
file is not consistent.

```bash
ssh <login>@<address> 'sudo systemctl stop edgevision-api && cd ~/edgevision \
  && cp -p edgevision.db backups/manual-$(date -u +%Y%m%dT%H%M%SZ).db \
  && sudo systemctl start edgevision-api'
```
