Restart cmd for linux

Restart a Linux Server from the Command Line

Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.

While your Linux server can run continuously for weeks or months, some configuration tasks may require a manual system reboot. This guide shows you how to restart a Linux server over SSH, using PuTTY, or on your server’s console interface.

When Do I Need to Restart a Linux Server?

Generally, you do not need to regularly restart your Linux server. It should be able to keep running for weeks or months, without needing to be “refreshed” with a reboot.

However, several factors may make you want to restart your server. Some software installations require a manual reboot after installation, and some applications benefit from the system being periodically rebooted. There are also many administrative processes that require restarting the server for changes to take effect. Linode Compute Instances have a feature called Lassie (Linode Autonomous System Shutdown Intelligent rEbooter), also referred to as the Shutdown Watchdog. When this feature is enabled, a Compute Instance automatically reboots if it ever powers off unexpectedly. To have a normal reboot functionality, ensure that you have enabled this feature. For more information, see the Shutdown Watchdog guide.

For those cases and others, it is helpful to know the available commands to quickly initiate a graceful system reboot.

How Do I Restart a Linux Server from the Command Line?

In this section, you learn how to reboot your Linux server using the command line. These commands work whether you are connected directly to your server’s console or are connecting to it over SSH.

How to Restart a Linux Server with the reboot Command

The most straightforward way to restart your Linux server is with the reboot command.

This command starts a graceful shutdown, letting processes exit, temporary files are removed, and other system clean up tasks.

If you need to force a reboot, you can do so with the —force option. However, this should only be used when no other option is available. This option forces a reboot without allowing the usual clean up tasks, which can lead to loss and/or corruption of data.

Читайте также:  Linux mint for tablets

How to Schedule a Restart on a Linux Server with the shutdown Command

The reboot command accomplishes the same system state as the shutdown command with the -r option and a schedule of now . The complete command is as follows:

You can safely use the above command and alter the time ( now ) to schedule when your Linux server restarts. For the time option, the shutdown command accepts either several minutes or a local time in 24-hour format. The command below, for example, schedules the server to reboot in 15 minutes.

The server then sends out a warning message to all logged-in users.

Broadcast message from root@localhost on pts/0 (Wed 2021-06-30 12:00:00 UTC): The system is going down for reboot at Wed 2021-06-30 12:15:00 UTC!

You can even send a custom message. In the example below, the server is scheduled to restart at 3:30 PM (local time), and a custom message is provided.

sudo shutdown -r 15:30 "Please wrap up your current tasks and save your work." 
Broadcast message from root@localhost on pts/0 (Wed 2021-06-30 19:15:00 UTC): Please wrap up your current tasks and save your work. The system is going down for reboot at Wed 2021-06-30 19:30:00 UTC!

Finally, you may want to cancel a scheduled reboot. You can do that with the following command:

How Do I Restart a Linux Server over PuTTY?

The process for restarting your Linux server over PuTTY is the same as above. The only difference is that you need to use PuTTY to open an SSH connection to your server.

If you are unsure how to do that, take a look at our guide on Connecting to a Remote Server Over SSH using PuTTY.

This page was originally published on Friday, August 6, 2021.

Источник

How to Restart or Reboot Linux Server from the Command Line

It’s a cliché, but true – restarting a Linux server solves a wide variety of issues.

When a system is rebooted, any malfunctioning software is purged from active memory. When the system restarts, it loads a fresh, clean copy of the software into active memory. Also, some operating systems require a restart to process updates or configuration changes.

This guide will show you how to restart a Linux server using only the command-line or prompt.

restart or reboot linux server from the command line

  • A system running a Linux operating system
  • Access to a command-line interface (also known as a terminal)
  • Root or sudo privileges
  • (optional) SSH software package for communicating with a remote server

Steps to Restart Linux using Command Prompt

Restarting Local Linux Operating System

Step 1: Open Terminal Window

If your version of Linux uses a graphical interface, you can open a terminal window by right-clicking the Desktop > left-clicking Open in terminal.

open terminal window in linux

You can also click the main menu (usually found in the lower-left or upper-left corner) and type in terminal in the search bar. Click on the Terminal icon, as in the image below.

Читайте также:  Linux зачем нужен загрузчик grub

search for terminal window in ubuntu

Step 2: Use the shutdown Command

Since powering off is one of the most basic functions of an operating system, this command should work for most distributions of Linux.

In a terminal window, type the following:

The sudo command tells Linux to run the command as an administrator, so you may need to type your password. The -r switch at the end indicates that you want the machine to restart.

Note: See our article for additional Linux shutdown command options.

Alternative Option: Restart Linux with reboot Command

Many Linux versions do not require administrator privileges to reboot. If you get a message that you do not have sufficient privileges, type:

Your system should close out of all open applications and restart.

Reboot Remote Linux Server

Step 1: Open Command Prompt

If you have a graphical interface, open the terminal by right-clicking the Desktop > left-clicking Open in terminal.

You can also click the main menu (usually found in the lower-left or upper-left corner), and then click Applications > System Tools > Terminal.

If you prefer using a keyboard shortcut, press Ctrl+Alt+T.

Step 2: Use SSH Connection Issue reboot Command

In a terminal window, type:

ssh -t user@server.com 'sudo reboot'

Note: You may need to enter the password for the username you’ve used. Also, make sure you type the single-quote marks.

The ssh command tells your system to connect to another machine. The -t option forces the remote system to enter the command in a terminal. Replace user@server.com with the username @ server name that you want to restart.

The sudo reboot command can be switched out for sudo shutdown and the above options above can be used.

That is: -r tells it to restart, hh:mm sets a specific time, +mm sets a countdown.)

In this tutorial, you have learned how to restart a Linux server from the command prompt.

Rebooting a Linux system or server is designed to be simple, so you shouldn’t have any trouble. Just make sure you have saved all your work before restarting.

Источник

reboot — Man Page

The reboot() call reboots the system, or enables/disables the reboot keystroke (abbreviated CAD, since the default is Ctrl-Alt-Delete; it can be changed using loadkeys(1)).

This system call fails (with the error EINVAL) unless magic equals LINUX_REBOOT_MAGIC1 (that is, 0xfee1dead) and magic2 equals LINUX_REBOOT_MAGIC2 (that is, 0x28121969). However, since Linux 2.1.17 also LINUX_REBOOT_MAGIC2A (that is, 0x05121996) and since Linux 2.1.97 also LINUX_REBOOT_MAGIC2B (that is, 0x16041998) and since Linux 2.5.71 also LINUX_REBOOT_MAGIC2C (that is, 0x20112000) are permitted as values for magic2. (The hexadecimal values of these constants are meaningful.)

The cmd argument can have the following values:

(RB_DISABLE_CAD, 0). CAD is disabled. This means that the CAD keystroke will cause a SIGINT signal to be sent to init (process 1), whereupon this process may decide upon a proper action (maybe: kill all processes, sync, reboot).

Читайте также:  Linux scrolling in screen

(RB_ENABLE_CAD, 0x89abcdef). CAD is enabled. This means that the CAD keystroke will immediately cause the action associated with LINUX_REBOOT_CMD_RESTART.

(RB_HALT_SYSTEM, 0xcdef0123; since Linux 1.1.76). The message «System halted.» is printed, and the system is halted. Control is given to the ROM monitor, if there is one. If not preceded by a sync(2), data will be lost.

(RB_KEXEC, 0x45584543, since Linux 2.6.13). Execute a kernel that has been loaded earlier with kexec_load(2). This option is available only if the kernel was configured with CONFIG_KEXEC.

(RB_POWER_OFF, 0x4321fedc; since Linux 2.1.30). The message «Power down.» is printed, the system is stopped, and all power is removed from the system, if possible. If not preceded by a sync(2), data will be lost.

(RB_AUTOBOOT, 0x1234567). The message «Restarting system.» is printed, and a default restart is performed immediately. If not preceded by a sync(2), data will be lost.

(0xa1b2c3d4; since Linux 2.1.30). The message «Restarting system with command ‘%s'» is printed, and a restart (using the command string given in arg) is performed immediately. If not preceded by a sync(2), data will be lost.

(RB_SW_SUSPEND, 0xd000fce1; since Linux 2.5.18). The system is suspended (hibernated) to disk. This option is available only if the kernel was configured with CONFIG_HIBERNATION.

Only the superuser may call reboot().

The precise effect of the above actions depends on the architecture. For the i386 architecture, the additional argument does not do anything at present (2.1.122), but the type of reboot can be determined by kernel command-line arguments («reboot=. «) to be either warm or cold, and either hard or through the BIOS.

Behavior inside PID namespaces

Since Linux 3.4, if reboot() is called from a PID namespace other than the initial PID namespace with one of the cmd values listed below, it performs a «reboot» of that namespace: the «init» process of the PID namespace is immediately terminated, with the effects described in pid_namespaces(7).

The values that can be supplied in cmd when calling reboot() in this case are as follows:

LINUX_REBOOT_CMD_RESTART, LINUX_REBOOT_CMD_RESTART2

The «init» process is terminated, and wait(2) in the parent process reports that the child was killed with a SIGHUP signal.

LINUX_REBOOT_CMD_POWER_OFF, LINUX_REBOOT_CMD_HALT

The «init» process is terminated, and wait(2) in the parent process reports that the child was killed with a SIGINT signal.

For the other cmd values, reboot() returns -1 and errno is set to EINVAL.

Return Value

For the values of cmd that stop or restart the system, a successful call to reboot() does not return. For the other cmd values, zero is returned on success. In all cases, -1 is returned on failure, and errno is set to indicate the error.

Errors

Problem with getting user-space data under LINUX_REBOOT_CMD_RESTART2.

The calling process has insufficient privilege to call reboot(); the caller must have the CAP_SYS_BOOT inside its user namespace.

Источник

Оцените статью
Adblock
detector