# Systemd and Modern Linux Service Management

URL: https://www.devopsness.com/blog/systemd-and-modern-linux-service-management
Author: Kiril Urbonas
Published: 2025-12-13
Updated: 2025-12-13
Categories: Linux
Tags: Docker, Terraform, Ansible

Summary: Run services reliably with systemd: units, dependencies, and resource limits.

---
# Systemd and Modern Linux Service Management

**Systemd** is the standard for service management on most Linux distros. Use it for reliability and observability.

## Unit Basics

```ini
[Unit]
Description=My App
After=network-online.target
Wants=network-online.target

[Service]
Type=exec
ExecStart=/usr/local/bin/myapp
Restart=on-failure
RestartSec=5
User=app
LimitNOFILE=65536

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

## Best Practices

- **Restart=on-failure** with **RestartSec** to avoid tight restart loops.
- **User=** non-root; use **CapabilityBoundingSet** and **NoNewPrivileges** when possible.
- **LimitNOFILE**, **LimitNPROC** to avoid resource exhaustion.
- **After=network-online.target** so the app starts when the network is ready.

## Logging

- **journald**: Use **StandardOutput=journal** and **StandardError=journal**; query with **journalctl -u myapp -f**.

Systemd gives you a consistent way to run and debug services across environments.
