Linux tmpfiles.d & Runtime Directory Management Prompt
Author and debug systemd-tmpfiles entries — creating, cleaning, and permissioning runtime/volatile paths in /run, /var, and /tmp declaratively instead of with fragile init scripts.
- Target user
- Linux admins and packagers managing service runtime state
- Difficulty
- Beginner
- Tools
- Claude, ChatGPT
The prompt
You are a senior Linux admin who replaced a pile of `mkdir`/`chown` boot scripts with clean `tmpfiles.d` entries, and you know every type code and its argument quirks by heart. I will provide: - What I need: create a runtime dir, set ownership/mode, auto-clean old files, or fix a path that vanishes on reboot - The service or app that owns the path and the user/group it runs as - Current init script / ExecStartPre hacks I'm trying to retire - Any symptom: dir missing after reboot, wrong perms, /tmp files never cleaned Your job: 1. **Explain the model** — `tmpfiles.d` is declarative: systemd-tmpfiles creates/cleans paths at boot and on a timer. Show the line format: `Type Path Mode User Group Age Argument`. 2. **Pick the type code** — `d` (create dir), `D` (create + clean contents), `f`/`F` (create file), `L` (symlink), `C` (copy), `z`/`Z` (recursively fix perms), `r`/`R` (remove), `x`/`X` (exclude from cleanup). Recommend the right one for my need and explain the uppercase-vs-lowercase distinction. 3. **Write the entry** — a concrete drop-in at `/etc/tmpfiles.d/myservice.conf` with correct Mode (octal), User, Group, and Age (e.g., `10d` cleanup). Explain that `/run` is volatile so `d` there must be recreated every boot. 4. **Wire to a service** — show `RuntimeDirectory=` in the unit as the simpler alternative when the path is purely per-service, and when `tmpfiles.d` is the better choice (shared paths, persistence in `/var`). 5. **Apply without reboot** — `systemd-tmpfiles --create /etc/tmpfiles.d/myservice.conf` to apply now, and `--clean` to test the aging rules. 6. **Debug** — `systemd-tmpfiles --create --dry-run`, check the `systemd-tmpfiles-setup.service` / `-clean.timer` status, and explain ordering vs your own service (`After=systemd-tmpfiles-setup.service`). 7. **Anti-patterns** — recreating `/run` dirs in ExecStartPre instead of declaratively, wrong Age semantics (atime vs mtime confusion deleting active files), using `R` on a path that could match too broadly, octal mode without a leading mode char. Output as: (a) the exact `tmpfiles.d` drop-in, (b) the apply-now command, (c) the `RuntimeDirectory=` alternative if it fits better, (d) the dry-run verification.
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
-
Runtime Capability & Ambient Set Audit (getpcaps) Prompt
Audit what Linux capabilities a running process actually holds across its permitted/effective/inheritable/ambient/bounding sets, and decide whether a service is over-privileged or whether a 'permission denied' is a missing capability.
-
systemd Encrypted Credentials (systemd-creds) Design Prompt
Replace plaintext secrets in environment variables and EnvironmentFile= with TPM-backed or host-bound encrypted credentials delivered to units via systemd-creds and LoadCredentialEncrypted=.
-
systemd-nspawn and machinectl Container Management Prompt
Build, network, and lifecycle-manage lightweight OS containers with systemd-nspawn and machinectl for test environments without pulling in a full container runtime.
-
systemd-sysext Extension Image Management Prompt
Design and troubleshoot systemd-sysext system extension images so tools overlay onto an immutable or read-only base OS at runtime without modifying the underlying image.
More Linux Admins prompts & error guides
Browse every Linux Admins prompt and troubleshooting guide in one place.
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.