Skip to main content

Overview

Triggers a graceful shutdown of the LongMem daemon. The daemon will:
  1. Stop accepting new requests
  2. Close the database connection
  3. Clean up the PID file
  4. Exit with status 0

Authentication

Requires Bearer token if authToken is configured in daemon settings.
Authorization: Bearer <your-token>

Request

No request body required.

Response

status
string
Always “shutting_down”

Example

cURL
curl -X POST http://localhost:38741/shutdown
Response
{
  "status": "shutting_down"
}

Use Cases

Programmatic Shutdown

Useful for scripts that manage the daemon lifecycle:
# Stop the daemon via HTTP
curl -X POST http://localhost:38741/shutdown

# Wait for shutdown
sleep 1

# Verify it stopped
longmem status

Integration Cleanup

Some integrations may call this during uninstall or reconfiguration.

Implementation Details

From daemon/server.ts:175-179:
  • Schedules shutdown 100ms after responding
  • Calls the shutdown() function which:
    • Destroys the idle detector
    • Stops the HTTP server
    • Closes the SQLite database
    • Removes the PID file at ~/.longmem/longmem.pid
    • Exits the process

Comparison with CLI

The longmem stop CLI command also calls this endpoint internally (or sends SIGTERM).
MethodUse Case
longmem stopRecommended for users
POST /shutdownFor programmatic control
kill <pid>Emergency stop

Safety Notes

  • Graceful: Completes current request handling before shutting down
  • No data loss: Database is properly closed with all pending writes flushed
  • PID cleanup: Removes stale PID file automatically

Error Responses

Unauthorized

{
  "error": "Unauthorized"
}
Status: 401 (if authToken is configured and missing/incorrect)

Build docs developers (and LLMs) love