Socket Activation
Starting 100 services at boot takes time, even in parallel. Socket activation is a clever trick: systemd creates the network sockets for services immediately, but only starts the actual service when the first connection arrives. Boot is faster; services start on demand.
The Problem Socket Activation Solves
Socket activation solves both problems elegantly:
- systemd creates the socket immediately at boot (microseconds)
- Client connects → kernel buffers the connection → systemd starts the service
- Service inherits the already-bound socket — no race condition
- Dependent services can connect to the socket before the service even starts (kernel buffers until service is ready)
Socket + Service Unit Files
How the Service Gets the Socket
sd_listen_fds() function from libsystemd reads the LISTEN_FDS environment variable to know how many FDs to use.
Languages with systemd libraries (Python: systemd.daemon, Go: coreos/go-systemd) can use socket activation with a few lines of code.
Real-World Examples
| Service | Socket | Notes |
|---|---|---|
| sshd | ssh.socket | Port 22 — inetd-style, one sshd per connection |
| DBus | dbus.socket | System bus socket |
| Docker | docker.socket | /var/run/docker.sock |
| CUPS (printing) | cups.socket | Only starts printer daemon when you print |
Frequently Asked Questions
What will I learn here?
This page covers the core concepts and techniques you need to understand the topic and progress confidently to the next lesson.
How should I use this page?
Start with the overview, then follow the section links to deepen your understanding. Use the table of contents on the right to jump to specific sections.
What should I read next?
Use the navigation below to continue to the next lesson or explore related topics.