In this lesson, you will learn how to safely modify a systemd service provided by your distribution (a "vendor unit") without risking your changes being overwritten during system updates.
The Problem: Why not edit the original file?
When you install a package, the vendor places unit files in /usr/lib/systemd/system/. If you edit these files directly, your modifications will likely vanish the next time the package manager updates that software. Furthermore, direct modification of vendor files is considered bad practice because it obscures the original configuration, making it difficult to debug or revert to the "factory" state.
The Solution: Drop-in Snippets
Systemd provides a clean mechanism to override specific settings without touching the master file: drop-in directories. For any service named example.service, you can create a directory named example.service.d/ inside /etc/systemd/system/. Any file ending in .conf placed inside this directory will be merged with the original unit file, with your settings taking precedence.
How to Implement a Drop-in
Let’s say you want to increase the RestartSec for a service provided by the vendor. Instead of editing the original, you run the following command:
sudo systemctl edit example.service
This command opens your default text editor and creates a temporary file in /etc/systemd/system/example.service.d/override.conf. You can then add your overrides:
[Service]
RestartSec=10s
When you save and exit, systemd automatically reloads the daemon configuration. If you ever want to revert your changes, you simply delete the example.service.d directory and reload the daemon.
This approach creates a clear separation between the "upstream" software defaults and your local environment requirements. It ensures your custom configuration is modular, persistent, and easy to audit, keeping your system's orchestration layer clean and reliable.
Key Takeaway: Never edit vendor-supplied unit files in /usr/lib/systemd/system/; always use systemctl edit to create local override snippets in /etc/systemd/system/ to ensure your configuration survives system updates.