Skip to content

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):

  1. The first container takes a global lock.
  2. It executes the install command.
  3. It creates a .nk-installed-[hash] sentinel file.
  4. Other containers wait for the lock to be released, see the sentinel, and skip the installation.

Note.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 ​

HookEnvironmentTiming
prestartHost / ContainerBefore service launch.
poststartHostAfter service is healthy.
installContainerDuring provisioning phase.
prestopContainerBefore service shutdown.
poststopHostAfter service is removed.