systemctl in Unix
systemctl is used to examine and control the state of “systemd” system and service manager. systemd is a system and service manager for Unix-like operating systems (most of the distributions, not all). As the system boots up, the first process created, i.e. init process with PID = 1, is systemd system that initiates the userspace services.
Syntax of `systemctl` command in Unix
systemctl [command] [service]
[command] = The action we want to perform (start, stop, enable, disable, etc.)
[service] = The name of the service we want to perform the action on.
Services in `systemctl`
1) Starting and Stopping Services
systemctl start [service]
If we want to start our SSH service.
systemctl start sshd
systemctl stop [service]
If we want to stop our SSH service.
systemctl stop sshd
2) Enabling and Disabling Service
systemctl enable [service]
If we want to enable our firewall service.
systemctl enable firewalld
systemctl disable [service]
If we want to disable our firewall service.
systemctl disable firewalld
3) Viewing the Staus of Services
Viewing Status of Services
systemctl status [service]
If we want to see the status of our firewall service.
systemctl status firewalld
4) Restarting and Reloading Services
systemctl restart [service]
If we want to restart our SSH service.
systemctl restart sshd
systemctl reload [service]
If we want to reload our Apache service.
systemctl reload httpd
5) Masking and Unmasking Services
systemctl mask [service]
If we want to mask our MySQL service.
systemctl mask mysqld
Masking a service prevents it from being started or enabled, even if it is required by other services.
systemctl unmask [service]
If we want to unmask our MySQL service.
systemctl unmask mysqld
Unmasking a service allows it to be started or enabled again.
6) Changing the Default Target
systemctl set-default [target]
If we want to change the default target to graphical.target (which will start the graphical user interface).
systemctl set-default graphical.target
The default target determines which system services are started when the system boots up.
7) Listing Unit Files
This command lists all the unit files available on the system, including both enabled and disabled unit files.
8) Masking and Unmasking Unit Files
Masking Unit Files
systemctl mask [unit-file]
If we want to mask the SSH unit file.
systemctl mask sshd.service
Masking a unit file prevents it from being started or enabled, even if it is required by other services.
Unmasking Unit Files
systemctl unmask [unit-file]
If we want to unmask the SSH unit file.
systemctl unmask sshd.service
Unmasking a unit file allows it to be started or enabled again.
Options available in `systemctl` command in Unix
|–version||This option displays the version number of the systemctl command.||
|–help||This option displays the help manual for systemctl, including a list of available options and commands||
|–type||The argument in this case should be comma-separated list of unit types such as service and socket.||
|–all||This option lists all available units, including those that are inactive.||
|–failed||This option lists all units that have failed.
|–user||talk to service manager of calling user, instead of system.||
|–force||This option forces the service to start or stop, even if it has dependencies that are not yet started or stopped.||
systemctl stop --force httpd.service
|This option starts or stops the service without blocking the shell, allowing the user to continue to use the shell while the service is starting or stopping.||
systemctl start --no-block httpd.service
This option is used to filter the output based on the specified unit state. You can specify one or more-unit states separated by commas, such as active, inactive, failed, and activating.
For example: to list all the failed units.
systemctl list-units --state=failed
This option is used to show units of local containers as well.
For example: to list all units including those in local containers.
systemctl list-units --recursive
This option is used to show the types of sockets along with showing sockets.
For example: to show the types of all sockets.
systemctl list-sockets --show-types
This option controls how to deal with already queued jobs in case of queuing a new job. There are three available modes:
replace: replace already queued jobs with the new one.
For example: to use the replace mode.
systemctl isolate graphical.target --job-mode=replace
This option is used to ignore inhibitor locks when requesting a system shutdown or sleep state.
For example: to ignore inhibitor locks when requesting a system shutdown.
systemctl poweroff --ignore-inhibitors
This option is used to suppress the printing of results of various commands and the hints about the truncated lines.
For example: to reload the systemctl daemon without showing any output.
systemctl daemon-reload --quiet
This option is used to not send a wall message before power-off, halt, or reboot.
For example: to halt the system without sending a wall message.
systemctl halt --no-wall
In this article we will understand the use of `systemctl` command in Unix which is used to examin and control the state of the `systemd` system and service manager. We have covered various options and commands that are available in `systemctl` command. Like starting and stopping services, enabling and disabling services, viewing the status of services, restarting and reloading services, masking and unmasking services, changing the default target, listing unit files, and masking and unmasking unit files. We have also discussed about various options available with `systemctl` command, such as `–version`, `–help`, `–type`, `–all`, `–failed`, `–user`, `–force`, `–no-block`, `–state`, `-r, –recursive`, `–show-types`, `–job-mode`, and `-i, –ignore-inhibitors`.
Please Login to comment...