Linux systemctl Command
The systemctl command is used to introspect and control the systemd system and service manager in Linux. It allows you to manage services, check their statuses, and perform various administrative tasks.
Common Options
start: Start a service.stop: Stop a service.restart: Restart a service.status: Check the status of a service.enable: Enable a service to start at boot.disable: Disable a service from starting at boot.is-active: Check if a service is active.is-enabled: Check if a service is enabled.list-units: List all loaded units.
Examples
Start a Service
To start a service, use the following command:
systemctl start nginx
Stop a Service
To stop a service, use:
systemctl stop nginx
Check the Status of a Service
To check the status of a service:
systemctl status nginx
Enable a Service
To enable a service to start at boot:
systemctl enable nginx
Disable a Service
To disable a service from starting at boot:
systemctl disable nginx
Restart a Service
To restart a service:
systemctl restart nginx
Check if a Service is Active
To check if a service is active:
systemctl is-active nginx
List All Loaded Units
To list all loaded units:
systemctl list-units
Check if a Service is Failed
To check if a service has failed:
systemctl is-failed nginx
Check all the failed services
To check all the failed services:
systemctl --failed
Check the list of all unit files
To check the list the unit of all files:
systemctl list-unit-files
Check the list of all unit temprory
To check the list the unit of all files:
systemctl list-unit-files --type=service
Check the list of all unit files with their status
To check the list the unit of all files with their status:
systemctl list-unit-files --type=service --state=enabled
Masking
To prevent a service from being started, even manually, you can mask it:
systemctl mask nginx
This creates a symlink to /dev/null, effectively disabling the service.
Unmasking
To unmask a service, use:
systemctl unmask nginx