How to unmask a masked service in CentOS/RHEL 7 and 8

Problem

systemd-tmpfile-clean.timer will not start, ignoring, unit is masked.

# systemctl start systemd-tmpfiles-clean.timer
Failed to start systemd-tmpfiles-clean.timer: Unit is masked.
# systemctl status -l systemd-tmpfiles-clean.timer
● systemd-tmpfiles-clean.timer
  Loaded: masked (/dev/null; bad)
  Active: inactive (dead)

May 01 09:30:08  systemd[1]: Cannot add dependency job for unit systemd-tmpfiles-clean.timer, ignoring: Unit is masked.
May 01 09:30:28  systemd[1]: Cannot add dependency job for unit systemd-tmpfiles-clean.timer, ignoring: Unit is masked.
May 01 09:30:28  systemd[1]: Cannot add dependency job for unit systemd-tmpfiles-clean.timer, ignoring: Unit is masked.
May 01 09:30:33  systemd[1]: Cannot add dependency job for unit systemd-tmpfiles-clean.timer, ignoring: Unit is masked.
May 01 09:30:39  systemd[1]: Cannot add dependency job for unit systemd-tmpfiles-clean.timer, ignoring: Unit is masked.

The Solution

“MASK” can be observed in a service that after the service is started, had it definitions modified, reload (systemctl daemon-reload) and the new state is NOT ok. Hence, the masked state may be originated from a improper service definitions.

A service unit that is empty (0 bytes) will be parsed by systemd as masked. While systemctl mask works by symlinking the service to /dev/null, systemd appears to just check if a file is 0 bytes when read to determine if a unit is masked.

To check all the systemd services that are masked:

# systemctl list-unit-files

1. Check that the unit file is a symlink to /dev/null:

# file /usr/lib/systemd/system/[service_name].service

OR

# file /usr/etc/systemd/system/[service_name].service

2. It should return:

# /usr/lib/systemd/system/[service_name].service: symbolic link to /dev/null

3. Delete the symlink:

# sudo rm /usr/lib/systemd/system/[service_name].service

4. Reload systemd daemon as you changed a service:

# sudo systemctl daemon-reload

5. Check the status:

# systemctl status [service_name]

Now you can see that the service is stopped.

6. Start the service without any errors:

# systemctl start [service_name]