Repository navigation
Idle container shutdown (Epic 2/6) Idle sweep - #544
Open
cmyers-mieweb wants to merge 3 commits into
Open
cmyers-mieweb wants to merge 3 commits into
cmyers-mieweb wants to merge 3 commits into
Conversation
Add stoppedReason (idle|manual), stoppedAt, stoppedBy and startedAt to Containers with markStopped()/markStarted() helpers. The create and reconfigure jobs call markStarted() after starting, clearing stop state and giving the idle rule a start grace. DummyApi.clusterResources reports a container as stopped when stoppedAt is set so dev sweeps behave like production. Refs #527 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- resources/idle-shutdown: idle rule (max of createdAt, startedAt and service lastAccessedAt vs effective idleTime; 0 = exempt), sweep over running containers via one status snapshot per node, stopLxc with a 60s wait, failures logged and skipped, per-owner results for #528. - bin/idle-sweep.js: run a sweep, --dry-run, or --enqueue a Job unless a sweep is already pending/running. - contrib/systemd/idle-sweep.{service,timer}: hourly enqueue; installed and enabled by the package scripts. - idle_shutdown_enabled setting (default off): the sweep only reports until an admin enables it; switch on the Settings page. - parseArgs accepts bare --flags. Closes #527 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Refs #527 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cmyers-mieweb
requested review from
runleveldev
and
a balanced review from Copilot
December 4, 2026 16:08
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
A non-admin account named system can access every sweep report, while grouping, stale-state, and enqueue concurrency flaws risk lost reporting and incorrect or duplicate container stops.
4 open issues
What changed in this PR
Implements the idle-shutdown sweep on top of the existing idleTime resource, with shutdown disabled by default for staged rollout.
Changes:
- Adds hourly sweep jobs, dry-run reporting and per-owner results.
- Records stop reasons and start times, with a fresh grace period after manager starts.
- Adds the admin setting, packaging, tests and documentation.
| File | Description |
|---|---|
mie-opensource-landing/docs/developers/release-pipeline.md |
Documents packaged sweep units. |
mie-opensource-landing/docs/developers/idle-shutdown.md |
Describes sweep behavior and lifecycle state. |
mie-opensource-landing/docs/developers/database-schema.md |
Documents stop/start fields. |
mie-opensource-landing/docs/admins/settings.md |
Explains the rollout setting. |
mie-opensource-landing/docs/admins/core-concepts/containers.md |
Adds sweep operation commands. |
create-a-container/utils/dummy-api.js |
Reflects persisted stop state. |
create-a-container/utils/cli.js |
Parses bare command-line flags. |
create-a-container/utils/__tests__/cli.test.js |
Tests flag parsing. |
create-a-container/routers/api/v1/settings.js |
Exposes the shutdown setting. |
create-a-container/routers/api/v1/__tests__/settings-idle-shutdown.api.test.js |
Tests safe setting defaults and updates. |
create-a-container/resources/idle-shutdown/service.js |
Implements idle evaluation, stopping and enqueueing. |
create-a-container/resources/idle-shutdown/repository.js |
Provides sweep database queries. |
create-a-container/resources/idle-shutdown/README.md |
Maps the sweep module. |
create-a-container/resources/idle-shutdown/__tests__/sweep.test.js |
Tests sweep execution and bookkeeping. |
create-a-container/resources/idle-shutdown/__tests__/service.test.js |
Tests idle thresholds and grace periods. |
create-a-container/README.md |
Documents timer packaging. |
create-a-container/openapi.v1.yaml |
Defines the shutdown setting contract. |
create-a-container/models/setting.js |
Adds the enabled-state lookup. |
create-a-container/models/container.js |
Adds stop/start fields and helpers. |
create-a-container/migrations/20261203000000-add-container-stop-state.js |
Migrates lifecycle audit columns. |
create-a-container/Makefile |
Installs sweep systemd units. |
create-a-container/contrib/systemd/idle-sweep.timer |
Schedules hourly sweeps. |
create-a-container/contrib/systemd/idle-sweep.service |
Enqueues sweep jobs. |
create-a-container/contrib/preremove.sh |
Disables the timer on removal. |
create-a-container/contrib/postinstall.sh |
Enables the timer after installation. |
create-a-container/client/src/pages/settings/SettingsPage.tsx |
Adds the shutdown toggle. |
create-a-container/client/src/lib/types.ts |
Types the shutdown setting. |
create-a-container/bin/reconfigure-container.js |
Records starts after reconfiguration. |
create-a-container/bin/idle-sweep.js |
Adds sweep CLI and report output. |
create-a-container/bin/create-container.js |
Records the initial container start. |
Review effort: Balanced
| if (active) return { enqueued: false, job: active }; | ||
| const job = await repo.createJob({ | ||
| command: dryRun ? `${SWEEP_COMMAND} --dry-run` : SWEEP_COMMAND, | ||
| createdBy: STOPPED_BY, |
| } | ||
|
|
||
| function groupByOwner(entries) { | ||
| const byOwner = {}; |
Comment on lines
+113
to
+114
| try { | ||
| await stopContainer(container, clients); |
Comment on lines
+130
to
+132
| const active = await repo.findActiveJobByCommandPrefix(SWEEP_COMMAND); | ||
| if (active) return { enqueued: false, job: active }; | ||
| const job = await repo.createJob({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Issue: #527
Adds an hourly sweep that stops containers with no proxied traffic for longer than their effective
idleTime, records why/when/who stopped them, and ships off by default so admins can review dry-run reports before enabling it.Idle sweep
resources/idle-shutdown: idle rule =now - max(createdAt, startedAt, service.lastAccessedAt…) > idleTime;idleTime = 0is exempt.clusterResources('lxc')snapshot per node).stopLxcwith a 60 s wait; failures are logged and skipped, and any failure marks the job failed.bin/idle-sweep.jssupports--dry-runand--enqueue(inserts a Job unless a sweep is already pending/running). Output lists STOPPED / WOULD STOP / FAILED / SKIPPED with reasons, plus per-owner lines;sweep()returnsbyOwnerfor Idle shutdown: notify owners of stopped containers (digest + unsubscribe) #528.Stop/start state
Containerscolumns:stoppedReason(idle|manual),stoppedAt,stoppedBy,startedAt.Container.markStopped()/markStarted(); the create and reconfigure jobs callmarkStarted(), which clears stop state and gives every start a fullidleTimewindow.Rollout safety
idle_shutdown_enabledsetting (Settings → Idle shutdown), default off: every sweep is report-only until an admin enables it.Packaging
contrib/systemd/idle-sweep.{service,timer}(hourly), installed by the Makefile and enabled/disabled by the post-install/pre-remove scripts.Testing
--enqueue(dedupes) → job-runner runs the sweep → containers recorded asidle/system→ next sweep skips them as offline.Screenshots