Masking Services in Systemd
Masking Services in Systemd
Introduction to Masking Services
Definition: Masking services in systemd ensures that certain units (services) cannot run simultaneously on the same system.
Use Case: This is particularly useful for services like HTTPB (HTTP Back-end) and NGINX, which cannot coexist on the same system.
Practical Application of Masking
Installation Consideration: The simplest way to avoid a conflict is to prevent the installation of both services on the same system.
Masking as a Solution: If both units are present on the system, masking one can enforce their mutual exclusivity.
Technical Explanation of Masking
Masking Command: The command
systemctl maskis used to link a unit (service) to a device node that effectively prevents it from being started, even accidentally.Underlying Mechanism:
The
systemctl maskcommand creates a symlink from the service file (e.g.,nginx.service) to/dev/null.This is a reinforcement that the service cannot be activated since starting it would try to refer to a null device.
Example Demonstration
Installing NGINX:
Command:
dnf install -y nginxFollowed by:
systemctl status nginx.serviceto check the status of NGINX service.
Conflicting Services
Conflict with HTTPB: Both HTTPB and NGINX cannot function effectively together, which is the rationale behind masking one of the services.
Masking in Action
Masking NGINX Service:
Command:
systemctl mask nginx.serviceResult: This creates a symlink in
/etc/systemd/system/nginx.service, which takes precedence over the service file located at/usr/lib/systemd/system/nginx.service.
Symlink Confirmation: The symlink will be connected to the null device confirming the masking.
Attempting to Start a Masked Service
Starting a masked service:
When attempting to start the masked service with the command:
systemctl start nginx.service.Outcome: The system responds with "Unit nginx.service is masked", confirming that the service cannot be activated due to the masking.
Unmasking a Service
Unmask Command: If the situation changes and you want to allow the service to run again, use the command:
systemctl unmask nginx.service
Caution: The speaker expresses a strong preference against allowing both HTTPB and NGINX to run on the same machine, indicating careful consideration is necessary when managing services.