Enhancing Skills

systemctl: System service manager to start, stop, and manage services

Command: sudo systemctl

systemctl is a command-line utility that interacts with systemd, a system and service manager used in many Linux distributions. It controls and manages system services, including starting, stopping, restarting, and checking the status of services.


Sample Command and Output:

$ sudo systemctl

Description:

  • systemctl: Launches the systemctl tool, allowing users to manage system services and units.

Additional Commands and Sample Outputs:

  • sudo systemctl start service_name: Start a service. Sample Command and Output:
  $ sudo systemctl start apache2

Description:

  • start <service_name>: Starts the specified service (apache2 in this case) if it is not already running.
  • sudo systemctl stop service_name: Stop a service. Sample Command and Output:
  $ sudo systemctl stop apache2

Description:

  • stop <service_name>: Stops the specified running service.
  • sudo systemctl restart service_name: Restart a service. Sample Command and Output:
  $ sudo systemctl restart apache2

Description:

  • restart <service_name>: Stops and then starts the specified service, useful when configuration changes require a service reload.
  • sudo systemctl status service_name: Check the status of a service. Sample Command and Output:
  $ sudo systemctl status apache2
  ● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2023-08-09 12:00:00 UTC; 1h 23min ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 1234 (apache2)
      Tasks: 6 (limit: 4915)
     Memory: 15.3M
     CGroup: /system.slice/apache2.service
             ├─1234 /usr/sbin/apache2 -k start
             ├─1235 /usr/sbin/apache2 -k start
             ├─1236 /usr/sbin/apache2 -k start

Description:

  • status <service_name>: Displays detailed information about the specified service, including its current status (active or inactive), the main process ID, and resource usage.
  • sudo systemctl enable service_name: Enable a service to start automatically on boot. Sample Command and Output:
  $ sudo systemctl enable apache2
  Created symlink /etc/systemd/system/multi-user.target.wants/apache2.service → /lib/systemd/system/apache2.service.

Description:

  • enable <service_name>: Configures the specified service to start automatically at boot time by creating necessary symbolic links.
  • sudo systemctl disable service_name: Disable a service from starting automatically on boot. Sample Command and Output:
  $ sudo systemctl disable apache2
  Removed /etc/systemd/system/multi-user.target.wants/apache2.service.

Description:

  • disable <service_name>: Prevents the specified service from starting automatically at boot by removing the symbolic links.
  • sudo systemctl is-active service_name: Check if a service is active. Sample Command and Output:
  $ sudo systemctl is-active apache2
  active

Description:

  • is-active <service_name>: Returns whether the specified service is currently active or inactive.
  • sudo systemctl is-enabled service_name: Check if a service is enabled to start on boot. Sample Command and Output:
  $ sudo systemctl is-enabled apache2
  enabled

Description:

  • is-enabled <service_name>: Returns whether the specified service is enabled or disabled for automatic start at boot.

Note: systemctl is an essential tool for managing system services, providing comprehensive control over the starting, stopping, enabling, and monitoring of services on a system running systemd.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.