How to Modify the Systemd Service

Systemd is the default init system for most Linux distros. Its popularity is mainly due to its enhanced performance and positive significance in the Linux ecosystem which makes it an integral part of any Linux system. Systemd is primarily responsible for the system’s services and processes. While at it, you may want to modify the different configuration files to modify the services. Our focus today is understanding the systemd service and how you can modify it.

Understanding the Systemd Service

Systemd is best described as a service manager for Linux distributions. It is a software suite that offers unit files to act as the init system in Linux. Systemd was introduced as an alternative to the traditional SysV init system which offers parallelization and enhanced performance.

Systemd works with unit files. The unit files are resources that are recognized and controlled by the system. Each unit file contains configuration instructions that define what the unit entails and its behavior. The unit files are stored in three main locations in Linux.

  1. /etc/systemd/system/ – The location contains the unit files that the system administrator creates or customizes. Any unit file that is created using the “systemctl enable” command is stored in this location.
  2. /run/systemd/system/ – It contains any unit file that is created at run time.
  3. /usr/lib/systemd/system/ – It stores the system’s copy of unit files. Any software that requires installing the unit files keeps them in this location.

Systemd is essential in Linux. It offers different features. The common ones include the following:

  1. System management – It provides various commands and required utilities to manage the different system aspects including user sessions, time synchronization, power management, etc.
  2. Process management – It tracks all processes in your Linux system while monitoring and controlling how the services utilize the resources to prevent any service from monopolizing a resource at the expense of other services.
  3. Journaling – A key role that systemd plays is to log the messages from different services and sources. Users can search, filter, and analyze the collected log messages.
  4. Parallelization – By utilizing the modern hardware capabilities, systemd can offer parallelization of services which leads to improved system responsiveness and faster boot time.
  5. Service Management – By utilizing the unit files, the systemd manages the tasks related to various system services such as starting, stopping, and reloading the services.

 How to Modify the Systemd Service

Systemd allows modifying the critical system services. Thus, you must be cautious about the configuration files that you want to modify. Nonetheless, modifying the systemd service involves opening its configuration file or the particular unit file, applying the modification, and reloading the systemd for the changes to apply.

Start by identifying the name of the service that you want to modify. That way, you will easily know its location from the three locations that are mentioned in the post. For instance, if we want to modify the sshd.service, we know it’s in the /etc/systemd/system/ location. You can verify so using the “ls” command as follows:

$ ls /etc/systemd/system/ | grep sshd

We can note that our target service exists in the target location.

Next, use a text editor of your choice to open your systemd service. We use nano in our case. Ensure to give the absolute path to the systemd service unit file.

The service configuration file opens in your text editor. Modify it to implement the changes that you want in the unit file. Note that the service follows the INI-style format. You can verify so with the different sections it has including [Unit], [Service], and [Install]. Modify your changes in the correct section.

Save the changes and exit the file.

You must reload the systemd daemon for your changes to take effect. For that, run the following command:

$ sudo systemctl daemon-reload

Once the systemd daemon reloads, you can then restart the service that you modified. For our case, the service is sshd.service. We restart it as shown in the following:

$ sudo systemctl restart sshd.service

Lastly, check the status of the systemd service to ensure that it is up and running with no errors. Use the “systemctl” status command. The output should confirm that your service is active (running). If there is an error in the modification, you will see it in the output and you can work to modify it correctly.

That’s how you modify the systemd service.

Conclusion

Linux distros rely on the systemd service to handle the system and processes. By utilizing the different unit files, the systemd enhances performance and achieves different goals which makes it the ideal init system for Linux. To modify the systemd service, identify the target service, open it with a text editor, modify the changes, save the file, reload the daemon, and restart the service. All of that are explained in this post.

source

Leave a Comment