The Linux systemctl
command is systemd
one of the main commands of the system and service manager. It can start, stop, restart, reload, and query the status of system services. The following are systemctl
common options and usage of the command:
grammar
systemctl [OPTIONS] COMMAND [UNIT]
OPTIONS
: Optional parameter used to specifysystemctl
the behavior of the .COMMAND
: Required parameter to execute a specificsystemd
command, such as start, stop or restart a service.UNIT
: An optional parameter that specifies the service or unit to operate on.
Common options
-H
, : Specifies the hostname or IP address of the instance--host
to run on the remote host .systemd
-a
,--all
: Shows all loaded units, not just the currently active one.-t
,--type
: Filters the list of cells based on the specified cell type. Supported unit types include service, socket, mount, etc.-u
,--user
: Execute user-level services associated with the current user.
Common commands
systemctl
It is a command-line tool for managing system services in the Linux operating system. It can start, stop, restart, enable or disable services, and provide information about service status and control. Here is systemctl
a full detailed explanation of the command:
1. View service status:
systemctl status <service>
: Display the running status, log information and dependencies of the specified service.systemctl is-active <service>
: Checks whether the specified service is active (running).systemctl is-enabled <service>
: Checks if the specified service is enabled (will start automatically at system boot).systemctl is-failed <service>
: Checks whether the specified service is in a failed state.
2. Management Services:
systemctl start <service>
: Start the specified service.systemctl stop <service>
: Stop the specified service.systemctl restart <service>
: Restart the specified service.systemctl reload <service>
: Reload the configuration file for the specified service.systemctl enable <service>
: Enable the specified service to start automatically when the system boots.systemctl disable <service>
: Disables the specified service so that it does not start at system boot.
3. Management service unit:
systemctl list-units
: Lists all known service units and displays their current status.systemctl list-unit-files
: List all installed service unit files.systemctl show <unit>
: Display detailed information of the specified service unit.
4. System operation:
systemctl poweroff
: Shut down the system.systemctl reboot
: Restart the system.systemctl suspend
: Put the system in a suspended state (sleep mode).systemctl hibernate
: Put the system into hibernation (save current state to disk).
5. Log query:
systemctl status <service/unit>.service
: Displays the current status and logs of the service or unit.journalctl -u <service/unit>.service
: View the logs of the specified service or unit.
example
-
Start the Apache server service:
systemctl start httpd.service
-
Stop the Apache server service:
systemctl stop httpd.service
-
View Apache server service status:
systemctl status httpd.service
-
To set the Apache server to start automatically at system startup:
systemctl enable httpd.service
-
Disable the Apache server from starting automatically at system boot:
systemctl disable httpd.service
The above is systemctl
the basic introduction and common options, commands and examples of the command. Note that using systemctl
the command requires administrator privileges (such as root or a user with sudo privileges).