Skip to main content
Concrete systemd unit patterns that reduced flakiness: restart policies, resource limits, and structured logs.

Systemd Tricks We Use to Keep Services Boring

KU
Kiril Urbonas
March 5, 2025 • 1 min read•816 views

Concrete systemd unit patterns that reduced flakiness: restart policies, resource limits, and structured logs.

Key takeaways

Concrete systemd unit patterns that reduced flakiness: restart policies, resource limits, and structured logs.

Systemd Tricks We Use to Keep Services Boring#

After a few painful outages caused by homemade init scripts, we moved everything to systemd and wrote down the patterns that worked.

Pattern: Restart with Backoff#

We had a service that occasionally failed to bind its port on boot.

```ini [Unit] Description=API service After=network-online.target Wants=network-online.target

[Service] ExecStart=/usr/local/bin/api Restart=on-failure RestartSec=5

[Install] WantedBy=multi-user.target ```

  • Restart=on-failure + RestartSec gave the process room to recover without flapping.

Pattern: Non-Root with Limits#

We saw file descriptor exhaustion during load tests.

  • Added User=api and LimitNOFILE=65536.
  • Used Ansible to roll the unit file change across the fleet.

Pattern: Journald as a Timeline#

When something goes wrong, we start with:

  • `journalctl -u api -b`
  • `journalctl -u api --since "-15min"`

Systemd didn’t fix our code, but it made failures predictable and repeatable.

Explore topics:TerraformLinux
React

Get the DevOps Troubleshooting Cheat Sheet

Subscribe and get our free one-page reference for the errors that eat an afternoon — CrashLoopBackOff, OOMKilled, Terraform state locks, and more — plus new guides as we publish them.

Share this post
KU

Kiril Urbonas

AI Engineer

560 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.