systemctl

systemctl is a command-line utility used to interact with systemd, the init system and service manager used by many Linux distributions. systemctl provides a comprehensive interface for managing services, inspecting the state of the system, and controlling system behavior.

Overview of systemctl

Purpose

systemctl is used to:

  • Manage system services (start, stop, restart, enable, disable).

  • Query and change system states.

  • Control system boot process.

  • Inspect logs and system status.

Basic Usage

The general syntax for systemctl commands is:

systemctl [options] <command> [name]
  • [options]: Various options to control the behavior of systemctl.

  • <command>: The specific action to perform (e.g., start, stop, status).

  • [name]: The name of the service, unit, or target to act upon.

Common systemctl Commands

  1. Starting and Stopping Services

    • Start a service:

      Example:

    • Stop a service:

      Example:

    • Restart a service:

      Example:

    • Reload a service (if the service supports it):

      Example:

  2. Enabling and Disabling Services

    • Enable a service (start at boot):

      Example:

    • Disable a service (do not start at boot):

      Example:

    • Check if a service is enabled:

      Example:

  3. Checking Service Status

    • Get the status of a service:

      Example:

  4. Listing Services and Units

    • List all services:

    • List all units (including services, sockets, targets, etc.):

    • List failed units:

  5. Managing System States

    • Reboot the system:

    • Power off the system:

    • Suspend the system:

    • Hibernate the system:

  6. Masking and Unmasking Services

    • Mask a service (prevent it from starting):

      Example:

    • Unmask a service (allow it to start):

      Example:

Advanced Usage

  1. Viewing Logs with journalctl

    • View logs for a specific service:

      Example:

  2. Editing Unit Files

    • Edit a service unit file:

    • Reload systemd manager configuration after editing unit files:

Conclusion

systemctl is an essential tool for managing and controlling services and system states on a Linux system running systemd. It provides powerful capabilities for administrators to maintain and troubleshoot system services effectively.

Last updated