Skip to content

Latest commit

 

History

History
109 lines (76 loc) · 2.91 KB

03-systemctl_introduction.md

File metadata and controls

109 lines (76 loc) · 2.91 KB

me

Introduction to systemctl

systemctl is a command-line tool used to control the systemd service manager on Linux systems. It allows you to manage system services, check the status of services, control system boot behavior, and manage system states. It is a critical tool for system administration, providing a comprehensive interface to interact with systemd.

Key Features

  • Service Management: Start, stop, restart, enable, or disable services.
  • System Status: View the status of services and the overall system.
  • Boot Management: Control which services start on boot.
  • System States: Manage the system's power states (e.g., reboot, shutdown).

Basic Usage

Starting and Stopping Services

To start a service, use the following command:

sudo systemctl start <service_name>

To stop a service, use:

sudo systemctl stop <service_name>

For example, to start or stop the nginx service:

sudo systemctl start nginx
sudo systemctl stop nginx

Restarting and Reloading Services

To restart a service, which stops and then starts the service, use:

sudo systemctl restart <service_name>

To reload the service configuration without stopping the service, use:

sudo systemctl reload <service_name>

Enabling and Disabling Services

To enable a service to start automatically at boot, use:

sudo systemctl enable <service_name>

To disable a service from starting at boot, use:

sudo systemctl disable <service_name>

Checking Service Status

To check the status of a service, use:

sudo systemctl status <service_name>

This command provides detailed information about the service, including whether it is running, its recent log entries, and any issues.

Viewing All Services

To list all available services and their statuses, use:

systemctl list-units --type=service

Managing System States

To reboot, shut down, or power off the system, use:

sudo systemctl reboot     # Reboot the system
sudo systemctl poweroff   # Power off the system
sudo systemctl halt       # Halt the system

Viewing System Logs

To view logs related to systemd and its services, use:

journalctl -u <service_name>

This is useful for troubleshooting and monitoring service behavior.

Masking and Unmasking Services

Masking a service prevents it from being started manually or automatically:

sudo systemctl mask <service_name>

To unmask a service, allowing it to start again, use:

sudo systemctl unmask <service_name>

Conclusion

systemctl is an essential tool for managing systemd on Linux systems, offering comprehensive control over services and system states. Whether you need to manage service lifecycles, configure boot behavior, or troubleshoot issues, systemctl provides a powerful and flexible interface for system administration.