Tear down MDK services
Stop ORK, App Node, and Workers cleanly
Overview
MDK registers graceful shutdown handlers automatically when you start services with getOrk(), startWorker(), or startAppNode().
For most deployments, SIGINT (Ctrl+C) triggers a clean teardown with no extra code. This guide covers the three situations where
you need to think about teardown explicitly:
Prerequisites
- Familiarity with the App Node
- MDK installed and a working boot sequence
Automatic teardown with getOrk()
getOrk() registers SIGINT/SIGTERM handlers internally. Any Workers or App Node instances started with opts.ork are
chained into the cleanup sequence automatically — no extra code needed.
const { getOrk, startWorker, startAppNode } = require('@tetherto/mdk')
const { WM_M56S } = require('@tetherto/miner-whatsminer')
const ork = await getOrk()
const { manager } = await startWorker(WM_M56S, { ork })
await startAppNode({ ork, port: 3000, noAuth: true })
// Press Ctrl+C — MDK stops App Node, Worker, then ORK automatically.See getOrk API reference.
Explicit teardown in tests or scripted runs
Short-lived processes — integration tests, one-shot scripts — never receive SIGINT. Call shutdown(ork) directly
to drain the full cleanup chain. Pass the ork object returned by getOrk(); passing a server object stops only the App Node.
const { getOrk, startAppNode, shutdown } = require('@tetherto/mdk')
const ork = await getOrk()
await startAppNode({ ork, noAuth: true })
// … run assertions or perform work …
await shutdown(ork) // stops App Node (chained), then stops ORKCustom signal handling with onShutdown
Use onShutdown when you need to close resources outside an MDK boot object — for example, a database connection or a log buffer.
const { onShutdown } = require('@tetherto/mdk')
onShutdown(async () => {
await db.close()
await logger.flush()
}, { forceMs: 5000 })What just happened
- Automatic chain:
getOrk(),startWorker({ ork }), andstartAppNode({ ork })wire themselves intoork._cleanupso a single signal stops everything in order. - Explicit drain:
shutdown(ork)gives you the same ordered teardown on demand, without a signal. - Custom hooks:
onShutdown(fn)lets you attach cleanup logic outside the MDK object hierarchy.
Next steps
- Full API reference —
@tetherto/mdkREADME - Run the App Node