Home > Package & System Management > systemctl

systemctl Command Guide: The Core of systemd Service Management

`systemctl` is a key tool for managing the system and services of the systemd system manager. systemd is used as a standard to manage the system's boot processes, services, mount points, sockets, and more in modern Linux distributions. With `systemctl`, you can efficiently control the entire system by checking the status of services, starting/stopping/restarting them, and configuring whether they should run automatically at system boot. Learn various ways to utilize `systemctl` through this guide.

Overview of systemctl

systemd is an init system that manages the boot process of the system and controls all services (daemons) that run in the background after the system boots. `systemctl` provides an interface to manipulate these functionalities of systemd from the command line. Various commands such as `service`, `chkconfig`, `reboot`, and `shutdown` have been integrated into `systemctl`.

Understanding systemd Units

systemd abstracts everything it manages into a concept called 'Unit'. Each unit represents a specific service, mount point, device, etc. The most commonly dealt unit types include `service unit (.service)`, `socket unit (.socket)`, `mount unit (.mount)`, `device unit (.device)`, and `target unit (.target)`. Typically, the `.service` extension is omitted in use.

Key Roles of systemctl

  • Check Service Status: Identify running services, enabled services, failed services, etc.
  • Control Services: Start, stop, restart, and reload (re-read configuration) services.
  • Set Automatic Start for Services: Configure services to start automatically at system boot or disable this setting.
  • System Power Management: Reboot, power off, or suspend the system.
  • Manage Unit Files: Check and modify locations, dependencies, etc. of unit files.

Main systemctl Command Options

`systemctl` provides a rich set of options for various functions such as service management, system power control, and unit file management. Most service-related commands require `sudo` privileges.

1. Service Status and Control

2. Set Service Auto-Start

3. System Power Management

4. Unit Files and Lists

Generated command:

Try combining the commands.

Description:

`systemctl` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Learn how to effectively manage services on systemd-based systems through various usage examples of the `systemctl` command.

Check Status of Web Server (Nginx)

systemctl status nginx.service

Check detailed information about whether the Nginx web server is currently running, inactive, or encountering errors.

Start MySQL Service

sudo systemctl start mysql.service

Starts the MySQL database service.

Restart SSH Service

sudo systemctl restart sshd.service

Restarts the SSH (Secure Shell) service. Useful after changing the configuration file.

Set Apache Web Server to Start Automatically

sudo systemctl enable apache2.service

Configures the Apache web server to start automatically at system boot.

Check List of All Active Services

systemctl list-units --type=service --state=active

Lists all service units in 'active' status (currently running or ready) on the current system.

Reboot System via systemd

sudo systemctl reboot

Safely reboots the system in the most recommended way.

View Content of Specific Service Unit File

systemctl cat redis-server.service

Check the contents of the Redis service's systemd unit file (e.g., `/etc/systemd/system/redis.service`) to understand how the service operates.


Same category commands