diff options
| author | Paul Buetow <paul@buetow.org> | 2026-04-14 23:05:59 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-04-14 23:05:59 +0300 |
| commit | 6b743ff9eb937b35595ac74453e24ca3e19c4a18 (patch) | |
| tree | bf5a6766b5373650f946f76a72823fc18a37e6ae | |
| parent | 8af25fc5dd15ab106e048f99606d979b6567ba91 (diff) | |
Remove PLAN.md, update README and upload client for FreeBSD, clarify install/test steps
| -rw-r--r-- | PLAN.md | 14 | ||||
| -rw-r--r-- | README.md | 39 | ||||
| -rwxr-xr-x | contrib/goprecords-upload-client.sh | 6 |
3 files changed, 39 insertions, 20 deletions
diff --git a/PLAN.md b/PLAN.md deleted file mode 100644 index bacd8a8..0000000 --- a/PLAN.md +++ /dev/null @@ -1,14 +0,0 @@ -# mage goprecords a microservice - -* Should run as a daemon, e.g. `goprecords --daemon` -* Should have a configurable database path to a local directory -* Local database is simply the input dir of the current goprecords CLI tool -* Introduce an API to generate the available output formats, also include a HTML output format. All should be configurable using a query-parameter to the API. -* Introduce an API to let clients upload new uprecords. see example database at /home/paul/git/uprecords/stats so every client should be able to upload 5 different files, HOSTNAME.{txt,cur.txt,records,os.txt,cpuinfo.txt}. -* Use token-based authentication (e.g. API keys or JWT) for upload endpoints. -* Upload should simply work using a curl CLI command given the auth is provided in the HTTP header. -* have a way to manage different auth keys per client. not via API but via a local database and a `goprecords --create-client-key HOSTNAME`. - - - - @@ -242,7 +242,7 @@ Re-running **`--create-client-key`** for the same hostname **replaces** the prev **2. On the client**, keep the token in a root-owned or user-private file (for example mode **`600`**) and use **`curl`** with **`Authorization: Bearer`** as in the examples above. Set the base URL to your daemon (plain HTTP behind the pod or **`https://`** behind ingress). -**3. Source files** — Typical uptimed locations: **`/var/spool/uptimed/records`** (many Linux distributions), **`/usr/local/var/uptimed/records`** (macOS/Homebrew), **`/var/db/uptimed/records`** (some BSDs). Use **`uprecords`** from the **`uptimed`** package to regenerate **`txt`** and **`cur.txt`**-equivalent content when you upload those kinds. **`os.txt`** and **`cpuinfo.txt`** are often **`/etc/os-release`** and **`/proc/cpuinfo`** on Linux. +**3. Source files** — Typical uptimed locations: **`/var/spool/uptimed/records`** (many Linux distributions and **FreeBSD** **`pkg`** installs), **`/usr/local/var/uptimed/records`** (macOS/Homebrew), **`/var/db/uptimed/records`** (some other BSD layouts). The upload client checks those paths in that order. Use **`uprecords`** from the **`uptimed`** package to regenerate **`txt`** and **`cur.txt`**-equivalent content when you upload those kinds. **`os.txt`** and **`cpuinfo.txt`** are often **`/etc/os-release`** and **`/proc/cpuinfo`** on Linux. **4. Automate (optional)** — A **`oneshot`** systemd service can call a small script that **`PUT`**s each present file; a **`systemd.timer`** (for example **`OnCalendar=hourly`**) triggers it. For a **user** timer, enable lingering if uploads should run while no graphical session is active: @@ -256,15 +256,27 @@ If there are **no** keys in the auth database, uploads are accepted without **`A Use this when the machine is **not** deployed from a Rex/Ansible repo. The reference script is **`contrib/goprecords-upload-client.sh`** (POSIX **`sh`**: Linux, FreeBSD, OpenBSD). +**SSH vs upload name:** **`GOPRECORDS_HOST`** must stay the **short** stats name (**`f0`**, **`pi2`**). For **SSH**, use a real host — e.g. **`ssh -p 22 paul@f0.lan.buetow.org`** or **`paul@192.168.1.130`**, not **`f0.lan`** (incomplete / invalid). OpenBSD frontends may use **port 2** in Rex; **f0–f3** and **Pis** use **port 22**. + +**Privilege on FreeBSD:** many hosts (e.g. **f0–f3**) ship **`doas`** and no **`sudo`**. Use **`doas`** for install, writing the token, and one-off test runs below; on Linux (Pis) use **`sudo`**. + **On each host** 1. Install **`curl`** and **`uptimed`**, and ensure **`uptimed`** is running. 2. Install the script (path is up to you; **`755`**, owned by **`root`**): + **Linux** + ```bash sudo install -m 755 contrib/goprecords-upload-client.sh /usr/local/bin/goprecords-upload-client.sh ``` + **FreeBSD** + + ```bash + doas install -m 755 contrib/goprecords-upload-client.sh /usr/local/bin/goprecords-upload-client.sh + ``` + 3. Create a token on the goprecords server (hostname must match **`GOPRECORDS_HOST`** exactly, e.g. **`f0`**, **`pi2`**): ```bash @@ -274,19 +286,29 @@ Use this when the machine is **not** deployed from a Rex/Ansible repo. The refer 4. Save the printed secret once as **`root`**, mode **`600`**: + **Linux** + ```bash umask 077 sudo sh -c 'cat > /etc/goprecords-upload.token' sudo chmod 600 /etc/goprecords-upload.token ``` + **FreeBSD** + + ```bash + umask 077 + doas sh -c 'cat > /etc/goprecords-upload.token' + doas chmod 600 /etc/goprecords-upload.token + ``` + 5. **FreeBSD — hourly cron** (example for **`f0`**; use **`/etc/crontab`** or **`root`**’s crontab). **`curl`** must be on **`PATH`** for cron (often **`/usr/local/bin`**): ```cron PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin 0 * * * * root /usr/bin/env GOPRECORDS_HOST=f0 /usr/local/bin/goprecords-upload-client.sh ``` - Repeat for **`f1`**, **`f2`**, **`f4`**, … with the matching **`GOPRECORDS_HOST`**. + Repeat for **`f1`**, **`f2`**, **`f3`**, … with the matching **`GOPRECORDS_HOST`**. 6. **Linux (systemd) — hourly timer** (example for **`pi0`**). **`/etc/goprecords-upload.env`** (mode **`644`**, root): @@ -309,12 +331,15 @@ Use this when the machine is **not** deployed from a Rex/Ansible repo. The refer **`/etc/systemd/system/goprecords-upload.timer`**: + **`OnActiveSec`** runs once soon after **`enable --now`**, so the first upload is not delayed until the next full hour (otherwise run **`systemctl start goprecords-upload.service`** manually once). + ```ini [Unit] Description=Hourly uptimed upload to goprecords [Timer] OnCalendar=hourly + OnActiveSec=90s RandomizedDelaySec=300 Persistent=true @@ -341,8 +366,16 @@ Use this when the machine is **not** deployed from a Rex/Ansible repo. The refer **Test one run** +**Linux** + +```bash +sudo env GOPRECORDS_HOST=f0 /usr/local/bin/goprecords-upload-client.sh +``` + +**FreeBSD** + ```bash -sudo GOPRECORDS_HOST=f0 /usr/local/bin/goprecords-upload-client.sh +doas env GOPRECORDS_HOST=f0 /usr/local/bin/goprecords-upload-client.sh ``` ## Test diff --git a/contrib/goprecords-upload-client.sh b/contrib/goprecords-upload-client.sh index b287410..e235c51 100755 --- a/contrib/goprecords-upload-client.sh +++ b/contrib/goprecords-upload-client.sh @@ -24,10 +24,10 @@ upload() { } records_path= -if test -f /var/db/uptimed/records; then - records_path=/var/db/uptimed/records -elif test -f /var/spool/uptimed/records; then +if test -f /var/spool/uptimed/records; then records_path=/var/spool/uptimed/records +elif test -f /var/db/uptimed/records; then + records_path=/var/db/uptimed/records elif test -f /usr/local/var/uptimed/records; then records_path=/usr/local/var/uptimed/records else |
