/etc/systemd
The /etc/systemd
directory is a critical part of the systemd
init system on Linux. It contains configuration files and subdirectories that control the behavior of system and service units. Understanding the structure and purpose of this directory is essential for effective system management.
Overview of /etc/systemd
/etc/systemd
The /etc/systemd
directory typically contains the following subdirectories:
/etc/systemd/system/
: Local unit files and custom unit configurations./etc/systemd/user/
: User-specific unit files and custom unit configurations.
/etc/systemd/system/
/etc/systemd/system/
The /etc/systemd/system/
directory is where administrators place unit files to override the default ones provided by the system or create custom units. This directory takes precedence over the system's default unit files located in /lib/systemd/system/
.
Common Directories and Files
Unit Files: Files that define how services, sockets, targets, and other units are managed.
multi-user.target.wants/
: Directory containing symlinks to unit files that are wanted by themulti-user.target
.graphical.target.wants/
: Directory containing symlinks to unit files that are wanted by thegraphical.target
.
Creating and Managing Unit Files
Unit files in systemd
describe the configuration and behavior of services and other system resources. They typically have the extension .service
, .socket
, .target
, etc.
Structure of a Unit File
A typical .service
unit file contains sections like [Unit]
, [Service]
, and [Install]
.
Enabling and Disabling Units
Enabling a unit means creating symlinks in the appropriate .wants
directory so that the unit starts automatically at boot.
Enable a Unit
To enable a unit (e.g., my-service.service
):
Disable a Unit
To disable a unit:
Reloading and Restarting Units
When changes are made to unit files, you need to reload the systemd
configuration and potentially restart the affected service.
Reload systemd
Configuration
systemd
ConfigurationTo reload the systemd
manager configuration:
Restart a Service
To restart a service:
Viewing and Editing Unit Files
Viewing Unit Files
To view the content of a unit file:
Editing Unit Files
To edit a unit file (using a text editor like nano
):
After editing, reload the systemd
configuration:
Overriding Default Unit Files
To override or extend the default unit files without modifying them directly, you can create drop-in files.
Creating Drop-In Files
To create a drop-in file for my-service.service
:
In the override.conf
file, you can add or modify specific settings:
Managing User-Specific Units
The /etc/systemd/user/
directory is used for user-specific unit files. These are typically managed by non-root users and allow user-level control over services.
Enabling User Units
To enable a user unit:
Starting User Units
To start a user unit:
Conclusion
The /etc/systemd
directory is crucial for managing systemd
configurations on a Linux system. It allows administrators to customize, enable, disable, and override system services and other units. Understanding how to navigate and utilize this directory is essential for effective system administration with systemd
.
Last updated