Software & AppsOperating SystemLinux

How To Unmask a Masked Systemd Service in Ubuntu

Ubuntu 12

In this article, we will delve into the process of unmasking a masked systemd service in Ubuntu. This is a useful skill for system administrators and developers who work with Ubuntu systems.

Quick Answer

To unmask a masked systemd service in Ubuntu, you can use the systemctl unmask command followed by the name of the service. If the unit file for the service is a symlink to /dev/null, you can delete the symlink using the rm command. After making any changes, remember to reload the systemd daemon using the systemctl daemon-reload command.

Introduction to Systemd Services

Systemd is an init system used in Linux distributions to bootstrap the user space and manage all processes subsequently. One of the main features of systemd is the concept of “units” which are resources that the system knows how to manage. Units are categorized into several types, one of which is a “service”.

A systemd service is a unit that represents a specific system process. Services can be in different states, including active (running), inactive (dead), and masked.

A masked service is one that is prevented from being started. This is usually done to prevent a service from automatically starting, but it can also be used to prevent a service from running at all.

Checking the Status of a Masked Service

Before unmasking a service, you first need to check its status. This can be done using the systemctl command followed by the status keyword and the name of the service. For example:

systemctl status x11-common

The output will show whether the service is masked. If it is, it will look something like this:

â— x11-common.service
 Loaded: masked (/dev/null; bad)
 Active: inactive (dead)

Unmasking the Service

If the service is masked, you can unmask it using the systemctl command followed by the unmask keyword and the name of the service. For example:

sudo systemctl unmask x11-common.service

The sudo command is used to run the command as the root user, which is necessary because unmasking a service is a system-level operation.

If running the unmask command does not change the status of the service, it may be because the unit file for the service is a symlink to /dev/null.

Checking if the Unit File is a Symlink to /dev/null

You can check if the unit file for the service is a symlink to /dev/null by using the file command followed by the path to the unit file. For example:

file /lib/systemd/system/x11-common.service

If the output shows that the unit file is a symbolic link to /dev/null, it will look something like this:

/lib/systemd/system/x11-common.service: symbolic link to /dev/null

Deleting the Symlink

If the unit file is a symlink to /dev/null, you can delete the symlink using the rm command followed by the path to the unit file. For example:

sudo rm /lib/systemd/system/x11-common.service

Again, the sudo command is used to run the command as the root user.

Reloading the Systemd Daemon

After deleting the symlink, you need to reload the systemd daemon to apply the changes. This can be done using the systemctl command followed by the daemon-reload keyword. For example:

sudo systemctl daemon-reload

Checking the Status of the Service Again

Finally, you should check the status of the service again to ensure that it is no longer masked. You can do this using the systemctl command followed by the status keyword and the name of the service, just like you did at the beginning. For example:

systemctl status x11-common

If the service has been successfully unmasked, the output will show that the service is now loaded and inactive (dead), like this:

â— x11-common.service
 Loaded: loaded (/lib/systemd/system/x11-common.service; disabled; vendor preset: enabled)
 Active: inactive (dead)

Conclusion

Unmasking a masked systemd service in Ubuntu is a straightforward process once you understand the steps involved. However, it is important to note that if there is an update for systemd in the future, the unit file may be reinstalled, which could mask the service again. Therefore, it is a good idea to check the status of important services regularly.

We hope you found this article helpful. If you have any questions or comments, please feel free to leave them in the comments section below.

What is a masked systemd service?

A masked systemd service is a service that is prevented from being started. It can be used to prevent a service from automatically starting or running at all.

How can I check the status of a masked service?

You can check the status of a masked service using the systemctl command followed by the status keyword and the name of the service. For example: systemctl status x11-common. The output will indicate whether the service is masked or not.

How do I unmask a masked systemd service?

To unmask a masked systemd service, you can use the systemctl command followed by the unmask keyword and the name of the service. For example: sudo systemctl unmask x11-common.service. Note that this operation requires root privileges.

What should I do if the service does not change status after unmasking?

If the service does not change status after unmasking, it may be because the unit file for the service is a symlink to /dev/null. You can check if this is the case by using the file command followed by the path to the unit file. If it is a symlink, you can delete it using the rm command followed by the path to the unit file.

How can I reload the systemd daemon?

To reload the systemd daemon and apply the changes made to the unit files, you can use the systemctl command followed by the daemon-reload keyword. For example: sudo systemctl daemon-reload. This ensures that the changes take effect.

How can I check the status of the service again after unmasking?

To check the status of the service again after unmasking, you can use the systemctl command followed by the status keyword and the name of the service. For example: systemctl status x11-common. The output will show the updated status of the service, indicating whether it is loaded and inactive or active.

Leave a Comment

Your email address will not be published. Required fields are marked *