fix: proper container lifecycle management to prevent stopped container accumulation
- Name containers (nanoclaw-{group}-{timestamp}) for trackability
- Replace SIGKILL timeout with graceful `container stop` so --rm fires
- Add startup sweep to clean up stopped nanoclaw containers from previous runs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
18
src/index.ts
18
src/index.ts
@@ -832,6 +832,24 @@ function ensureContainerSystemRunning(): void {
|
||||
throw new Error('Apple Container system is required but failed to start');
|
||||
}
|
||||
}
|
||||
|
||||
// Clean up stopped NanoClaw containers from previous runs
|
||||
try {
|
||||
const output = execSync('container ls -a --format {{.Names}}', {
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
encoding: 'utf-8',
|
||||
});
|
||||
const stale = output
|
||||
.split('\n')
|
||||
.map((n) => n.trim())
|
||||
.filter((n) => n.startsWith('nanoclaw-'));
|
||||
if (stale.length > 0) {
|
||||
execSync(`container rm ${stale.join(' ')}`, { stdio: 'pipe' });
|
||||
logger.info({ count: stale.length }, 'Cleaned up stopped containers');
|
||||
}
|
||||
} catch {
|
||||
// No stopped containers or ls/rm not supported
|
||||
}
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
|
||||
Reference in New Issue
Block a user