home-hosted 0.9.3 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/AGENTS.md +27 -21
  2. package/README.md +109 -50
  3. package/dist/cli.js +1289 -172
  4. package/dist/cli.js.map +1 -1
  5. package/docs/DDNS.md +6 -8
  6. package/docs/NOTIFICATIONS.md +6 -0
  7. package/docs/RESTORE_DEMO.md +128 -0
  8. package/docs/REVERSE_PROXY.md +23 -12
  9. package/docs/SERVERS.md +50 -2
  10. package/docs/UI_CREATION.md +7 -7
  11. package/docs/demo/blank-host-restore.sh +192 -0
  12. package/package.json +3 -1
  13. package/uis/stock/dist/assets/de-DI7SS5ZM.js +1 -0
  14. package/uis/stock/dist/assets/es-DDPUYXdi.js +1 -0
  15. package/uis/stock/dist/assets/fr-Dpyr2qTp.js +1 -0
  16. package/uis/stock/dist/assets/index-BtE1z5wU.css +2 -0
  17. package/uis/stock/dist/assets/{index-DVmJrO-t.js → index-JBfH8bkX.js} +10 -8
  18. package/uis/stock/dist/assets/ja-CTGEGJ4n.js +1 -0
  19. package/uis/stock/dist/assets/ko-BSVsEsYY.js +1 -0
  20. package/uis/stock/dist/assets/ru-DvSoJlxX.js +1 -0
  21. package/uis/stock/dist/assets/vi-BTIQb_8V.js +1 -0
  22. package/uis/stock/dist/assets/zh-CN-D2-g9feN.js +1 -0
  23. package/uis/stock/dist/index.html +2 -2
  24. package/uis/stock/dist/ui.json +3 -3
  25. package/uis/stock/dist/assets/de-BVk31frd.js +0 -1
  26. package/uis/stock/dist/assets/es-BLevhZGM.js +0 -1
  27. package/uis/stock/dist/assets/fr-S3YXRHdG.js +0 -1
  28. package/uis/stock/dist/assets/index-GxTN2fYn.css +0 -2
  29. package/uis/stock/dist/assets/ja-BOB-E8_K.js +0 -1
  30. package/uis/stock/dist/assets/ko-Dc88YLt7.js +0 -1
  31. package/uis/stock/dist/assets/ru-BBxCT8MK.js +0 -1
  32. package/uis/stock/dist/assets/vi-CxubJ_Mw.js +0 -1
  33. package/uis/stock/dist/assets/zh-CN-BIvisZnl.js +0 -1
package/docs/DDNS.md CHANGED
@@ -29,14 +29,12 @@ credentials button saves on its own, being a secret. Provider credentials never
29
29
  ```
30
30
 
31
31
  Credentials live in the workspace's `.secrets.json` (0600), keyed by the account `id` and sealed with
32
- AES-256-GCM under `HHOSTED_DDNS_SECRET` — set your own, or the default `hh` only stops a casual
33
- read. The panel logs a warning when it seals credentials under that default, so a copied state
34
- directory is not the first time you hear about it. The block above is the workspace's
35
- `.hh/<workspace>/settings.json`; the credentials are cached
36
- separately in `.secrets.json`, both beside that workspace's `servers.config.json`. The account does
37
- not have to be saved first, and the provider is stored with the entry, so an id that later changes
38
- provider does not silently keep the old secret. Removing an account drops its credentials on the next
39
- save.
32
+ AES-256-GCM under `HHOSTED_DDNS_SECRET` — set your own, or the default `hh` only stops a casual read.
33
+ The panel logs a warning when it seals credentials under that default, so a copied state directory is
34
+ not the first time you hear about it. Both files sit beside that workspace's `servers.config.json`.
35
+ The account does not have to be saved first, and the provider is stored with the entry, so an id that
36
+ later changes provider does not silently keep the old secret. Removing an account drops its
37
+ credentials on the next save.
40
38
 
41
39
  Header fields:
42
40
 
@@ -62,10 +62,16 @@ can be tried before it is saved; `DELETE /api/notifications/destinations/alerts/
62
62
  | a server exceeded its memory limit | `onCrash` | ✅ |
63
63
  | a health check is failing | `onUnhealthy` | ✅ |
64
64
  | a server was force-restarted (health timeout) | `onForcedRestart` | ✅ |
65
+ | a force-restarted server is serving again | `onForcedRestart` | ✅ |
65
66
  | a server recovered | `onRecovered` | ⬜ |
66
67
  | host thresholds breached, and recovered | `onHost` | ✅ |
67
68
  | a dynamic DNS record changed, or a pass failed | `onDdns` | ✅ |
68
69
 
70
+ A **forced restart** is two messages, not one: the restart is announced, and then its outcome is —
71
+ the entry is serving again, or it did not come back (in which case its crash is the second message).
72
+ That is what makes "restarted and fine" distinguishable from "restarted and still broken" without
73
+ reading the panel.
74
+
69
75
  Host thresholds themselves — disk, memory, swap, load, temperature — are **Global settings → Host
70
76
  vitals**. Dynamic DNS carries one message per pass that changed a record, and one per failed pass —
71
77
  see [DDNS.md](./DDNS.md).
@@ -0,0 +1,128 @@
1
+ # Blank-host restore, with a database
2
+
3
+ A worked example: one home stack backed up on one machine, restored onto a machine that starts with
4
+ nothing, and the database read back afterwards.
5
+
6
+ Every command below is real. The whole thing is a script you can run:
7
+ [`blank-host-restore.sh`](./demo/blank-host-restore.sh). It uses throwaway directories under `$TMPDIR` and
8
+ docker containers it removes on exit, so it touches nothing of yours.
9
+
10
+ ```sh
11
+ docs/demo/blank-host-restore.sh
12
+ ```
13
+
14
+ ## The stack
15
+
16
+ One entry: a MongoDB container, with a database dump declared as its data.
17
+
18
+ ```json
19
+ {
20
+ "id": "blog-db",
21
+ "command": "docker",
22
+ "args": ["run", "--rm", "--name", "hh-demo-blog", "-p", "27017:27017", "mongo:7"],
23
+ "port": 27017,
24
+ "backupPaths": ["/srv/blog/dump"]
25
+ }
26
+ ```
27
+
28
+ `backupPaths` is the important field. It names what belongs to this entry **beyond** its config, and
29
+ that is what the archive carries.
30
+
31
+ ## Backing it up
32
+
33
+ ```console
34
+ $ home-hosted backup create
35
+ backup created backup-2026-10-21-04-15-49-881.zip (4 KB)
36
+
37
+ $ home-hosted backup list
38
+ 1 archive in /home/you/.home-hosted/.hh/.backups
39
+ backup-2026-10-21-04-15-49-881.zip 4 KB 2026-10-21 04:15
40
+ ```
41
+
42
+ The archive is a plain zip. Its contents, in full:
43
+
44
+ ```text
45
+ data/
46
+ data/srv-blog-dump/
47
+ data/srv-blog-dump/blog.archive <- the database dump
48
+ global/
49
+ global/secrets.json <- password hash, API token hash
50
+ global/settings.json <- listener, TLS policy, host vitals, proxy
51
+ global/workspaces.json <- the registry: what workspaces exist
52
+ manifest.json <- what release wrote it, and the schema it understood
53
+ workspaces/
54
+ workspaces/default/
55
+ workspaces/default/servers.config.json
56
+ workspaces/default/settings.json
57
+ ```
58
+
59
+ **The dump is the data.** `backupPaths` pointed at a directory holding `mongodump` output, not at
60
+ MongoDB's live data directory. That distinction matters: copying a running database's files can
61
+ capture it torn, which [`README.md`](../README.md#-backups) warns about. A dump is consistent by
62
+ construction.
63
+
64
+ ## Restoring onto a blank host
65
+
66
+ ```console
67
+ $ home-hosted backup restore backup-2026-10-21-04-15-49-881.zip
68
+ Plan for backup-2026-10-21-04-15-49-881.zip — nothing has been written yet
69
+ settings global:settings
70
+ secrets global:secrets
71
+ secrets global:secrets:password
72
+ secrets global:secrets:apiToken
73
+ settings workspace:default:settings
74
+ servers workspace:default:servers
75
+ data workspace:default:data:/srv/blog/dump
76
+
77
+ apply it with `home-hosted backup restore backup-2026-10-21-04-15-49-881.zip --confirm`
78
+ ```
79
+
80
+ The plan comes first, always. A restore writes over live data, so the default is to say what it
81
+ *would* do.
82
+
83
+ ```console
84
+ $ home-hosted backup restore backup-2026-10-21-04-15-49-881.zip --confirm
85
+ restored 7 items from backup-2026-10-21-04-15-49-881.zip
86
+ ```
87
+
88
+ The workspace did not exist on this host. It was created, not skipped: an archive is a whole machine's
89
+ setup, and refusing it because the id is new would make a blank-host restore impossible.
90
+
91
+ Then the entry starts, and the database is read back:
92
+
93
+ ```console
94
+ $ home-hosted start blog-db
95
+ started blog-db
96
+
97
+ $ docker exec hh-demo-blog mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()'
98
+ 0
99
+
100
+ $ docker exec hh-demo-blog mongorestore --archive=/srv/blog/dump/blog.archive --drop
101
+ $ docker exec hh-demo-blog mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()'
102
+ 3
103
+ ```
104
+
105
+ Three documents, on a host that started with nothing.
106
+
107
+ ## What is recovered, and what is not
108
+
109
+ | | |
110
+ | --- | --- |
111
+ | ✅ **Recovered** | Every workspace and its label. Every entry, with its command, args, env, port and policies. Workspace settings: notifications, DDNS, log retention, server defaults. Panel settings: listener, TLS policy, host vitals, backup schedule, proxy routes. Secrets, if you kept them ticked. Declared data paths, including the database dump. |
112
+ | ⚠️ **Recovered, then you must act** | The **password hash and API token hash** travel in `global/secrets.json`, so the restored host has the old machine's credentials. Anyone holding that token still has access. Rotate with `home-hosted set-token --generate`, or exclude those secrets and set them fresh. |
113
+ | ⚠️ **Recovered, but the database needs its own step** | The panel restores **files**, not databases. It puts `blog.archive` back where it was; applying it is `mongorestore` (or `pg_restore`, `.restore`, whatever your engine calls it). That is deliberate: only the engine knows how to apply its own dump. |
114
+ | ❌ **Not recovered** | `HHOSTED_DDNS_SECRET`, the key DDNS credentials are sealed under. It is never archived, so a restored host cannot decrypt them until you set it again. |
115
+ | ❌ **Not recovered** | Anything not in a `backupPaths` directory or the panel's own state: files your entries wrote elsewhere, host packages, `/etc` changes, a reverse proxy outside the panel, cron jobs, the docker images themselves. |
116
+ | ❌ **Not recovered** | The UI you had installed, if it was not the stock one. An official UI is fetched again on the next `up`. |
117
+
118
+ ## Re-running it
119
+
120
+ The script is the reproducible form of everything above:
121
+
122
+ ```sh
123
+ docs/demo/blank-host-restore.sh
124
+ ```
125
+
126
+ It creates two state directories, seeds a real MongoDB, dumps it, backs it up, restores onto the
127
+ blank second host, starts the entry there and asserts the documents came back. It exits non-zero if
128
+ they do not.
@@ -51,9 +51,19 @@ sudo setcap 'cap_net_bind_service=+ep' "$HHOSTED_HOME/.hh/.proxy/bin/hh-caddy"
51
51
  ```
52
52
 
53
53
  Otherwise use **4480/4443** — one click in the page, or `httpPort`/`httpsPort` — and
54
- forward `80 → 4480` and `443 → 4443` on your router. A port already in use is reported with
55
- the pid that holds it, on a first start and on a later change alike, and no listener the
56
- panel did not start is ever killed.
54
+ forward `80 → 4480` and `443 → 4443` on your router.
55
+
56
+ A port a *stranger* holds is refused before anything is started, and no listener the panel did not
57
+ start is ever killed. The ports the engine actually bound are not a conflict: once it is running, a
58
+ settings edit re-applies to the engine already listening on them. A configured port it did **not**
59
+ bind — a `tls: "off"`-only route table binds no HTTPS listener — is not claimed on its behalf.
60
+
61
+ One limit worth knowing: a process carrying a file capability (the `setcap` above) is
62
+ **non-dumpable**, so the panel cannot see the socket it holds — `lsof` and the OS report nothing.
63
+ The panel identifies its own engine from the records it wrote — the ports the applied configuration
64
+ actually listens on, plus the engine's live nanny state — rather than from the process table, and
65
+ says so when it refuses a port it cannot attribute. A stranger holding a capped process's ports is
66
+ reported without a pid.
57
67
 
58
68
  ## Routes
59
69
 
@@ -103,9 +113,11 @@ never gets its certificate.
103
113
 
104
114
  A name the CA will not issue for falls back to the engine's own CA. The route reads
105
115
  **Fell back to Local CA**: the name answers, but with an untrusted certificate, and the
106
- engine keeps trying on its own. certmagic renews once a third of a certificate's lifetime
107
- is left, and the engine's own CA issues 12 hours by default, so the next attempt is about
108
- **8 hours** away — no restart, no downtime.
116
+ engine keeps trying on its own. The next attempt is about **8 hours** away — no restart,
117
+ no downtime. The panel derives that wait from the certificate: certmagic renews once a
118
+ third of the lifetime is left, so two thirds of it is the wait, and the engine's own CA
119
+ issues 12 hours by default. The interval is read, never configured, so there is no knob to
120
+ shorten it.
109
121
 
110
122
  **Force retry certificate** appears on that row only, and asks the CA again immediately.
111
123
  The engine is **not** restarted: a certificate the engine holds cannot be cleared by
@@ -113,17 +125,16 @@ deleting the file or by reloading the configuration, but it *is* released when t
113
125
  leaves the configuration — so the panel reloads without that one route, drops the stored
114
126
  pair while it is out, and puts the route back. Every other route keeps serving; the name
115
127
  itself has no certificate until the CA answers. It is not offered while a name is still
116
- *pending*, because there the engine is already mid-ACME.
128
+ *pending*, because there the engine is already mid-ACME. It is refused when removing that
129
+ route would leave **nothing served** — it is the only working route, or every other one is
130
+ disabled or has no upstream — because a configuration with no listeners takes the site
131
+ dark. Add another working route first.
117
132
 
118
133
  A **removed** route has its stored certificate dropped on the next apply, so adding it
119
134
  back asks the CA instead of serving the old pair. A **disabled** route keeps its
120
135
  certificate: it is still configured, and switching it back on should not cost a new
121
136
  issuance.
122
137
 
123
- The panel derives that wait from the certificate itself: certmagic renews once a third of
124
- the lifetime is left, so two thirds of it is the wait — about 8 hours for the engine's own
125
- 12-hour CA. The interval is read, never configured, so there is no knob to shorten it.
126
-
127
138
  A hostname **no route claims** gets a page saying so, on both ports — not a redirect into
128
139
  a handshake that cannot finish. A visitor with no hostname at all (a bare IP on the HTTPS
129
140
  port) is answered by the engine's own CA under `hh-fallback.invalid`, so the page appears
@@ -218,7 +229,7 @@ rather than adding a 151st record to a zone already at the limit.
218
229
  | Replaceable | Drop any `hh-caddy` build at that path and the panel runs it: it reports *a path configured by hand* and probes no version. Installing or updating is refused while the engine is up — **Stop** it first, because the binary is replaced on disk. |
219
230
  | Runs as | A child of the panel's own nanny, exactly like a `persistent: true` entry. |
220
231
  | Supervised by | The panel. The admin API is opened on the panel side only: a unix socket in a `0700` directory (loopback TCP plus Caddy's origin check on Windows). |
221
- | Reloaded by | `POST /load` — atomic, and the revision that applied is kept on disk so a change can be reverted in one click (the first one has nothing to go back to). A reload onto a port something else holds is refused with that pid before the engine is touched, and the panel keeps reporting the ports the engine is really on. |
232
+ | Reloaded by | `POST /load` — atomic, and the revision that applied is kept on disk so a change can be reverted in one click (the first one has nothing to go back to). A reload onto a port a stranger holds is refused before the engine is touched, naming the pid when the OS will tell it and saying so when it will not, and the panel keeps reporting the ports the engine is really on. |
222
233
  | Stops with | **Stop** in the page, switching the proxy off, or `POST /api/proxy/stop`. It never stops itself, and `down` leaves it serving — the socket facing the internet is not something a panel restart should drop. It is never restarted automatically either: a configuration the engine refuses needs a person, not a retry loop. |
223
234
 
224
235
  Because it runs under a nanny, a panel restart does not drop the socket that faces the
package/docs/SERVERS.md CHANGED
@@ -25,11 +25,39 @@ Pick one in the header; the workspace's server defaults and log retention sit in
25
25
  Relative paths resolve against the directory you ran `home-hosted` from, so a project can keep its
26
26
  servers and its state together.
27
27
 
28
+ ## Presets
29
+
30
+ The add-server panel offers a gallery — Minecraft, Jellyfin, a Node app, a Python file server, Gitea,
31
+ MongoDB, Docker Compose, a chat bot. Picking one **fills the form**; it creates nothing you cannot edit
32
+ afterwards, and no preset is required to add a server.
33
+
34
+ A preset is only a starting point, so two things to check:
35
+
36
+ - **The port is what the panel probes, not always what the program binds.** Node, Python, Gitea and
37
+ MongoDB take the form's port (`{port}`, in `args` or `env`). Three cannot: Minecraft reads
38
+ `server-port` from `server.properties`, Jellyfin reads `network.xml`, and a compose stack publishes
39
+ what its file says — for those the port only moves the probe, so set it to the port the program
40
+ actually uses. The bot has no port at all, so it has no probe.
41
+ - **The working directory matters.** Python's `http.server` serves the working directory; Minecraft
42
+ needs it set to the folder holding `server.jar`. The preset description names what to point it at.
43
+
44
+ ## Orphaned processes
45
+
46
+ A child the panel spawns is detached, so it outlives a hard panel death. The handle is
47
+ `.state/<id>.run.json`, keyed by the id it was started under — so an entry that is **renamed** or
48
+ **removed** while its process is still running leaves that process with no entry to own it. It keeps
49
+ running, holding its port and its resources, and nothing in the panel lists it.
50
+
51
+ **Servers** now shows them: a warning above the list names each id, its pid and when it started, with
52
+ a **Stop it** button. The state file is left alone until the process is actually gone, so a survivor
53
+ of `SIGKILL` is still findable on the next boot. There is no automatic kill — a pid whose identity the
54
+ platform cannot confirm is exactly what the rest of this file refuses to signal on a guess.
55
+
28
56
  ## Field reference
29
57
 
30
58
  | field | what it does |
31
59
  | --- | --- |
32
- | `command`, `args`, `cwd` | what to run, with `{placeholders}` resolved per entry |
60
+ | `command`, `args`, `cwd` | what to run. `{placeholders}` resolve in `args` only (`env`, `dataEnvs`, `backupPaths` and `bootstrap.args` too); `command`, `cwd` and `envFile` are used literally, so `cwd: "~/app"` is not a home directory |
33
61
  | `env`, `dataEnvs`, `envFile` | environment; `dataEnvs` also marks data directories for backups, `envFile` keeps secrets out of the config |
34
62
  | `enabled` | `true` (default) starts it; `false` keeps the entry in the config but refuses to start it, stops it if it is running, and leaves a disabled `persistent` entry unattached at boot |
35
63
  | `port`, `bind` | enables the readiness wait, health checks and the conflict preflight; `local` keeps it on `127.0.0.1` |
@@ -37,7 +65,7 @@ servers and its state together.
37
65
  | `persistent` | run it under its own nanny so it survives the panel — see below |
38
66
  | `health.mode` | `port` (TCP connect) or `http` (path, expected status, expected body — a `HEAD` carries no body, so it is warned about and the body check is skipped) |
39
67
  | `health.http.scheme`, `health.http.allowInvalidCert` | `http` (default) or `https` for a backend that serves TLS itself; the second accepts a self-signed certificate, which is the usual case on a home network. A certificate is verified unless you say otherwise |
40
- | `health.unhealthyThreshold`, `forceRestartAfterMs` | how many failed probes before the card warns, and when to restart anyway |
68
+ | `health.unhealthyThreshold`, `forceRestartAfterMs` | how many failed probes before the card warns, and when to restart anyway — bounded by `restart.maxRetries`, after which the entry is stopped rather than restarted forever, with the reason left on its card |
41
69
  | `restart.*` | backoff: `maxRetries`, `baseDelayMs`, `factor`, `maxDelayMs`, `resetAfterMs` — the spent budget is remembered on disk, so a crash loop cannot outlast `maxRetries` by outliving the panel |
42
70
  | `stop.*` | `signal`, `killGroup`, `graceMs`, and `killPortHolders` to sweep a leftover listener |
43
71
  | `dependsOn` | ids that must be healthy first. `stop-all`/`down` stop dependents before their dependencies; stopping **one** server does not cascade — the log names any dependent it left running |
@@ -91,6 +119,26 @@ Preflight runs before every start, so two servers cannot silently fight over one
91
119
  | `reclaim` | same detection, but it stops that successor and starts a fully supervised process of its own |
92
120
  | `kill` | stops **whatever holds the port** — no ownership test — then starts. The blunt one: see below |
93
121
 
122
+ ### Docker and compose
123
+
124
+ A compose stack is a supervised entry like any other — `command: docker`, `args: ["compose","up"]`,
125
+ `cwd` the directory holding `compose.yml`. The foreground form streams every container's log into
126
+ the entry and a stop takes the stack down. Set `port` to the port the compose file publishes; that
127
+ published port is the health probe.
128
+
129
+ ```json
130
+ { "id": "blog", "command": "docker", "args": ["compose", "up"], "cwd": "./blog", "port": 8080 }
131
+ ```
132
+
133
+ `docker compose up -d` is not an entry: it exits as soon as the containers start, so there is nothing
134
+ left to supervise, and the entry backs off against the stack it just started. Drop the `-d`.
135
+
136
+ A published port belongs to a root-owned `docker-proxy`, so it has no pid this process may signal.
137
+ The panel asks docker instead and names the container. Both ways of freeing a port — the **Free
138
+ port** button (or `free-port`) and `onPortConflict: kill` — then stop that container through docker,
139
+ needing no privileges beyond the socket you already have. Under `block` the entry is reported and the
140
+ message names the stack to stop.
141
+
94
142
  ### When a program restarts itself
95
143
 
96
144
  Some programs restart themselves by launching a new detached process and exiting — a plugin doing an
@@ -64,9 +64,9 @@ With those set, `home-hosted ui-update` lists the releases carrying your `asset`
64
64
  you pick; `--old` lists older ones. A version bump in your own repo is enough — nothing about the
65
65
  panel is involved.
66
66
 
67
- > **Official UIs** (`repo: NamesMT/home-hosted`) are paired with the panel instead: the panel knows
68
- > its own release, so `home-hosted ui-update` installs the matching tag without asking, and
69
- > upgrading the panel re-pairs the UI on the next `up`.
67
+ > **Official UIs** (`repo: NamesMT/home-hosted`) follow the panel instead: the panel knows its own
68
+ > release, so `home-hosted ui-update` installs the matching version without asking, and upgrading the
69
+ > panel switches the UI to the matching version on the next `up`.
70
70
 
71
71
  Nothing is built on the server side: whatever you upload is served as-is, so ship plain
72
72
  HTML/JS/CSS or the output of your own Vite/Next/Astro build with relative asset paths.
@@ -142,12 +142,12 @@ naming one that does not exist is a `404 UNKNOWN_WORKSPACE`, never a silent fall
142
142
  | `POST` / `DELETE /api/settings/ui` | install or revert a UI — what Global settings calls |
143
143
  | `POST` / `DELETE /api/settings/tls` | upload or clear a PEM pair |
144
144
  | `GET` / `PATCH /api/proxy`, `POST /api/proxy/{engine,start,stop,apply,revert}`, `PUT` / `DELETE /api/proxy/certificates/:id`, `POST /api/proxy/routes/:id/retry-certificate` | the panel-wide reverse proxy: engine, route table, its uploaded PEM pairs. Its live view also rides in the state frame as an optional `proxy` — read it defensively |
145
- | `GET` / `POST /api/backups`, `/api/backups/restore`, `/api/backups/:name/download` | archives; entries are global (`global:settings`, `global:secrets`, `global:tls`) or per workspace, whose leaves are `workspace:<id>:settings`, `:servers`, `:secrets` plus `data:<path>`; a create/restore body `include` selects them |
145
+ | `GET` / `POST /api/backups`, `/api/backups/restore`, `/api/backups/:name/download` | archives; entries are global (`global:settings`, `global:secrets`, `global:tls`) or per workspace, whose leaves are `workspace:<id>:{settings,servers,secrets,data:<path>}`; a create/restore body `include` selects them |
146
146
  | `POST` / `DELETE /api/auth/password` | set the panel password, or clear it and disable auth. `POST` needs the current one unless none is set; an empty password is refused |
147
- | `POST` / `DELETE /api/notifications/token`, `/api/notifications/test`, `/detect-chats` | Telegram, per workspace |
147
+ | `PUT` / `DELETE /api/notifications/destinations/:id/token`, `POST /api/notifications/destinations/:id/{test,detect-chats}`, `POST /api/notifications/test-webhook` | one destination's bot credential and a test send, per workspace |
148
148
  | `GET` / `PUT /api/ddns`, `PUT` / `DELETE /api/ddns/credentials/:id`, `POST /api/ddns/check` | dynamic DNS, per workspace: the policy plus live per-record state, one account's sealed credentials (write-only — the view exposes ids and whether each is set, never the values), and a pass run now |
149
149
  | `POST /api/auth/login`, `GET /api/auth/session`, `POST /api/auth/logout` | the session |
150
- | `GET /healthz` | liveness — **no session**, and `503` when an autostart server has crashed or a running one is failing its health check |
150
+ | `GET /healthz` | liveness — **no session**, and `503` when a server has crashed, when the panel stopped one because it could not serve, or while a running one is failing its health check |
151
151
  | `GET /api/metrics` | Prometheus text (needs a session) |
152
152
 
153
153
  `GET /healthz` and `GET /openapi/*` are the only unauthenticated reads; the SPA shell itself is
@@ -268,7 +268,7 @@ A pending-edit summary pays for itself: show how many fields changed, and let th
268
268
 
269
269
  The repo's own UIs are Vite apps: `uis/<name>/` holds `index.html`, `src/`, a `tsconfig.json`
270
270
  (copied from a sibling) and a two-line `vite.config.ts` calling `createUiConfig` from
271
- `uis/vite.shared.ts`, with `public/ui.json` naming it. Yours does not have to be Vite — only the
271
+ `uis/vite.shared.ts`, with `uis/<name>/public/ui.json` naming it. Yours does not have to be Vite — only the
272
272
  output matters.
273
273
 
274
274
  ```sh
@@ -0,0 +1,192 @@
1
+ #!/usr/bin/env bash
2
+ #
3
+ # A blank-host backup/restore demo, with a real database.
4
+ #
5
+ # Two hosts, one after the other, in throwaway directories:
6
+ #
7
+ # 1. host A — a panel with one entry (a MongoDB container) and some data in it
8
+ # 2. take a backup: `home-hosted backup create`
9
+ # 3. host B — a *blank* home, nothing configured
10
+ # 4. restore into it: `home-hosted backup restore <name> --confirm`
11
+ # 5. start the entry on host B and read the database back
12
+ #
13
+ # Every step is a real command against a real panel and a real container. Nothing is faked, and the
14
+ # script fails loudly rather than continuing on a wrong assumption.
15
+ #
16
+ # Usage: docs/demo/blank-host-restore.sh
17
+ # Requires: docker, pnpm, node 24. Runs entirely under $TMPDIR; touches nothing of yours.
18
+
19
+ set -euo pipefail
20
+
21
+ REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
22
+ WORK="$(mktemp -d "${TMPDIR:-/tmp}/hh-demo-XXXXXX")"
23
+ HOST_A="$WORK/host-a"
24
+ HOST_B="$WORK/host-b"
25
+ DATA="$WORK/blog"
26
+ MONGO="hh-demo-mongo"
27
+ APP="hh-demo-blog"
28
+ PANEL_A=6470
29
+ PANEL_B=6471
30
+ CLI=(pnpm --dir "$REPO" exec tsx src/cli.ts)
31
+
32
+ say() { printf '\n\033[1m%s\033[0m\n' "$*"; }
33
+ note() { printf ' %s\n' "$*"; }
34
+
35
+ cleanup() {
36
+ docker rm -f "$APP" "$MONGO" >/dev/null 2>&1 || true
37
+ HHOSTED_HOME="$HOST_A" "${CLI[@]}" down >/dev/null 2>&1 || true
38
+ HHOSTED_HOME="$HOST_B" "${CLI[@]}" down >/dev/null 2>&1 || true
39
+ rm -rf "$WORK"
40
+ }
41
+ trap cleanup EXIT
42
+
43
+ # ---------------------------------------------------------------------------- host A
44
+
45
+ say "Host A: a blank machine with one stack"
46
+
47
+ mkdir -p "$DATA/dump"
48
+ docker run -d --name "$MONGO" -p 27017:27017 mongo:7 >/dev/null
49
+ note "started $MONGO"
50
+
51
+ # Wait for it to accept connections, rather than sleeping and hoping.
52
+ for _ in $(seq 1 60); do
53
+ docker exec "$MONGO" mongosh --quiet --eval 'db.runCommand({ping:1}).ok' >/dev/null 2>&1 && break
54
+ sleep 1
55
+ done
56
+
57
+ docker exec "$MONGO" mongosh --quiet --eval '
58
+ db.getSiblingDB("blog").posts.insertMany([
59
+ { title: "How I stopped using tmux", slug: "tmux" },
60
+ { title: "One panel for six services", slug: "panel" },
61
+ { title: "Backups that survive a dead disk", slug: "backups" },
62
+ ])
63
+ ' >/dev/null
64
+ note "seeded 3 documents into blog.posts"
65
+
66
+ # The dump, not the live files. A running database's data directory copied file by file can be torn,
67
+ # which the README warns about; `mongodump --archive` is the consistent artifact.
68
+ docker exec "$MONGO" mongodump --db blog --archive=/tmp/blog.archive --quiet
69
+ docker cp "$MONGO:/tmp/blog.archive" "$DATA/dump/blog.archive" >/dev/null
70
+ note "dumped the database to $DATA/dump/blog.archive"
71
+
72
+ mkdir -p "$HOST_A"
73
+ HHOSTED_HOME="$HOST_A" "${CLI[@]}" up --port "$PANEL_A" --no-autostart >/dev/null
74
+ TOKEN_A="$(HHOSTED_HOME="$HOST_A" "${CLI[@]}" set-token --generate | grep -oE 'hh_[A-Za-z0-9_-]+' | head -1)"
75
+ note "panel on :$PANEL_A"
76
+
77
+ # An entry whose `backupPaths` names the dump, and whose port lets the panel health-check it.
78
+ curl -fsS -o /dev/null -X POST \
79
+ -H "Authorization: Bearer $TOKEN_A" -H 'content-type: application/json' \
80
+ -d "{
81
+ \"id\": \"blog-db\",
82
+ \"command\": \"docker\",
83
+ \"args\": [\"run\", \"--rm\", \"--name\", \"$APP\", \"-p\", \"27017:27017\", \"mongo:7\"],
84
+ \"port\": 27017,
85
+ \"backupPaths\": [\"$DATA/dump\"]
86
+ }" \
87
+ "http://127.0.0.1:$PANEL_A/api/servers?workspace=default"
88
+ note "declared the entry: docker run mongo:7, backupPaths = $DATA/dump"
89
+
90
+ # ---------------------------------------------------------------------------- the backup
91
+
92
+ say "Taking a backup"
93
+
94
+ HHOSTED_HOME="$HOST_A" "${CLI[@]}" backup create
95
+ ARCHIVE="$(HHOSTED_HOME="$HOST_A" "${CLI[@]}" backup list --json | node -e '
96
+ let raw = ""
97
+ process.stdin.on("data", chunk => raw += chunk)
98
+ process.stdin.on("end", () => {
99
+ const view = JSON.parse(raw)
100
+ process.stdout.write(view.files[0].name)
101
+ })
102
+ ')"
103
+ note "archive: $ARCHIVE"
104
+
105
+ # Host A is gone, which is the premise of the whole exercise. Its container has to go with it, or
106
+ # the port is still held when host B tries to start the restored entry.
107
+ docker rm -f "$MONGO" >/dev/null 2>&1 || true
108
+ note "stopped host A's container (host A is gone, after all)"
109
+
110
+ say "What is in the archive"
111
+ node -e '
112
+ const { execFileSync } = require("node:child_process")
113
+ const out = execFileSync("unzip", ["-Z1", process.argv[1]], { encoding: "utf8" })
114
+ for (const line of out.trim().split("\n")) console.log(" " + line)
115
+ ' "$HOST_A/.hh/.backups/$ARCHIVE" 2>/dev/null || note "(unzip not installed; skipping the listing)"
116
+
117
+ # ---------------------------------------------------------------------------- host B
118
+
119
+ say "Host B: a blank machine, nothing configured"
120
+
121
+ mkdir -p "$HOST_B"
122
+ if [ -e "$HOST_B/.hh/workspaces.json" ]; then
123
+ note "unexpected: host B is not blank"; exit 1
124
+ fi
125
+ note "$HOST_B has no .hh at all"
126
+
127
+ HHOSTED_HOME="$HOST_B" "${CLI[@]}" up --port "$PANEL_B" --no-autostart >/dev/null
128
+ # A token to authorise the upload. The archive carries host A's `secrets.json`, so this one is
129
+ # replaced by the restore and a fresh one is minted afterwards.
130
+ SETUP_TOKEN="$(HHOSTED_HOME="$HOST_B" "${CLI[@]}" set-token --generate | grep -oE 'hh_[A-Za-z0-9_-]+' | head -1)"
131
+ note "panel on :$PANEL_B"
132
+
133
+ # The archive travels as a file, which is the whole point: one artifact to move.
134
+ cp "$HOST_A/.hh/.backups/$ARCHIVE" "$WORK/$ARCHIVE"
135
+
136
+ # The plan first, always: a restore writes over live data, so the default is to say what it would do.
137
+ say "Planning the restore (nothing is written yet)"
138
+ mkdir -p "$HOST_B/.hh/.backups"
139
+ cp "$WORK/$ARCHIVE" "$HOST_B/.hh/.backups/$ARCHIVE"
140
+ HHOSTED_HOME="$HOST_B" "${CLI[@]}" backup restore "$ARCHIVE"
141
+ rm -f "$HOST_B/.hh/.backups/$ARCHIVE"
142
+ curl -fsS -o /dev/null -X POST \
143
+ -H "Authorization: Bearer $SETUP_TOKEN" \
144
+ -F "file=@$WORK/$ARCHIVE" \
145
+ "http://127.0.0.1:$PANEL_B/api/backups/restore?confirm=true"
146
+ note "uploaded and restored onto the blank host"
147
+
148
+ # The archive carried host A's `global/secrets.json`, so host B now has host A's password hash and
149
+ # API token hash — the archive is the whole machine's identity, not just its entries. The README
150
+ # warns about exactly this. A real move should either accept that or rotate afterwards; this demo
151
+ # rotates, because a token that travelled in an archive is a token in a file.
152
+ TOKEN_B="$(HHOSTED_HOME="$HOST_B" "${CLI[@]}" set-token --generate | grep -oE 'hh_[A-Za-z0-9_-]+' | head -1)"
153
+ note "rotated host B's API token (the archive had brought host A's)"
154
+
155
+ say "What host B now has"
156
+ HHOSTED_HOME="$HOST_B" "${CLI[@]}" status
157
+
158
+ # ---------------------------------------------------------------------------- prove it serves
159
+
160
+ say "Starting the restored entry"
161
+
162
+ START_ANSWER="$(curl -sS -X POST -H "Authorization: Bearer $TOKEN_B" \
163
+ "http://127.0.0.1:$PANEL_B/api/servers/blog-db/start?workspace=default")"
164
+ node -e 'const a = JSON.parse(process.argv[1]); if (a.ok !== true) { console.error(" start refused: " + (a.message ?? a.error ?? JSON.stringify(a))); process.exit(1) }' "$START_ANSWER"
165
+
166
+ for _ in $(seq 1 60); do
167
+ docker exec "$APP" mongosh --quiet --eval 'db.runCommand({ping:1}).ok' >/dev/null 2>&1 && break
168
+ sleep 1
169
+ done
170
+
171
+ say "Reading the database on the restored host"
172
+
173
+ docker cp "$DATA/dump/blog.archive" "$APP:/tmp/blog.archive"
174
+ BEFORE="$(docker exec "$APP" mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()')"
175
+ note "documents in blog.posts before applying the dump: $BEFORE — the container is fresh, so it is empty"
176
+
177
+ # The dump is the data; restoring the *panel* brought back the entry and the dump beside it. Applying
178
+ # the dump is the database's own step, and this is it.
179
+ docker exec "$APP" mongorestore --archive=/tmp/blog.archive --quiet --drop
180
+ COUNT="$(docker exec "$APP" mongosh --quiet --eval 'db.getSiblingDB("blog").posts.countDocuments()')"
181
+ TITLES="$(docker exec "$APP" mongosh --quiet --eval 'db.getSiblingDB("blog").posts.find({}, {title:1, _id:0}).toArray().map(p => p.title).join(" | ")')"
182
+
183
+ say "Result"
184
+ note "blog.posts documents: $COUNT"
185
+ note "titles: $TITLES"
186
+
187
+ if [ "$COUNT" = "3" ]; then
188
+ printf '\n\033[32mrestored: the same 3 documents, on a host that started blank\033[0m\n'
189
+ else
190
+ printf '\n\033[31mFAILED: expected 3 documents, got %s\033[0m\n' "$COUNT"
191
+ exit 1
192
+ fi
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "home-hosted",
3
3
  "type": "module",
4
- "version": "0.9.3",
4
+ "version": "0.9.5",
5
5
  "packageManager": "pnpm@12.5.1",
6
6
  "description": "Self-hosted control panel that keeps your home-server processes alive: supervision, restarts, port conflicts, logs — and a UI you can replace.",
7
7
  "author": "NamesMT <dangquoctrung123@gmail.com>",
@@ -59,11 +59,13 @@
59
59
  "dist",
60
60
  "docs/DDNS.md",
61
61
  "docs/NOTIFICATIONS.md",
62
+ "docs/RESTORE_DEMO.md",
62
63
  "docs/REVERSE_PROXY.md",
63
64
  "docs/SERVERS.md",
64
65
  "docs/UI_CREATION.md",
65
66
  "docs/branding/logo.svg",
66
67
  "docs/branding/social-preview.png",
68
+ "docs/demo/blank-host-restore.sh",
67
69
  "uis/stock/dist"
68
70
  ],
69
71
  "engines": {