selfapi-v2 / docs /persistence.md
akashyadav758
Add HOWTOUSE.md and docs/ for fast, error-free new setup
8ea09fa
|
Raw
History Blame Contribute Delete
1.83 kB
# Persistence β€” staying logged in
The Chrome profile (cookies/logins) lives in `/home/chrome/data`. How it survives a restart
depends on where you run.
## Hugging Face β†’ Neon Postgres (required)
HF free `cpu-basic` Spaces have **no persistent disk** β€” the filesystem is wiped on every
restart/rebuild. So the profile is snapshotted to an external Postgres DB by the `profilesync` tool:
- **Boot:** `profilesync restore` pulls the last snapshot.
- **Every 5 min + on shutdown:** `profilesync backup` saves it.
- Stored as one row: `chrome_profile(id, updated_at, data bytea)` (auto-created).
- **Gated on `DATABASE_URL`.** Not set β†’ restore/backup skipped β†’ logins lost on restart.
### Setup
1. Free DB at [neon.tech](https://neon.tech) β†’ copy the connection string
(`postgresql://user:pass@host.neon.tech/db?sslmode=require`).
2. HF Space β†’ Settings β†’ Variables and secrets β†’ secret **`DATABASE_URL`** = that string.
3. Saving auto-restarts the Space. **Log in once** after that β†’ first backup within 5 min β†’ survives
all future restarts.
### Verify a backup landed
```sql
SELECT id, updated_at, octet_length(data) FROM chrome_profile;
```
A row with non-zero size = persisted. (Profile stays small β€” junk/cache is stripped each boot;
typically 0.5–2 MB. Neon free = 512 MB, so it's ~0.1% used.)
## Self-host Docker β†’ named volume (no DB needed)
`docker-compose.yml` mounts the `chrome-profile` named volume at `/home/chrome/data`, so logins
survive `docker compose down/up` and reboots automatically. **`DATABASE_URL` is not needed** for
Docker. To wipe the profile: `docker compose down -v`.
> Important: setting a new secret on HF forces a restart. If you log in *before* `DATABASE_URL` is
> set, that login is lost on the restart the secret triggers β€” log in again afterward.