I had a service that worked fine for about ten days, then mysteriously stopped accepting connections. Restarting it fixed things — for another ten days. Took me a while to figure out the pattern.

The culprit wasn't the service itself. It was systemd-tmpfiles.

What systemd-tmpfiles Does

On most modern Linux distros, systemd runs a periodic cleanup job that removes files from /tmp that haven't been accessed recently. The default is 10 days.

This is usually fine. /tmp fills up with garbage, and the cleanup keeps things tidy. But if your service puts sockets, PID files, or temp data in /tmp and doesn't touch them for a while — they get deleted. Silently.

My service created a Unix socket in /tmp on startup, then just... sat there. No one connected to it for ten days. The cleanup job ran, saw an untouched socket file, and removed it. The service was still running — but nothing could connect to it anymore.

How to Check If This Will Bite You

Look at your tmpfiles configuration:

systemd-tmpfiles --cat-config 

You'll see something like q /tmp 1777 root root 10d — that 10d means files untouched for 10 days get cleaned out.

You can also check when the last cleanup ran:

journalctl -u systemd-tmpfiles-clean --since yesterday 

The Fix

A few options depending on your situation:

Move your runtime files out of /tmp — Use /run/myservice/ instead. The /run directory is a tmpfs (RAM-backed) that gets cleared on reboot but isn't subject to the periodic cleanup. This is the cleanest fix.

Whitelist your paths — Create a custom tmpfiles config that excludes your service's directory:

# /etc/tmpfiles.d/myservice.conf x /tmp/myservice/* 

The x tells tmpfiles to skip those paths entirely during cleanup.

Touch your files periodically — If you can't change the location, have your service periodically access its socket or temp files. A simple touch in a cron job or an in-process timer works, but this feels like a hack.

The Part That Got Me

The service didn't crash. It didn't log any errors. It just silently lost its socket file and kept running in a zombie-like state where it was technically alive but completely unreachable. No amount of systemctl status would tell you the socket was gone — you had to actually look in /tmp and notice it was missing.

If you're running anything long-lived that uses /tmp for sockets or state files, worth a quick check. Ten days of uptime is a long time, but not as long as you'd think before someone notices the service is dead.