Maintenance
The server runs five cleanup and bookkeeping jobs on a schedule. You control them in /admin/maintenance. This page covers what each job does, how to schedule or run it, and what to do when the scheduler is not available.
Jobs
| Job | What it does | Default schedule (UTC) |
|---|---|---|
| Change-history and housekeeping pruning | Collapses change history older than the retention limit. Also deletes expired sessions, one-time tokens and email codes, billing webhook records older than 90 days, and unused rate-limit counters. | 0 2 * * * (daily, 02:00) |
| Blob garbage collection | Marks blobs that nothing refers to, deletes marked blobs once the grace period has passed, and removes stored files that have no database record once they are older than the grace period. | 0 3 * * * (daily, 03:00) |
| Storage usage snapshots | Records each user's storage use once a day. Snapshots are kept for 396 days. | 5 0 * * * (daily, 00:05) |
| Scheduled subscription downgrades | Moves users to the free tier when a cancelled subscription reaches its end date. See Billing. |
0 1 * * * (daily, 01:00) |
| Expired/stalled account archives | Deletes account export archives 24 hours after they were built, and marks stuck builds as failed. | 30 * * * * (hourly) |
Some jobs are only available when the server has what they need:
- Blob garbage collection needs blob storage to be set up.
- Storage usage snapshots and Scheduled subscription downgrades need at least one tier.
The page marks a job that cannot run as unavailable and disables its Run now button.
Automatic runs
Automatic runs need Deno's cron support. Install or start the CLI with --unstable-cron:
deno install jsr:@civility/cli -Afg --unstable-cron --name=civ
The top of /admin/maintenance says whether the scheduler is available. You cannot turn it on from the panel. If it is not available, see Without the scheduler.
Every job is on by default. The scheduler checks once a minute and uses the settings saved at that moment, so a new schedule applies within a minute, with no restart.
- A job that is still running is not started again.
- Runs that were missed, for example while the server was down, are not made up later.
Change a job's schedule
- Open
/admin/maintenanceand find the job. - Set Policy to Saved override. Built-in defaults goes back to the default schedule, with automatic runs on.
- Tick or clear Enable automatic runs.
- Enter the UTC cron schedule.
- Tick the confirmation box and save.
Schedule format
A schedule has five fields, in UTC: minute, hour, day of month, month, weekday.
| Allowed | Example | Meaning |
|---|---|---|
| A number | 5 |
At 5 |
* |
* |
Every value |
| A range | 1-5 |
1 through 5 |
| A list | 1,3 |
1 and 3 |
| A step | */15 |
Every 15th value |
- Weekdays are
0to7. Both0and7are Sunday. - If both the day of month and the weekday are restricted, the job runs when either one matches.
- Month names, day names, a seconds field and shortcuts like
@dailyare not supported.
For example, */15 * * * * runs every 15 minutes.
Pause everything
Tick Pause all automatic maintenance and save. No job starts on its schedule while this is on.
- Each job keeps its own on/off setting and schedule. Unpausing brings them back as they were.
- A job that is already running is not stopped.
- Run now still works.
Run a job now
- Find the job in
/admin/maintenance. - Tick the confirmation box and click Run now.
Run now works without the scheduler, while automatic runs are paused, and for a job whose automatic runs are off. It uses the current limits and tiers.
The page waits until the job finishes. A large run can take longer than your reverse proxy's timeout. If the request times out, the job still finishes and records its result. Reload the page and check the status before starting it again.
Reset
Reset all maintenance to the built-in defaults removes every saved schedule and turns off pause-all.
Read a job's status
For each job the page shows:
- whether it can run,
- whether it is running in this server process now,
- its schedule in effect, whether automatic runs are on, and where that setting comes from,
- the last recorded run: status, start and finish time, whether it was manual or scheduled, and its counters.
A run that hit errors is recorded as failed. The page shows a short message; the details are in the server log. A failed run can be started again by hand, or it runs again at its next scheduled time.
If the server crashed during a run, the last run stays recorded as running. That record does not block the next run.
Without the scheduler
If the server runs without --unstable-cron, no job starts on its own. You can still use Run now for every job.
For blob cleanup, you can also run the CLI from cron or a systemd timer on the machine that holds the database:
civ api gc blobs --once --db-path /path/to/civility.db
| Flag | What it does |
|---|---|
--once |
Required. Runs one sweep and exits. |
--grace-days <days> |
Overrides the grace period. Default: the value saved in /admin/limits, then 7. 0 allows deletion right away. |
--user <userId> |
Only sweeps one account's blobs. Skips the check for stored files with no database record. |
--db-path <path> |
The SQLite database file. Required unless civ api start saved a config (its interactive setup); then it defaults to that path. |
--json |
Prints the result as JSON. |
The command uses the storage saved in /admin/storage or, if none is saved, the directory in CIVILITY_BLOB_PATH (default ./.data/blobs, relative to where you run the command). Run it with the same environment and working directory as the server. If that is an S3 bucket, set CIVILITY_AUTH_SECRET in the command's environment so it can read the stored key. It exits with code 1 if the sweep had errors.
Do not run this command while a blob cleanup started from the panel or the scheduler is running. The two do not know about each other, and the command does not appear in the job's status.
One server per database
Run one server process per database. The check that stops a job from running twice only works inside one process.
Audit log
- Saving or resetting settings adds a
maintenance_settings_changedentry. - Each finished run adds a
maintenance_runentry with the job, its result and its counters. The actor is the signed-in admin,admin_tokenfor a script, orsystemfor a scheduled run.