# autopilot — on-airframe install (Jetson Orin Nano Super)

Native systemd deployment per `_docs/02_document/deployment/containerization.md §3`.

## Prerequisites

- Jetson Orin Nano Super 8 GB with JetPack-bundled Ubuntu 22.04 (pinned).
- Network access to the suite-internal `missions` and `ground-station` services.
- `/dev/ttyUSB0` wired to ArduPilot (or `serial:///dev/ttyAMA0` / UDP — adjust `config.toml`).
- ViewPro A40 reachable via RTSP + UDP control.

## Install steps

1. Copy the aarch64 binary from CI artefacts:

   ```bash
   sudo install -m 0755 -o root -g root autopilot /usr/local/bin/autopilot
   ```

2. Create user, state directory, and config tree:

   ```bash
   sudo groupadd --system autopilot
   sudo useradd  --system --gid autopilot --shell /usr/sbin/nologin autopilot
   sudo install -d -o autopilot -g autopilot -m 0750 /var/lib/autopilot
   sudo install -d -o root      -g root      -m 0755 /etc/azaion/autopilot
   sudo install -m 0640 autopilot.prod.toml /etc/azaion/autopilot/config.toml
   sudo install -m 0600 secrets.env         /etc/azaion/autopilot/secrets.env
   ```

3. Install the systemd unit:

   ```bash
   sudo install -m 0644 deploy/systemd/autopilot.service /etc/systemd/system/autopilot.service
   sudo systemctl daemon-reload
   sudo systemctl enable --now autopilot.service
   ```

4. Verify:

   ```bash
   systemctl status autopilot
   curl -s http://127.0.0.1:8080/health | jq
   ```

## Flight-gate contract

The unit's `ExecStartPre` creates `/run/azaion/in-flight`; `ExecStopPost` removes it.
`model-sync.service` (suite-level) honours this marker and defers any model swap
while the autopilot is running. Do not delete the marker manually mid-flight.

## Rollback

The previous binary is left at `/usr/local/bin/autopilot.bak` by the rollout
script. To roll back:

```bash
sudo systemctl stop autopilot
sudo mv /usr/local/bin/autopilot.bak /usr/local/bin/autopilot
sudo systemctl start autopilot
```
