Linux command line restart command

How do I shut down or reboot from a terminal?

Appendix: If your keyboard is «locked up», so you can’t enter a command like «reboot» which would run from «su» anyway, use the keyboard: hold down Alt + PrintScreen/SysRq , buttons and type «REISUB». It doesn’t have to be capital letters. It will restart your computer gently. http://blog.kember.net/articles/reisub-the-gentle-linux-restart/

@NicolasRaoul nopes, for me i see this without sudo . Failed to set wall message, ignoring: Interactive authentication required. Failed to reboot system via logind: Interactive authentication required. Failed to open /dev/initctl: Permission denied Failed to talk to init daemon.

Open your terminal with CTRL + ALT + T and do these following commands

& one more command for restart:

Another way as one of the user mentioned.

You can get more info on the shutdown command by using one of the following:

Can anyone explain why sudo halt might not perform shutdown in some cases, whereas sudo halt -p does?

Hate passwords ( sudo ) and love one-liners?

For Ubuntu 15.04 and later

This is due to Ubuntu’s shift in using systemd instead of Upstart

systemctl poweroff systemctl reboot systemctl suspend systemctl hibernate systemctl hybrid-sleep 

Since hibernate is normally disabled by default in Ubuntu systems, you can enable this by checking this answer.

For Ubuntu 14.10 or earlier

/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Stop 
/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.ConsoleKit" /org/freedesktop/ConsoleKit/Manager org.freedesktop.ConsoleKit.Manager.Restart 

Other commands you may like:

/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Suspend 

Hibernate: (if enabled on your system)

/usr/bin/dbus-send --system --print-reply --dest="org.freedesktop.UPower" /org/freedesktop/UPower org.freedesktop.UPower.Hibernate 

On 16.04 no need of sudo

sudo shutdown -h (time) (message) 

This will shutdown your computer and halt it. That is what the -h is for. Then, in the time area you can choose the shutdown delay (in minutes) and if you want you can send a broadcast message in the message area (like goodbye, or I’m shutting the thing down :P).

To restart the computer, type

sudo shutdown -r (time) (message) 

Now, instead of shutting it down and halting it, you will restart your computer once it’s shutdown. 🙂

Источник

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.

Читайте также:  Посмотреть системное время linux

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.

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:

Читайте также:  What games for linux

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.

Источник

5 Linux Commands to Shutdown and Reboot the System

On Linux, like all tasks, the shutdown and restart operations can also be done from the command line.

The commands are shutdown, halt, poweroff, reboot and REISUB keystrokes.

In this post I am going to show you how to shutdown or restart a linux system using these commands.

The commands are useful specially when you have to reboot a remote linux server, where only shell access is available and no gui.

Servers often need a restart when upgrades are installed or need to shutdown for other maintainance tasks.

The commands are available on any linux system like centos, ubuntu, debian, fedora or suse and do not require the installation of any extra packages.

1. «shutdown» command

The first command is the shutdown command and it can be used to shutdown a system or restart it. It is commonly used to shutdown or reboot both local and remote machines.

shutdown arranges for the system to be brought down in a safe way. All logged-in users are notified that the system is going down and, within the last five minutes of TIME, new logins are prevented.
shutdown [OPTION] [TIME] [MESSAGE]

To shutdown a machine call the shutdown command like this

The h option is for halt which means to stop. The second parameter is the time parameter. «now» means that shutdown the system right away.

The time parameter can be specified in minutes or hours also. For example

# shutdown -h +5 "Server is going down for upgrade. Please save your work."

The above command shall flash the message to all other logged in users and give them 5 minutes before the system goes for shutdown.

The shutdown command can be used to restart a system with the r option instead of the h option. Usage is same as before. Just replace the h option with r option.

# shutdown -r +5 "Server will restart in 5 minutes. Please save your work."

All other logged in users will see a broadcast message in their terminal like this

[[email protected] ~]# Broadcast message from [email protected] (/dev/tty1) at 21:35 . The system is going down for reboot in 5 minutes! Server will restart in 5 minutes. Please save your work.

At this point a shutdown can be cancelled by calling shutdown with «c» option.

2. «reboot» command

Next command is the reboot command. It can be used to shutdown or reboot linux.

The following command will shutdown linux.

The «p» options stands for poweroff.

To reboot linux just call the reboot command directly without any options.

This will perform a graceful shutdown and restart of the machine. This is what happens when you click restart from your menu.

Читайте также:  Astra linux китайский язык

Reboot linux forcibly

The following command will forcefully reboot the machine. This is similar to pressing the power button of the CPU. No shutdown takes place. The system will reset instantly.

The man page explains it as follows

When called with --force or when in runlevel 0 or 6, this tool invokes the reboot(2) system call itself (with REBOOTCOMMAND argument passed) and directly reboots the system. Otherwise this simply invokes the shutdown(8) tool with the appropriate arguments without passing REBOOTCOMMAND argument.

3. «halt» command

The next command is the halt command. This can shutdown a system

The halt command also has a force option, but you do not want to use it. It is supposed to shutdown the system instantly. But its behaviour may not be consistent. Desktops might hang on running this command.

4. «poweroff» command

There is another command exactly same as the halt command. It does the same things and takes the same options.

5. REISUB — R E I S U B key strokes

The above shown commands can be used when you are in control of your system. What if the system has hanged and is not responding at all. And you do not want to press the power button on the CPU which might lead to data corruption. To save from such a situation, comes the magic sysRQ keys.

A special combination of key presses that will allow you to reboot your linux system, no matter how much it is hanged. Check the wikipedia article. for more information.

A common use of the magic SysRq key is to perform a safe reboot of a Linux computer which has otherwise locked up. This can prevent a fsck being required on reboot and gives some programs a chance to save emergency backups of unsaved work.

Warning : Pressing the following keys would instantly reboot your system. Its similar to pressing the power button of your CPU or executing the reboot -f command.

Now in place of the B key we have to use R E I S U letters first. Each key does a task as mentioned below

unRaw (take control of keyboard back from X), tErminate (send SIGTERM to all processes, allowing them to terminate gracefully), kIll (send SIGKILL to all processes, forcing them to terminate immediately), Sync (flush data to disk), Unmount (remount all filesystems read-only), reBoot.

1. Hold down the Alt and SysRq (Print Screen) keys.
2. While holding those down, type the following keys in order, several seconds apart: R E I S U B
3. Computer should reboot.

Make sure to have some time gap between each of keys R E I S U B.

The sysrq feature can be controlled by changing the value of /proc/sys/kernel/sysrq. To check if sysrq is enabled on the system or not, echo the value. It should be non zero.

$ cat /proc/sys/kernel/sysrq 176

A Tech Enthusiast, Blogger, Linux Fan and a Software Developer. Writes about Computer hardware, Linux and Open Source software and coding in Python, Php and Javascript. He can be reached at [email protected] .

10 Comments

Источник

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