Definition
What it is
Init has several faces depending on context. In Unix systems, init is PID 1, the first user-space process started by the kernel, responsible for launching all other processes. In systemd, init is replaced by systemd as PID 1, but the role is the same: bring the system up and keep it running. In containers, docker init or tini acts as PID 1 inside the container, reaping zombie processes and forwarding signals. In version control, git init creates the .git directory and initializes the repository skeleton. In a service context, the "init" phase is whatever the application does before it can accept traffic: load config, open database connections, warm caches, register with the service discovery.
The common thread across all of them is that init turns a blank runtime into a ready runtime. Without init, a kernel alone cannot run a userspace, a container cannot receive traffic, a repository cannot accept a commit. Init is the boundary between "empty" and "operational".
Why it matters
Init is the first thing that can go wrong. A container whose init process crashes enters a crash loop. A VM whose systemd unit fails to start is unreachable. A repository whose git init produced an inconsistent .git directory cannot be cloned reliably. A service that bootstraps without verifying its configuration may start in a half-broken state that only shows up under load.
Getting init right is what separates a system that restarts cleanly from a system that requires manual intervention. In containerized environments, where pods get killed and rescheduled frequently, a clean init is the difference between a self-healing cluster and a cascade of CrashLoopBackOff events. In CI, a well-designed init step is the difference between a reproducible build and a flaky one.
How it works
The mechanism varies by context but the structure is uniform. Read configuration from environment variables, files, or a configuration server. Validate that the configuration is complete and consistent. Open the resources that must be available before serving: sockets, database connections, cache clients, queue subscriptions. Register with service discovery if the environment requires it. Signal readiness. Either release control to the main loop, or exit non-zero so the supervisor restarts the process.
graph TD
S[Start] --> R[Read config]
R --> V{Validate}
V -->|invalid| F[Exit non-zero]
V -->|valid| O[Open resources]
O --> G[Register / signal ready]
G --> M[Main loop]
F --> X[Supervisor restarts]
In systemd, init is organized as units. Each unit declares its dependencies, its startup command, its restart policy, and its target state. systemd computes a dependency graph and starts units in the right order, with parallel starts where the graph allows. In containers, init runs as PID 1 and is responsible for reaping zombies and forwarding signals: the container's PID 1 must forward SIGTERM to its child processes, or a graceful shutdown will hang until the orchestrator's grace period expires.
Writing a clean init
Read config first
Read environment variables and config files before doing anything else. Fail fast if required values are missing.
Validate before opening resources
Check that the database host resolves, the credentials parse, the schema version matches. Abort early if not.
Open resources, then signal readiness
Open the database pool, warm the cache, subscribe to queues. Only after all dependencies are ready, signal readiness to the orchestrator.
Forward signals to children
If PID 1 has children, forward SIGTERM and SIGINT. Reap zombies. On shutdown, close resources gracefully.
A common variation is the "init container" pattern in Kubernetes: a separate container runs before the main container, with the same filesystem volume, to perform initialization tasks that should complete before the main container starts (running migrations, copying config, waiting for a dependency). The main container starts only after every init container has exited successfully.
Common failures
A second failure is doing too much work in init. Loading a large model, precomputing a large index, or running a full migration on every start turns a fast restart into a slow one and makes failures more likely. Heavy work belongs in a build step or a dedicated job, not in the hot path of every container start.
A third failure is ignoring validation. Init that starts regardless of configuration state turns a misconfiguration into a runtime failure. Validation should be cheap, deterministic, and complete. If validation fails, init must exit non-zero so the supervisor (Kubernetes, systemd, Docker restart policy) knows not to keep retrying blindly.
Origin
The word "init" is a truncation of "initialize", from the Latin initialis, "of the beginning". In Unix, init was the first process started by the kernel after the kernel itself had finished booting. The original Unix init dates to the early 1970s at Bell Labs. It has been reimplemented many times: SysV init, upstart, systemd. The name has since spread by analogy: git init, npm init, terraform init, docker init, kubeadm init. Each one performs the same conceptual operation — bringing an empty starting point into a usable state.
The init process is the first process started by the kernel, and it remains running throughout the lifetime of the system. It is responsible for bringing the system up and for reaping orphaned processes.
— Michael Kerrisk, *The Linux Programming Interface*, 2010
Evidence
FAQ
- Is init the same as systemd?
On modern Linux systems, systemd replaces init as PID 1 but plays the same role. The traditional SysV init is still present in some distributions and embedded systems. In containers, init is whatever runs as PID 1 inside the container's namespace, often
tini,dumb-init, or a purpose-built entrypoint.- Do I need an init process in every container?
Only if the container's main process has children. A single-process container that does not fork does not need an explicit init. A container that forks children needs an init to reap zombies and forward signals. When in doubt, adding
tinicosts almost nothing and prevents a class of hard-to-debug failures.- What is `git init` doing?
git initcreates a.gitdirectory with the repository skeleton: config, HEAD, refs, objects, hooks. Without that directory, Git does not recognize the folder as a repository and refuses to track anything. It is the minimal operation that turns a folder into a repository.- Should init do migrations?
Usually no. Migrations in init turn every restart into a migration attempt, which is expensive, fragile, and hard to reason about. Migrations belong in a dedicated migration job or a pre-deploy step, not in the hot path of every container start.
- Why does my container exit immediately on start?
The most common cause is init that exits: either the entrypoint finished with no long-running process, or the entrypoint failed and the container's restart policy was "no". Check the container logs, check the exit code, and confirm that the entrypoint stays in the foreground. Init must keep the process alive; if it exits, the container exits.
Connections
● broader ● narrower ● related
Used in the garden
- Medellín's Secret: Scaling Your Sub-K B2B SaaS to Market Dominance with Klaviyo (1×)
- Mastering Content Curation: Build Your Own RSS Aggregator with PHP & SimplePie (1×)
- Puppeteer & Cheerio: Master Web Data for Micro-SaaS Dominance in LatAm (1×)
- Crafting the 'Wow' Factor: Aesthetic MVPs for Lean B2B SaaS in Spain (1×)
- The Unseen Architecture: Building a Brand Operating System for Emerging SaaS Founders (1×)
- Unleash Your Inner Architect: Crafting Dominant CLI Tools with Python & Click (1×)
Sources
Kerrisk, M. (2010). The Linux Programming Interface. No Starch Press. https://man7.org/tlpi/
Kubernetes (2024). Init Containers. https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
Docker (2024). Specify an init process. https://docs.docker.com/engine/reference/run/#specify-an-init-process
Open Container Initiative (2024). Runtime Specification. https://github.com/opencontainers/runtime-spec/blob/main/config.md
Git (2024). git init. https://git-scm.com/docs/git-init
Etymology
Origin: borrowed
init(noun): truncation of "initialize", a clipping of the English verbinitialize(verb): from Latin initialis, of the beginning, from initium, a beginning
Semantic network
● broader ● narrower ● related
Used in the garden
- Medellín's Secret: Scaling Your Sub-K B2B SaaS to Market Dominance with Klaviyo (1×)
- Mastering Content Curation: Build Your Own RSS Aggregator with PHP & SimplePie (1×)
- Puppeteer & Cheerio: Master Web Data for Micro-SaaS Dominance in LatAm (1×)
- Crafting the 'Wow' Factor: Aesthetic MVPs for Lean B2B SaaS in Spain (1×)
- The Unseen Architecture: Building a Brand Operating System for Emerging SaaS Founders (1×)
- Unleash Your Inner Architect: Crafting Dominant CLI Tools with Python & Click (1×)
Sources
Kerrisk, M. (2010). The Linux Programming Interface. https://man7.org/tlpi/
Kubernetes (2024). Init Containers. https://kubernetes.io/docs/concepts/workloads/pods/init-containers/
Docker (2024). Specify an init process. https://docs.docker.com/engine/reference/run/#specify-an-init-process
Open Container Initiative (2024). Runtime Specification. https://github.com/opencontainers/runtime-spec/blob/main/config.md
Git (2024). git init. https://git-scm.com/docs/git-init