---
url: https://docs.sunlicense.com/guide/self-hosted-services.md
---
# Cloud services for a self-hosted SunLicense

Once your self-hosted SunLicense server (1.4.0 and newer) is [linked to your organization](/guide/self-hosted-link),
you switch each Cloud service on or off on the **SunLicense Cloud** card in your server (**Integrations** ›
**SunLicense Cloud**). This page explains what four of them do in Cloud: store deliveries, offsite backups, backup
validation and uptime alerts. None of them ever blocks a license check, and all of them follow your organization's
[plan](/guide/plans).

> This page covers the Cloud side. The linking itself, license emails and the 3-month Lite offer are on
> [Connect a self-hosted SunLicense](/guide/self-hosted-link).

## Store integrations: deliver to your SunLicense server

Any Cloud [store integration](/integrations/) that gets purchases by webhook can hand them to your server instead of
issuing a Cloud license: **Tebex, Stripe, Ko-fi, Payhip, Lemon Squeezy, WooCommerce and Gumroad**.

1. On your server, switch **Store integrations** on.
2. In the dashboard, open the integration (**Integrations** › your store) and choose **Where purchases go** ›
   **Deliver to your SunLicense server**. The choice only shows up while a linked server relays purchases.
3. Map the store's products to Cloud products and policies as usual (Cloud uses that mapping to say *which* product
   was bought). On your server, map each Cloud product to one of its own products under **Integrations** ›
   **Store relay**.

What happens on a purchase:

* Cloud checks the store's signature or secret exactly as for any other integration. Requests that fail it are
  refused and never reach your server.
* A verified purchase gets **no Cloud license**. Cloud sends your server the product, the buyer's email and name, the
  store's order id and the quantity. Your server finds or creates the customer, issues the license and emails the key.
* What your server answers shows in the integration's **Activity**: *Sent to your SunLicense server*, then
  *Your SunLicense server delivered it* with the key (masked, with a reveal button), or *refused it* with its reason.
* A redelivered webhook or a re-download isn't sent twice. Buying again after a refund is sent again.
* **Refunds** are sent too, and your server revokes the license. **Chargebacks** (a dispute opened) are sent, and
  your server suspends it. Reinstatements and subscription ends aren't part of the relay.
* If your server is offline, Cloud keeps the purchases (up to 7 days) and delivers them in order when it is back.

Good to know:

* **Not for stores that need the key at once:** BuiltByBit and Voxel Shop write the key into the download, SpigotMC's
  plugin asks for it, and itch.io and Envato buyers get it on the redeem page. Those keep issuing Cloud licenses (or
  use your server's own webhook, as BuiltByBit does today).
* **Buyers always get a key:** while your server isn't relaying purchases (the switch is off on your server), sales
  get a Cloud license as before, and the integration says so. Disconnecting your server turns the integration back
  to Cloud licenses.
* **Gumroad, Lemon Squeezy and Payhip with "use the store's key":** the store already emailed the buyer its own key.
  Cloud passes that key to your server so it can use it as the license key.
* Automations don't see relayed purchases: your server decides.

## Offsite backups

After each automatic backup, your server encrypts the zip **on your server** with a recovery code that only you have
(SunLicense shows it once when you switch the service on: keep it, nobody can open your backups without it), and
uploads the encrypted file to Cloud.

| Plan | Largest backup | Kept |
|---|---|---|
| Free | 50 MB | the newest 7 |
| Lite and up | 95 MB | the newest 30 |

* Cloud checks the upload's size and SHA-256 against what your server declared and keeps it only if both match.
* Older backups are deleted automatically once a newer one is in, past the number your plan keeps.
* The **Backups** page on your server lists Cloud's copies under **Cloud copies**: download, decrypt and restore with
  the recovery code. That works on a brand-new install too, which is the point when a server is lost.
* Cloud only ever has the encrypted file. Removing the link keeps the backups (so a new server can restore them);
  deleting your organization deletes them.

## Backup validation (mirror)

Your server sends its products, licenses (status, expiry, limits, machines and IP addresses), customers, blacklists
and API token hashes to Cloud: everything once, then every change about once a minute. Cloud keeps them up to date as
a **mirror**:

* Mirrored products and policies show **Mirrored from your SunLicense server** in the dashboard and are read-only
  there: change them on your server and the next sync brings the change. (Through the API, editing one answers
  `409` with the code `mirrored_record`.)
* Nobody is notified by a sync: no customer emails, Discord posts or webhooks, since your server already did that.
  Cloud also doesn't send expiry reminders for mirrored licenses.
* Revocation stays permanent in Cloud: a key revoked on your server can't be brought back in the mirror.
* Something deleted on your server (a license, a blacklist entry) stays in the mirror; a full sync doesn't remove
  anything.
* **Plans:** the mirror keeps going even when it holds more than your plan allows, and so does validation. The
  dashboard shows that you're over your plan with an upgrade link; you just can't add more in Cloud by hand.
* Remove the link and the mirrored products and policies become normal Cloud ones, with their data.

## Uptime alerts

With **Uptime alerts** on, Cloud watches your server's connection to Cloud. If it stops checking in for 5 minutes,
your organization's Owners get one email: *Your SunLicense server is down*. When it's back, they get one more. At
most one "down" email an hour, however often the server drops.

Optionally, give your server's public address (for example `https://play.example.net` or `http://203.0.113.5:25599`)
and Cloud also checks `GET <address>/api/v2/healthy` every 5 minutes. That catches a server that is running but
unreachable for your plugins (two failed checks in a row count as down). The check:

* calls only that one path, with no query, no login and no redirects, and waits at most 5 seconds;
* goes only to public addresses: an address that resolves to a private, loopback, link-local or cloud metadata
  range isn't checked (only the connection is watched then).

Discord DMs for uptime aren't sent yet; the alerts are email only.

## For developers

The server calls these with its link token (`Authorization: Bearer sll_…`):

| Route | What |
|---|---|
| `POST /api/v1/v1-link/sync?mode=import\|mirror&dryRun=` | The canonical `sunlicense.import` file (gzip allowed, at most 25 MB unpacked). `mode=import` is the same import the admin console runs; `mode=mirror` updates what an earlier sync brought. A change batch says `"partial": true` in its `source`. Answers the import report, including `usage.<limit>.over`. |
| `GET /api/v1/v1-link/products` | `[{id, name, code}]`, for the store-relay mapping. |
| `POST /api/v1/v1-link/backups` | `{sizeBytes, sha256, createdAt, note?}` → `201 {id, uploadPath, uploadHeaders, expiresAt}`; `413 backup_too_large` over the plan's size. |
| `PUT {uploadPath}` | The encrypted bytes, `application/octet-stream`, exactly `sizeBytes`. `400 size_mismatch`, `422 checksum_mismatch`, `409 already_uploaded`. |
| `GET /api/v1/v1-link/backups` · `GET …/{id}/content` · `DELETE …/{id}` | `[{id, sizeBytes, sha256, createdAt, note, state}]` · the bytes · `204`. |

Errors are JSON with a `code` and a `message`.
