LinuxCommandLibrary

restart

Restart system services

SYNOPSIS

systemctl restart [--no-block] [--wait] [--no-legend] [--no-pager] UNIT...

PARAMETERS

UNIT...
    One or more unit names (e.g., 'apache2.service', 'network.target') to restart. These units typically represent services, sockets, devices, mount points, or other systemd objects.

--no-block
    Do not wait for the operation to finish. The command returns immediately after the unit has been enqueued for the operation.

--wait
    Wait for the operation to finish. This is typically the default for certain unit types (like services), ensuring the command doesn't return until the service has successfully started.

--no-legend
    Do not print the legend (column headers) when listing units or services.

--no-pager
    Do not pipe output into a pager. This is useful for scripting or when output needs to be redirected.

DESCRIPTION

The term 'restart' in Linux does not refer to a standalone command but rather to a common operation performed on services, applications, or the entire system. When referring to services, 'restart' typically means stopping a running service and then starting it again. This is crucial for applying configuration changes, recovering from errors, or refreshing service state.

The most prevalent tool for restarting services on modern Linux distributions (those using systemd) is the systemctl command with its restart subcommand. For restarting the entire Linux system, commands like reboot or shutdown -r are used. This analysis will focus primarily on the systemctl restart operation for services, which ensures that a service is gracefully shut down and then brought back up, often reloading its configuration files in the process.

CAVEATS

The 'restart' command itself does not exist as a standalone executable in typical Linux installations; it's a subcommand of tools like systemctl or service. Restarting a service or the system typically requires root privileges (or sudo). A restart operation will momentarily stop the service, causing a brief interruption. For configuration changes that don't require a full stop/start, consider using reload if the service supports it.

RESTART VS. RELOAD

The restart command explicitly stops a service and then starts it again. This ensures the service is completely reinitialized, which is often necessary after significant configuration changes or to clear internal states. In contrast, reload (if supported by the service) attempts to apply configuration changes without stopping the service, leading to zero or minimal downtime. Always prefer reload if it achieves the desired effect and the service supports it, otherwise use restart.

SYSTEM-WIDE RESTART

For a complete system reboot, commands such as reboot or shutdown -r now are used. These commands are typically reserved for kernel updates, system-wide configuration changes, or critical system recovery, as they affect all running processes and bring the entire operating system down and back up.

HISTORY

In older Linux systems (pre-systemd), services were primarily managed via System V init scripts located typically in /etc/init.d/. Restarting a service involved executing a script directly, e.g., /etc/init.d/apache2 restart, or using the service wrapper command (e.g., service apache2 restart).

With the adoption of systemd as the default init system in most modern distributions (e.g., Fedora, CentOS 7+, Debian 8+, Ubuntu 15.04+), systemctl has become the standard utility for managing services, including the restart operation. This evolution aimed to provide a more consistent, efficient, and powerful framework for service control and dependency management.

SEE ALSO

systemctl(1), service(8), reboot(8), shutdown(8), init(8)

Copied to clipboard