Home  »  ArticlesGuidesTechnologyTools   »   How to Safely Restart CentOS, RHEL, or Ubuntu Linux Servers
Safely Restart CentOS, RHEL, or Ubuntu Linux Servers

How to Safely Restart CentOS, RHEL, or Ubuntu Linux Servers

‘Safely’ is the keyword here. You can probably reboot your server by unplugging it from the socket and pressing the power button. However, that isn’t exactly safe for your data integrity. That’s why in this tutorial we will show your how to safely restart CentOS or RHEL Linux server.

As we start it is good to note that the commands here work for other Linux distros such as Arch, Ubuntu, LinuxMint, Manjaro, Debian, Fedora Linux, etc.

Different ways to Safely Restart CentOS or RHEL Linux Servers

In reality, there is no single command to gracefully reboot your CentOS or RHEL server though the current methods are generally safe in almost all situations.

The commands below will all…

  • Flush all data to disk.
  • Stop all running processes and services.
  • All file systems are unmounted.
  • The system will reboot.

shutdown command: This command can be used to schedule a power-off or reboot on your Linux system.
Example:

$ sudo shutdown -r now

The -r option signifies a reboot. Other options are -H for halt, -h for power-off, -c to cancel a scheduled shutdown, -k Don’t halt/power-off/reboot, just send warnings

now means the action should be invoked immediately. now is an alias for ‘+0‘ That is zero minutes from the time the command is run. The default is +1 (one minute). The other way to set the reboot time is to use the time string in the format 'hh:mm‘ for an hour:minutes.

shutdown allows for displaying walled messages as shown below:

$ sudo shutdown -r now "CentOS 7 webserver is going down for kernel update"

systemctl command: This is Systemd’s systemctl command that has options for shutting down or rebooting your server.
Example:

$ sudo systemctl reboot

systemctl provides a --force option. Please do not pass the –force option unless absolutely necessary such as in emergency cases where the system manager has crashed and you need to shut down the server.

See also  X-Plane 11.50 Release Available With the new Vulkan Renderer

reboot command: This is the symbolic link that is aliased to /sbin/systemctl used to restart the system.
Usage:

$ sudo reboot

The reboot command is much easier to type than the two methods above.

halt command: This is the symbolic link that is aliased to /sbin/systemctl used to shut down and halt the system.
With this command, you will still need to press the power-off button manually to power off the system.
Example:

$ sudo halt

poweroff command: This is the symbolic link that is aliased to /sbin/systemctl to power off your server machine
Example:

$ sudo poweroff

A Better Way to Safely Restart CentOS or RHEL Linux Server

One thing you may want to do before rebooting your CentOS or RHEL Linux server is to synchronize cached writes to persistent storage as the root user. This can help avoid problems especially in relation to database systems for example PostgreSQL, MySQL, and MariaDB, etc.

Use this to synchronize cached writes to persistent storage.

# sync;sync

If you are running a database server then it would be a good idea to shut it down before issuing the reboot command.
Full Example:

# sync;sync
# systemctl stop postgresql
# systemctl stop mysql # for MySQL/MariaDB
# systemctl reboot

Conclusion

That’s it! You now know a new way to safely restart CentOS or RHEL Linux servers as well as other major Linux distros such as Ubuntu, Debian, Fedora, and others.

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.

Sharing it!

See also  The C++ Standard Template Library Modifying Algorithms - Part 8

Available under:
Articles, Guides, Technology, Tools