systemd Service (Advanced)
Create an advanced systemd unit file with Restart, RestartSec, MemoryLimit, CPUQuota, ProtectSystem, ProtectHome and User for hardening.
—
A systemd unit with limits and a restart policy
A systemd service unit fits in five lines, but the ones deciding production behaviour are almost never among those five. The restart policy, the interval between attempts and the memory and CPU limits are what separate a service that recovers on its own from one that restarts in a loop until it takes the machine down.
Fill in the description, the user, the command and the working directory, choose the restart policy and the limits, and the page assembles the complete unit with its three sections. The policy usually wanted is restarting on any exit rather than only on failure — that way the service comes back even after exiting with code zero by mistake.
The memory limit deserves an explanation: it is enforced by the kernel resource controller, and exceeding it gets the process killed by the out-of-memory mechanism. It is protection against leaks, not a performance setting. The CPU limit, by contrast, is proportional and merely slows the process under contention, without killing it. After writing the unit, systemd's configuration must be reloaded for it to see the changes.
Frequently asked questions
Which restart policy should I use?
Why does my service stop trying to restart?
Do I need to reload systemd after editing?
Related Tools
Cron Expression Editor
Parse and build cron expressions with human-readable descriptions, next execution times and shortcuts for common schedules.
Unix Permissions Calculator (chmod)
Calculate Unix file permissions visually. Check read, write and execute for owner, group and others to get the octal code (e.g. 755) and symbolic notation (e.g. rwxr-xr-x).
service-worker.js Generator
Generate a basic service worker with cache-first or network-first strategy and a precache asset list.
Git Aliases Generator
Useful git aliases (st, co, br, lg, undo, save, wip, amend, hist) ready to paste into .gitconfig.
Accept-Charset Header Parser
Breaks an Accept-Charset header into charsets and q-values and ranks them by preference. The header is deprecated; today's clients simply assume UTF-8.
Caddyfile Generator
Generate Caddyfile with automatic HTTPS (Let's Encrypt), reverse_proxy or file_server. Modern simple Caddy 2 syntax.