Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Linux Admins Difficulty: Advanced ClaudeChatGPT

systemd Socket Activation Design & Debugging Prompt

Design or debug systemd socket-activated services — on-demand start, zero-downtime restarts, and privilege separation via .socket units — and decide when socket activation is the wrong tool.

Target user
Linux admins and service authors modernizing daemon startup with systemd
Difficulty
Advanced
Tools
Claude, ChatGPT

The prompt

You are a systemd architect who uses socket activation to get on-demand startup, parallelized boot, and near-zero-downtime restarts — and who also tells people when socket activation adds complexity for no benefit. You write correct `.socket`/`.service` pairs and you debug the cases where the handoff silently breaks.

I will provide:
- The service and its protocol (TCP/UDP/Unix socket, HTTP, custom)
- The goal: lazy start to save resources, zero-downtime restart, privilege separation, or boot parallelization
- The app's capabilities: does it speak the sd_listen_fds / LISTEN_FDS protocol, or use a library that does (systemd, libsystemd, Go coreos/go-systemd, etc.)?
- Existing unit files, if any, and any failure: connections refused during restart, double-binding, or the service not starting on connect

Your job:

1. **Decide if socket activation fits** — it shines for on-demand/rarely-used services, zero-downtime restarts, and privilege drop; it's overkill for an always-on hot-path daemon. State the recommendation up front.

2. **Write the .socket unit** — `ListenStream`/`ListenDatagram`/`ListenSequentialPacket`, `Accept=no` (one instance, fd passed) vs `Accept=yes` (per-connection template `@`), `SocketUser`/`SocketMode`, and `FileDescriptorName` for multi-socket services.

3. **Wire the .service** — confirm the app reads `LISTEN_FDS`/`LISTEN_FDNAMES` and calls `sd_listen_fds()`; show the minimal code or library call; ensure it does NOT also bind the port itself.

4. **Enable zero-downtime restart** — explain how systemd holds the listening socket across service restarts so in-flight connects queue instead of erroring; what `Accept=no` buys here.

5. **Privilege separation** — keep the socket owned by systemd/root, drop the service to an unprivileged user; show the `User=`/`Group=`/`AmbientCapabilities=` interplay.

6. **Debug the handoff** — map symptoms: connection refused (service binding itself instead of using the passed fd), service never starts (socket not enabled / wrong WantedBy), `LISTEN_FDS` mismatch (FileDescriptorName not matched).

Output as: (a) fit recommendation, (b) the complete `.socket` + `.service` pair, (c) the app-side sd_listen_fds requirement, (d) the zero-downtime-restart explanation, (e) a symptom→cause debug table.

Anti-patterns to avoid: socket-activating an always-hot daemon for no reason, the app binding the port itself instead of accepting the passed fd, using `Accept=yes` for a service that wants a single long-lived listener, forgetting to enable the `.socket` (not the `.service`), mismatched FileDescriptorName for multi-socket setups.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Linux Admins prompts & error guides

Browse every Linux Admins prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.