|
| 1 | +--- |
| 2 | +description: How to deploy ProtoMQ to a remote server and validate it |
| 3 | +--- |
| 4 | + |
| 5 | +# ProtoMQ Remote Deployment Guide |
| 6 | + |
| 7 | +This workflow guides agents on how to deploy the ProtoMQ server to a remote machine, specifically configuring it to run as a systemd service, and how to validate that the deployment is working correctly. |
| 8 | + |
| 9 | +> [!IMPORTANT] |
| 10 | +> Do not assume any prior knowledge of the target environment. |
| 11 | +
|
| 12 | +## Prerequisites |
| 13 | +- Ask the user which SSH connection string to use (e.g., `<ssh_user>@<remote_host>`). |
| 14 | + |
| 15 | +## Deployment Steps |
| 16 | + |
| 17 | +1. **Verify Zig Dependency**: |
| 18 | + Search for the `zig` binary on the remote machine (e.g., `ssh <ssh_target> "which zig"` or `ssh <ssh_target> "find / -name zig 2>/dev/null | grep bin/zig"`). |
| 19 | + If `zig` is not found, **STOP** and tell the user to install Zig on the remote machine before proceeding. |
| 20 | + |
| 21 | +2. **Clone Repository to `/opt/protomq`**: |
| 22 | + Connect via the provided SSH connection and create the `/opt/protomq` directory, ensuring appropriate permissions, then clone the repository there. |
| 23 | + ```bash |
| 24 | + ssh <ssh_target> "sudo mkdir -p /opt/protomq && sudo chown \$USER /opt/protomq && git clone https://github.com/electricalgorithm/protomq /opt/protomq || (cd /opt/protomq && git fetch --all)" |
| 25 | + ``` |
| 26 | + |
| 27 | +3. **Checkout and Pull**: |
| 28 | + Checkout the correct branch and pull the latest changes. |
| 29 | + ```bash |
| 30 | + ssh <ssh_target> "cd /opt/protomq && git checkout <branch_name> && git pull" |
| 31 | + ``` |
| 32 | + |
| 33 | +4. **Build and Install the Application**: |
| 34 | + Build the Zig application on the remote server using the located `zig` binary. Ensure you build with the `-Dadmin_server=true` flag. |
| 35 | + Use the `--prefix /opt/protomq` flag so that it installs the `bin/` files and the systemd service file into `/opt/protomq`. |
| 36 | + ```bash |
| 37 | + ssh <ssh_target> "cd /opt/protomq && sudo <path_to_zig_binary> build -Doptimize=ReleaseSafe -Dadmin_server=true --prefix /opt/protomq" |
| 38 | + ``` |
| 39 | + |
| 40 | +5. **Configure systemd Service**: |
| 41 | + Since the build step installed the service file directly into `/opt/protomq/etc/systemd/system/protomq.service`, simply link it to the system bus, reload, and start it. |
| 42 | + ```bash |
| 43 | + ssh <ssh_target> "sudo ln -sf /opt/protomq/etc/systemd/system/protomq.service /etc/systemd/system/protomq.service && sudo systemctl daemon-reload && sudo systemctl enable --now protomq && sudo systemctl restart protomq" |
| 44 | + ``` |
| 45 | + |
| 46 | +6. **Verify Service Status**: |
| 47 | + Ensure the service is actively running. |
| 48 | + ```bash |
| 49 | + ssh <ssh_target> "systemctl status protomq" |
| 50 | + ``` |
| 51 | + It should say `Active: active (running)`. |
| 52 | + |
| 53 | +## Validation Steps |
| 54 | + |
| 55 | +### 1. Local MQTT Client Validation |
| 56 | +Send a ProtoMQ request from the **host machine** (the machine you are running on) to the remote machine to verify basic functionality using the `protomq-cli` tool. |
| 57 | +First, build the project locally if necessary, then run the CLI (ensure you use the correct IP/host of the remote machine). |
| 58 | +```bash |
| 59 | +./zig-out/bin/protomq-cli connect --host <remote_host> |
| 60 | +``` |
| 61 | +*(You can also use `publish` or `subscribe` commands with `-t <topic>` to test actual message flow).* |
| 62 | + |
| 63 | +### 2. Admin Server Validation |
| 64 | +If the Admin Server is enabled, it will listen on `127.0.0.1:8080` on the remote server. Validate the endpoints directly on the remote machine over SSH using the default authorization token (`admin_secret` or check `ADMIN_TOKEN`): |
| 65 | + |
| 66 | +- **Metrics Endpoint**: |
| 67 | + ```bash |
| 68 | + ssh <ssh_target> 'curl -s -H "Authorization: Bearer admin_secret" http://127.0.0.1:8080/metrics' |
| 69 | + ``` |
| 70 | + *Expected Output*: JSON with connections, messages, schemas, etc. `{"connections":0,"messages_routed":0,"schemas":1,"memory_mb":0}` |
| 71 | + |
| 72 | +- **Schemas Endpoint**: |
| 73 | + ```bash |
| 74 | + ssh <ssh_target> 'curl -s -H "Authorization: Bearer admin_secret" http://127.0.0.1:8080/api/v1/schemas' |
| 75 | + ``` |
| 76 | + *Expected Output*: Topic-schema mapping JSON. e.g., `{"sensor/data":"SensorData"}` |
| 77 | + |
| 78 | +If all responses match expectations and the remote CLI connection succeeds, the server is healthy and successfully deployed. |
0 commit comments