Systemd is an integral part of many Linux distributions, including Ubuntu. It’s a system and service manager, responsible for the boot process and controlling user processes. This article will delve into where systemd units/services are located in Ubuntu, how to find specific service files, and what each directory means.
Systemd units/services in Ubuntu are located in two main directories:
/lib/systemd/system/ for system-wide services provided by installed packages, and
/etc/systemd/system/ for service files specific to your local system configuration. User-specific services are located in various directories depending on the Ubuntu version and configuration. To locate specific service files, you can use commands like
Understanding Systemd Units/Services
Systemd units refer to the resources that systemd can manage. These units are represented by unit configuration files located in various directories. They can be of different types, such as service (.service), mount (.mount), device (.device), and more. This article will focus on service units, which are often referred to as “services”.
System-wide services are services that are available to all users and the system itself. They are located in two main directories:
/lib/systemd/system/: This directory contains the service files provided by installed packages. Most of the system-wide services can be found here.
/etc/systemd/system/: This directory is for service files specific to your local system configuration. It takes precedence over the
/lib/systemd/system/directory, meaning that if the same service is defined in both directories, the one in
/etc/systemd/system/will be used. This is the recommended location for customizing or adding new services.
Starting from Ubuntu 16.04, systemd also supports user-specific services. These services are only available to a specific user and are located in several directories:
Locating Specific Service Files
To locate a specific service file, you can use the following methods:
systemctlcommand is a primary tool for managing systemd services. You can use
systemctl status <service>or
systemctl show <service>to see the path of the service file. For example:
$ systemctl show ssh.service | grep Path
This command will output the path of the ssh.service file:
locatecommand is a quick way to find files by name. For example:
locate systemd | grep plex
This command will output the paths of all files that contain “systemd” and “plex” in their names.
findcommand can perform a live search in a specific directory. For example:
find / -name plexmediaserver.service
This command will search the entire filesystem for a file named plexmediaserver.service.
dpkg -L: If you know the package name associated with the service, you can use
dpkg -Lto list all the files in that package. For example:
dpkg -L plexmediaserver | grep plexmediaserver.service
This command will output the path of the plexmediaserver.service file if it is part of the plexmediaserver package.
Understanding where systemd units/services are located in Ubuntu is crucial for system administration tasks. The main locations are
/etc/systemd/system/ for system-wide services, and various directories for user-specific services. With commands like
dpkg, you can easily locate specific service files. Remember that the locations may vary depending on your Ubuntu version and configuration. Always refer to the official Ubuntu documentation or the
man pages for the most accurate and up-to-date information.
Systemd is a system and service manager that is responsible for controlling the boot process and managing user processes in Linux distributions, including Ubuntu.
Systemd units/services refer to the resources that systemd can manage. They are represented by unit configuration files that are located in various directories.
System-wide systemd unit/service files are located in the
/lib/systemd/system/ directory and the
/etc/systemd/system/ directory. User-specific systemd unit/service files can be found in various directories such as
$HOME/.config/systemd/user/, and more.
There are several methods to locate a specific systemd unit/service file. You can use commands like
systemctl show <service>,
dpkg -L to find the path of the service file.
The recommended location for customizing or adding new services in Ubuntu is the
/etc/systemd/system/ directory. This directory takes precedence over the
/lib/systemd/system/ directory, meaning that if the same service is defined in both directories, the one in
/etc/systemd/system/ will be used.
You can refer to the official Ubuntu documentation or the
man pages for more information about systemd in Ubuntu.