restart Command in Linux

Learn via video courses
Topics Covered

Overview

The restart command in Linux is a powerful tool often used by administrators and power users alike to control system services. Its primary purpose is to stop and then immediately start a service again. This is especially useful when applying configuration changes or debugging issues.

Syntax of restart Command in Linux

The basic syntax of the restart command in Linux is as follows:

Where:

  • sudo: This is a command that allows users to run programs with the security privileges of another user (normally the root).
  • systemctl restart: This is the actual restart command that is used to stop and start a service.
  • service-name: This is the name of the service that you wish to restart.

Options in restart Command in Linux

  1. --no-pager: The --no-pager option disables the automatic use of a pager for the full systemctl command output.

    For example -

    This command restarts the specified service without the output being piped into a pager.

  2. --quiet: The --quiet option minimizes the output of the restart command in Linux.

    For example -

    This command restarts the specified service with minimal command output.

  3. --force: The --force option can be used to force a service to restart, even if it is currently in an active state.

    For example -

    This command forcefully restarts the specified service.

Example Usages

  • Standard usage of the restart command in Linux.:

    Explanation: This command restarts the Apache HTTP server (httpd).

  • Restarting multiple services at once.:

    Explanation: This command restarts both the Apache HTTP server (httpd) and the MySQL server (mysqld) simultaneously.

Tips

  • Always verify the status of the service after using the restart command in Linux to ensure it has restarted properly.

  • Be careful when using the --force option as it can disrupt running processes.

Advanced Use Cases of restart Command in Linux

  • Restarting a service and displaying the status afterwards.:

    Explanation: This command restarts the Apache HTTP server (httpd) and then immediately displays the status of the service.

  • Using the --force option to restart a stubborn service.:

    Explanation: This command forcefully restarts the Apache HTTP server (httpd), regardless of its current state.

  • Restarting a service without a pager for the output.:

    Explanation: This command restarts the Apache HTTP server (httpd) and displays the output directly without using a pager.

Conclusion

  • The restart command in Linux is a critical tool for managing system services.

  • Always ensure to check the status of a service after using the restart command.

  • Using the --force option can be helpful for stubborn services, but use with caution as it can disrupt running processes.

  • You can customize the output of the command with options such as --no-pager and --quiet.