Lifecycle & Hook Pipeline
Nanokit provides a robust lifecycle management system that allows you to orchestrate complex application starts and stops using Hooks.
The Execution Pipeline
When a service is launched or updated, Nanokit follows a strict sequence of events. This ensures that dependencies are satisfied, migrations are run, and the environment is stabilized before the service becomes public.
1. Pre-Start (Host)
Executed on the host machine (or build agent) before any container is created.
- Use Case: Checking local requirements, generating assets, or validating config files.
2. Orchestration (Provider)
The Infrastructure Provider creates and starts the container/instance.
3. Pre-Start (Container)
Executed inside the container before the main start command.
- Use Case: Database migrations (
prisma migrate), warming up caches, or waiting for sibling services.
4. Provisioning (Internal)
The provisioning.install command runs. This is handled by the Atomic Provisioning Engine to ensure shared volumes are initialized correctly.
5. Health Check
Nanokit waits for the service to report a “Healthy” status.
6. Post-Start
Executed after the service is healthy and routing traffic.
- Use Case: Sending deployment notifications or updating external status pages.
Provisioning & Shared Volumes
One of Nanokit’s most powerful features is how it handles shared resources in distributed environments.
Atomic Provisioning
The provisioning.install command uses a Lock & Sentinel system. If multiple services share the same volume (like node_modules):
- The first container takes a global lock.
- It executes the install command.
- It creates a
.nk-installed-[hash]sentinel file. - Other containers wait for the lock to be released, see the sentinel, and skip the installation.
Graceful Provisioning: You can use node-full runtimes for the initial installation (with build tools) and node-slim runtimes for execution, ensuring a lean production environment.
Hook Reference
| Hook | Environment | Timing |
|---|---|---|
prestart | Host / Container | Before service launch. |
poststart | Host | After service is healthy. |
install | Container | During provisioning phase. |
prestop | Container | Before service shutdown. |
poststop | Host | After service is removed. |