# sa-doctor — SA1 read-only checkup :id=top

------

> _Doc Ver:_ 1.0  
_App Ver:_ 2.6.6.53  
_Date:_ 09/10/2026

------

`sa-doctor` checks whether **SA1 2.x** (`sa-di` + `sa-web` + `csdfu`) is healthy. Read-only: it does not change config, start/stop processes, or upgrade. Binary: `/var/sa/bin/sa-doctor`. **Not** a systemd / `sa1-supervise` daemon.

**Not** SA2 `sa_doctor` (underscore). Do not point SA2’s doctor at SA1.

Remote use is HTTP only (80 / 8080 / 81). **Do not** open TCP 7090 from a laptop (the command port is loopback-only). On-box runs may probe `127.0.0.1:7090`.

Hub: [Ops tools](ops.md). HTTP JSON: [API §8](api.md). Field ops: [Start, check, upgrade](operate.md). Also [sa-cli](sa-cli.md), [sa-mcp](sa-mcp.md).

The binary `--help` text is **Chinese**. English below matches it one-for-one. On the device:

```bash
sa-doctor --help
sa-doctor -h
sa-doctor help
sa-doctor --version
```

------

## 1. CLI help (same coverage as `sa-doctor --help`) :id=cli

Go’s flag package accepts both `-url` and `--url`. This program has no extra mode switch.

```
sa-doctor 2.6.6.29 — SA1 read-only checkup (not SA2 sa_doctor)

Check SA1 2.x (sa-di + sa-web) on the device or from a laptop. Read-only:
no config writes, no process start/stop, no upgrade. Remote is HTTP only
(80 / 8080 / 81). Do not open TCP 7090 from a laptop (loopback only).

Usage:
  sa-doctor [flags]
  sa-doctor help
  sa-doctor --help
  sa-doctor --version

Flags:
  --url URL          sa-web address: host, host:port, or http://host[:port]
                     If omitted, probe 127.0.0.1 ports 80 → 8080 → 81
                     (each candidate uses --timeout). An explicit port skips the probe.
                     Env: SA1_URL
  --user NAME        Web user for GET /api/ops/health (default admin). Env: SA1_USER
  --password PASS    Web password. Prefer env SA1_PASSWORD (not visible in ps)
  --local            Also probe this machine's /proc and 127.0.0.1:7090 even if
                     --url is remote. Already implied when --url is empty or loopback
  --timeout DURATION HTTP timeout (default 8s), e.g. 5s, 12s
  --json             JSON report on stdout (default is a text table)
  -h, --help         this text
  -v, --version      print version and exit

Environment:
  SA1_URL        same as --url
  SA1_USER       same as --user
  SA1_PASSWORD   same as --password
  SA1_INIT       on-box only: override init detection (systemd / sysv / supervise)

On-box checks (device, or --local, or loopback URL):
  sa_di_count    /proc comm/cmdline sa-di; must be exactly 1
  sa_web_count   exactly 1 sa-web
  csdfu_count    exactly 1 csdfu (warn if missing)
  mutex          no sa_daq / sa_daq_c / sa_web / sa_broker / sa_run / sa_control
  di_idn         TCP 127.0.0.1:7090 *IDN? non-empty
  di_ver         *VER? (skip if unreachable)
  login_local    /login on 80 or 8080 or 81, HTTP < 400
  init           systemd / sysv (/etc/init.d/sa1) / supervise

Remote / public HTTP (this process):
  http           probe sa-web (GET /api/info)
  info           public GET /api/info (app name, IDN, dotted 2.6.x)
  product        warn if version is not 2.6.x
  login_http     /login opens on that URL
  login          --user/--password (without a password, skip full remote health)
  ops_health     GET /api/ops/health after login (warn if old sa-web lacks it)

Checks absorbed from GET /api/ops/health (password set and URL is not loopback):
  product        sa1 + dotted version; warn if not 2.6.x
  sa_di_count    exactly 1 sa-di on the device
  sa_web_count   exactly 1 sa-web on the device
  csdfu_count    exactly 1 csdfu (warn if missing)
  mutex          no sa_daq / sa_daq_c / sa_web / sa_broker / sa_run / sa_control
  login_http     device /login on 80 or 8080 or 81
  di_idn         device *IDN? non-empty
  di_os          device TCP 7094 spectrum port (unreachable → warn, not fail)
  version_match  version.json VersionN vs *VER?; lag → warn, restart sa-di
  disk           data dir: ≥95% fail, ≥90% warn
  init           systemd / sysv / supervise; unknown → warn

No password: remote does info + /login only; on-box still probes /proc and 7090.
Password and non-loopback target: drop local probes; the report is health checks.
Password and loopback (or --local): local checks + one ops_health=fetched row;
remote checks are not expanded.
sa-doctor --json is always the slim report {ok,product,worst,target,checks},
not the full health JSON. Use sa-cli health for the full document.

Exit codes:
  0   all pass or skip (worst=pass)
  1   at least one fail (worst=fail)
  2   no fail but warn (e.g. *VER? lags version.json → systemctl restart sa-di)
  3   usage error

JSON (--json) fields:
  ok        true if no fail (still true when worst=warn; look at worst)
  product   "sa1"
  worst     pass | warn | fail
  target    HTTP root actually used
  checks    [{id, ok, status, detail}]  status is pass|warn|fail|skip

Binary: package /var/sa/bin/sa-doctor (not systemd / sa1-supervise).
After install/upgrade /usr/local/bin/sa-doctor points at it.
Handbook: web/help/zh-cn/sa-doctor.md    web/help/sa-doctor.md
Hub: web/help/zh-cn/ops.md

Not:
  SA2 sa_doctor / sa_tui / sa_mcp / sax
  not a replacement for sa1-upgrader / cspkg
  does not open LAN 7090, does not write config
```

------

## 2. How to run :id=run

On the device:

```bash
sa-doctor
sa-doctor --json
```

From a laptop (Web credentials required for full `GET /api/ops/health`):

```bash
export SA1_URL=http://192.168.3.6
export SA1_USER=admin
export SA1_PASSWORD=…          # do not commit; factory often temppwd — change it
sa-doctor --json
sa-doctor --url http://192.168.3.6:8080 --user admin --password "$SA1_PASSWORD"
```

`--local` on a laptop probes the **laptop**, not the device.

------

## 3. Text vs JSON :id=out

Default text table:

```
PASS  sa_di_count      1
FAIL  mutex            sa_daq=1
ok=false  worst=fail  product=sa1
```

`--json`: `{ok, product, worst, target, checks[]}`. `ok` stays true when there are only warnings; use `worst` and the exit code (fail→1, warn-only→2).

Full health JSON (process counts, disk bytes, `version.match`, …) is `GET /api/ops/health` via `sa-cli health`.

------

## 4. vs sa-cli health :id=vs-cli

| | sa-doctor | sa-cli health |
|--|-----------|----------------|
| On-box `/proc`, 7090 | yes on device | HTTP only |
| Output | slim checks | full `/api/ops/health` JSON |
| No password | still on-box | exit 3 except `info` |

------

## 5. Typical results :id=tips

| Result | Action |
|--------|--------|
| `mutex` fail | Stop SA2: `sa_daq` / `sa_daq_c` / `sa_web` / `sa_broker` / `sa_run` / `sa_control`. One stack at a time. |
| `sa_di_count` ≠ 1 | Do not `killall -9`. systemd: `sudo systemctl start sa-di`. BusyBox: `sudo /etc/init.d/sa1 start`. |
| `version_match` warn | New `version.json`, old `*VER?`: `sudo systemctl restart sa-di`. |
| `di_os` warn | Local 7094 down; spectrum UI may fail; checkup is not a fail. |
| `disk` fail | Data dir ≥95%. Clean `/var/sa/data`; do not wipe `persist/conf`. |
| `ops_health` warn “upgrade sa-web” | Field sa-web has no `/api/ops/health` yet. |
| Exit 3 | Usage / unknown flag. |

Older packages without `sa-doctor`: [Start, check, upgrade](operate.md).

------

### [Top](#top)
