diff --git a/sources/tech/20181009 6 Commands To Shutdown And Reboot The Linux System From Terminal.md b/sources/tech/20181009 6 Commands To Shutdown And Reboot The Linux System From Terminal.md deleted file mode 100644 index c119f69ebf..0000000000 --- a/sources/tech/20181009 6 Commands To Shutdown And Reboot The Linux System From Terminal.md +++ /dev/null @@ -1,331 +0,0 @@ -translating---cyleft -==== - -6 Commands To Shutdown And Reboot The Linux System From Terminal -====== -Linux administrator performing many tasks in their routine work. The system Shutdown and Reboot task also included in it. - -It’s one of the risky task for them because some times it wont come back due to some reasons and they need to spend more time on it to troubleshoot. - -These task can be performed through CLI in Linux. Most of the time Linux administrator prefer to perform these kind of tasks via CLI because they are familiar on this. - -There are few commands are available in Linux to perform these tasks and user needs to choose appropriate command to perform the task based on the requirement. - -All these commands has their own feature and allow Linux admin to use it. - -**Suggested Read :** -**(#)** [11 Methods To Find System/Server Uptime In Linux][1] -**(#)** [Tuptime – A Tool To Report The Historical And Statistical Running Time Of Linux System][2] - -When the system is initiated for Shutdown or Reboot. It will be notified to all logged-in users and processes. Also, it wont allow any new logins if the time argument is used. - -I would suggest you to double check before you perform this action because you need to follow few prerequisites to make sure everything is fine. - -Those steps are listed below. - - * Make sure you should have a console access to troubleshoot further in case any issues arise. VMWare access for VMs and IPMI/iLO/iDRAC access for physical servers. - * You have to create a ticket as per your company procedure either Incident or Change ticket and get approval - * Take the important configuration files backup and move to other servers for safety - * Verify the log files (Perform the pre-check) - * Communicate about your activity with other dependencies teams like DBA, Application, etc - * Ask them to bring down their Database service or Application service and get a confirmation from them. - * Validate the same from your end using the appropriate command to double confirm this. - * Finally reboot the system - * Verify the log files (Perform the post-check), If everything is good then move to next step. If you found something is wrong then troubleshoot accordingly. - * If it’s back to up and running, ask the dependencies team to bring up their applications. - * Monitor for some time, and communicate back to them saying everything is working fine as expected. - - - -This task can be performed using following commands. - - * **`shutdown Command:`** shutdown command used to halt, power-off or reboot the machine. - * **`halt Command:`** halt command used to halt, power-off or reboot the machine. - * **`poweroff Command:`** poweroff command used to halt, power-off or reboot the machine. - * **`reboot Command:`** reboot command used to halt, power-off or reboot the machine. - * **`init Command:`** init (short for initialization) is the first process started during booting of the computer system. - * **`systemctl Command:`** systemd is a system and service manager for Linux operating systems. - - - -### Method-1: How To Shutdown And Reboot The Linux System Using Shutdown Command - -shutdown command used to power-off or reboot a Linux remote machine or local host. It’s offering -multiple options to perform this task effectively. If the time argument is used, 5 minutes before the system goes down the /run/nologin file is created to ensure that further logins shall not be allowed. - -The general syntax is - -``` -# shutdown [OPTION] [TIME] [MESSAGE] - -``` - -Run the below command to shutdown a Linux machine immediately. It will kill all the processes immediately and will shutdown the system. - -``` -# shutdown -h now - -``` - - * **`-h:`** Equivalent to –poweroff, unless –halt is specified. - - - -Alternatively we can use the shutdown command with `halt` option to bring down the machine immediately. - -``` -# shutdown --halt now -or -# shutdown -H now - -``` - - * **`-H, --halt:`** Halt the machine. - - - -Alternatively we can use the shutdown command with `poweroff` option to bring down the machine immediately. - -``` -# shutdown --poweroff now -or -# shutdown -P now - -``` - - * **`-P, --poweroff:`** Power-off the machine (the default). - - - -Run the below command to shutdown a Linux machine immediately. It will kill all the processes immediately and will shutdown the system. - -``` -# shutdown -h now - -``` - - * **`-h:`** Equivalent to –poweroff, unless –halt is specified. - - - -If you run the below commands without time parameter, it will wait for a minute then execute the given command. - -``` -# shutdown -h -Shutdown scheduled for Mon 2018-10-08 06:42:31 EDT, use 'shutdown -c' to cancel. - -[email protected]# -Broadcast message from [email protected] (Mon 2018-10-08 06:41:31 EDT): - -The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT! - -``` - -All other logged in users can see a broadcast message in their terminal like below. - -``` -[[email protected] ~]$ -Broadcast message from [email protected] (Mon 2018-10-08 06:41:31 EDT): - -The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT! - -``` - -for Halt option. - -``` -# shutdown -H -Shutdown scheduled for Mon 2018-10-08 06:37:53 EDT, use 'shutdown -c' to cancel. - -[email protected]# -Broadcast message from [email protected] (Mon 2018-10-08 06:36:53 EDT): - -The system is going down for system halt at Mon 2018-10-08 06:37:53 EDT! - -``` - -for Poweroff option. - -``` -# shutdown -P -Shutdown scheduled for Mon 2018-10-08 06:40:07 EDT, use 'shutdown -c' to cancel. - -[email protected]# -Broadcast message from [email protected] (Mon 2018-10-08 06:39:07 EDT): - -The system is going down for power-off at Mon 2018-10-08 06:40:07 EDT! - -``` - -This can be cancelled by hitting `shutdown -c` option on your terminal. - -``` -# shutdown -c - -Broadcast message from [email protected] (Mon 2018-10-08 06:39:09 EDT): - -The system shutdown has been cancelled at Mon 2018-10-08 06:40:09 EDT! - -``` - -All other logged in users can see a broadcast message in their terminal like below. - -``` -[[email protected] ~]$ -Broadcast message from [email protected] (Mon 2018-10-08 06:41:35 EDT): - -The system shutdown has been cancelled at Mon 2018-10-08 06:42:35 EDT! - -``` - -Add a time parameter, if you want to perform shutdown or reboot in `N` seconds. Here you can add broadcast a custom message to logged-in users. In this example, we are rebooting the machine in another 5 minutes. - -``` -# shutdown -r +5 "To activate the latest Kernel" -Shutdown scheduled for Mon 2018-10-08 07:13:16 EDT, use 'shutdown -c' to cancel. - -[[email protected] ~]# -Broadcast message from [email protected] (Mon 2018-10-08 07:08:16 EDT): - -To activate the latest Kernel -The system is going down for reboot at Mon 2018-10-08 07:13:16 EDT! - -``` - -Run the below command to reboot a Linux machine immediately. It will kill all the processes immediately and will reboot the system. - -``` -# shutdown -r now - -``` - - * **`-r, --reboot:`** Reboot the machine. - - - -### Method-2: How To Shutdown And Reboot The Linux System Using reboot Command - -reboot command used to power-off or reboot a Linux remote machine or local host. Reboot command comes with two useful options. - -It will perform a graceful shutdown and restart of the machine (This is similar to your restart option which is available in your system menu). - -Run “reboot’ command without any option to reboot Linux machine. - -``` -# reboot - -``` - -Run the “reboot” command with `-p` option to power-off or shutdown the Linux machine. - -``` -# reboot -p - -``` - - * **`-p, --poweroff:`** Power-off the machine, either halt or poweroff commands is invoked. - - - -Run the “reboot” command with `-f` option to forcefully reboot the Linux machine (This is similar to pressing the power button on the CPU). - -``` -# reboot -f - -``` - - * **`-f, --force:`** Force immediate halt, power-off, or reboot. - - - -### Method-3: How To Shutdown And Reboot The Linux System Using init Command - -init (short for initialization) is the first process started during booting of the computer system. - -It will check the /etc/inittab file to decide the Linux run level. Also, allow users to perform shutdown and reboot the Linux machine. There are seven runlevels exist, from zero to six. - -**Suggested Read :** -**(#)** [How To Check All Running Services In Linux][3] - -Run the below init command to shutdown the system . - -``` -# init 0 - -``` - - * **`0:`** Halt – to shutdown the system. - - - -Run the below init command to reboot the system . - -``` -# init 6 - -``` - - * **`6:`** Reboot – to reboot the system. - - - -### Method-4: How To Shutdown The Linux System Using halt Command - -halt command used to power-off or shutdown a Linux remote machine or local host. -halt terminates all processes and shuts down the cpu. - -``` -# halt - -``` - -### Method-5: How To Shutdown The Linux System Using poweroff Command - -poweroff command used to power-off or shutdown a Linux remote machine or local host. Poweroff is exactly like halt, but it also turns off the unit itself (lights and everything on a PC). It sends an ACPI command to the board, then to the PSU, to cut the power. - -``` -# poweroff - -``` - -### Method-6: How To Shutdown And Reboot The Linux System Using systemctl Command - -Systemd is a new init system and system manager which was implemented/adapted into all the major Linux distributions over the traditional SysV init systems. - -systemd is compatible with SysV and LSB init scripts. It can work as a drop-in replacement for sysvinit system. systemd is the first process get started by kernel and holding PID 1. - -**Suggested Read :** -**(#)** [chkservice – A Tool For Managing Systemd Units From Linux Terminal][4] - -It’s a parent process for everything and Fedora 15 is the first distribution which was adapted systemd instead of upstart. - -systemctl is command line utility and primary tool to manage the systemd daemons/services such as (start, restart, stop, enable, disable, reload & status). - -systemd uses .service files Instead of bash scripts (SysVinit uses). systemd sorts all daemons into their own Linux cgroups and you can see the system hierarchy by exploring /cgroup/systemd file. - -``` -# systemctl halt -# systemctl poweroff -# systemctl reboot -# systemctl suspend -# systemctl hibernate - -``` - --------------------------------------------------------------------------------- - -via: https://www.2daygeek.com/6-commands-to-shutdown-halt-poweroff-reboot-the-linux-system/ - -作者:[Prakash Subramanian][a] -选题:[lujun9972][b] -译者:[译者ID](https://github.com/译者ID) -校对:[校对者ID](https://github.com/校对者ID) - -本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 - -[a]: https://www.2daygeek.com/author/prakash/ -[b]: https://github.com/lujun9972 -[1]: https://www.2daygeek.com/11-methods-to-find-check-system-server-uptime-in-linux/ -[2]: https://www.2daygeek.com/tuptime-a-tool-to-report-the-historical-and-statistical-running-time-of-linux-system/ -[3]: https://www.2daygeek.com/how-to-check-all-running-services-in-linux/ -[4]: https://www.2daygeek.com/chkservice-a-tool-for-managing-systemd-units-from-linux-terminal/ diff --git a/translated/tech/20181009 6 Commands To Shutdown And Reboot The Linux System From Terminal.md b/translated/tech/20181009 6 Commands To Shutdown And Reboot The Linux System From Terminal.md new file mode 100644 index 0000000000..fe273fa69e --- /dev/null +++ b/translated/tech/20181009 6 Commands To Shutdown And Reboot The Linux System From Terminal.md @@ -0,0 +1,307 @@ +重启和关闭 Linux 系统的 6 个终端命令 +====== +在 Linux 管理员的日程当中, 有很多需要执行的任务, 系统的重启和关闭就被包含其中. + +对于 Linux 管理员来说, 重启和关闭系统是其诸多风险操作中的一例, 有时候, 由于某些原因, 这些操作可能无法挽回, 他们需要更多的时间来排查问题. + +在 Linux 命令行模式下我们可以执行这些任务. 很多时候, 由于熟悉命令行, Linux 管理员更倾向于在命令行下完成这些任务. + +重启和关闭系统的 Linux 命令并不多, 用户需要根据需要, 选择合适的命令来完成任务. + +以下所有命令都有其自身特点, 并允许被 Linux 管理员使用. + +**建议阅读 :** + +**(#)** [查看系统/服务器正常运行时间的 11 个方法][1] + +**(#)** [Tuptime 一款为 Linux 系统保存历史记录, 统计运行时间工具][2] + +系统重启和关闭之始, 会通知所有已登录的用户和已注册的进程. 当然, 如果会造成冲突, 系统不会允许新的用户登入. + +执行此类操作之前, 我建议您坚持复查, 因为您只能得到很少的提示来确保这一切顺利. + +下面陈列了一些步骤. + + * 确保您拥有一个可以处理故障的终端, 以防之后可能会发生的问题. VMWare 可以访问物理服务器的虚拟机, IPMI, iLO 和 iDRAC. + * 您需要通过公司的流程, 申请修改或故障的执行权直到得到许可. + * 为安全着想, 备份重要的配置文件, 并保存到其他服务器上. + * 验证日志文件(提前检查) + * 和相关团队交流, 比如数据库管理团队, 应用团队等. + * 通知数据库和应用服务人员关闭服务, 并得到确定. + * 使用适当的命令复盘操作, 验证工作. + * 最后, 重启系统 + * 验证日志文件, 如果一切顺利, 执行下一步操作, 如果发现任何问题, 对症排查. + * 无论是回退版本还是运行程序, 通知相关团队提出申请. + * 对操作做适当守候, 并将预期的一切正常的反馈给团队 + +使用下列命令执行这项任务. + + * **`shutdown 命令:`** shutdown 命令用来为中止, 重启或切断电源 + * **`halt 命令:`** halt 命令用来为中止, 重启或切断电源 + * **`poweroff 命令:`** poweroff 命令用来为中止, 重启或切断电源 + * **`reboot 命令:`** reboot 命令用来为中止, 重启或切断电源 + * **`init 命令:`** init(initialization 的简称) 是系统启动的第一个进程. + * **`systemctl 命令:`** systemd 是 Linux 系统和服务器的管理程序. + + +### 方案 - 1: 如何使用 Shutdown 命令关闭和重启 Linux 系统 + +shutdown 命令用户关闭或重启本地和远程的 Linux 设备. 它为高效完成作业提供多个选项. 如果使用了 time 参数, 系统关闭的 5 分钟之前, /run/nologin 文件会被创建, 以确保后续的登录会被拒绝. + +通用语法如下 + +``` +# shutdown [OPTION] [TIME] [MESSAGE] + +``` + +运行下面的命令来立即关闭 Linux 设备. 它会立刻杀死所有进程, 并关闭系统. + +``` +# shutdown -h now + +``` + + * **`-h:`** 如果不特指 -halt 选项, 这等价于 -poweroff 选项. + +另外我们可以使用带有 `poweroff` 选项的 `shutdown` 命令来立即关闭设备. + +``` +# shutdown --halt now +或者 +# shutdown -H now + +``` + + * **`-H, --halt:`** 停止设备运行 + +另外我们可以使用带有 `poweroff` 选项的 `shutdown` 命令来立即关闭设备. + +``` +# shutdown --poweroff now +或者 +# shutdown -P now + +``` + + * **`-P, --poweroff:`** 切断电源 (默认). + +运行以下命令立即关闭 Linux 设备. 它将会立即杀死所有的进程并关闭系统. + +``` +# shutdown -h now + +``` + + * **`-h:`** 如果不特指 -halt 选项, 这等价于 -poweroff 选项. + +如果您没有使用 time 选项运行下面的命令, 它将会在一分钟后执行给出的命令 + +``` +# shutdown -h +Shutdown scheduled for Mon 2018-10-08 06:42:31 EDT, use 'shutdown -c' to cancel. + +[email protected]# +Broadcast message from [email protected] (Mon 2018-10-08 06:41:31 EDT): + +The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT! + +``` + +其他的登录用户都能在中断中看到如下的广播消息: + +``` +[[email protected] ~]$ +Broadcast message from [email protected] (Mon 2018-10-08 06:41:31 EDT): + +The system is going down for power-off at Mon 2018-10-08 06:42:31 EDT! + +``` + +对于使用了 Halt 选项. + +``` +# shutdown -H +Shutdown scheduled for Mon 2018-10-08 06:37:53 EDT, use 'shutdown -c' to cancel. + +[email protected]# +Broadcast message from [email protected] (Mon 2018-10-08 06:36:53 EDT): + +The system is going down for system halt at Mon 2018-10-08 06:37:53 EDT! + +``` + +对于使用了 Poweroff 选项. + +``` +# shutdown -P +Shutdown scheduled for Mon 2018-10-08 06:40:07 EDT, use 'shutdown -c' to cancel. + +[email protected]# +Broadcast message from [email protected] (Mon 2018-10-08 06:39:07 EDT): + +The system is going down for power-off at Mon 2018-10-08 06:40:07 EDT! + +``` + +可以在您的终端上敲击 `Shutdown -c` 选项取消操作. + +``` +# shutdown -c + +Broadcast message from [email protected] (Mon 2018-10-08 06:39:09 EDT): + +The system shutdown has been cancelled at Mon 2018-10-08 06:40:09 EDT! + +``` + +其他的登录用户都能在中断中看到如下的广播消息: + +``` +[[email protected] ~]$ +Broadcast message from [email protected] (Mon 2018-10-08 06:41:35 EDT): + +The system shutdown has been cancelled at Mon 2018-10-08 06:42:35 EDT! + +``` + +添加 time 参数, 如果你想在 `N` 秒之后执行关闭或重启操作. 这里, 您可以为所有登录用户添加自定义广播消息. 例如, 我们将在五分钟后重启设备. + +``` +# shutdown -r +5 "To activate the latest Kernel" +Shutdown scheduled for Mon 2018-10-08 07:13:16 EDT, use 'shutdown -c' to cancel. + +[[email protected] ~]# +Broadcast message from [email protected] (Mon 2018-10-08 07:08:16 EDT): + +To activate the latest Kernel +The system is going down for reboot at Mon 2018-10-08 07:13:16 EDT! + +``` + +运行下面的命令立即重启 Linux 设备. 它会立即杀死所有进程并且重新启动系统. + +``` +# shutdown -r now + +``` + + * **`-r, --reboot:`** 重启设备. + +### 方案 - 2: 如何通过 reboot 命令关闭和重启 Linux 系统 + +reboot 命令用于关闭和重启本地或远程设备. Reboot 命令拥有两个实用的选项. + +它能够优雅的关闭和重启设备(就好像在系统菜单中惦记重启选项一样简单). + +执行不带任何参数的 `reboot` 命令来重启 Linux 设备 + +``` +# reboot + +``` + +执行带 `-p` 参数的 `reboot` 命令来关闭 Linux 设备或切断电源 + +``` +# reboot -p + +``` + + * **`-p, --poweroff:`** 调用 halt 或 poweroff 命令, 切断设备电源. + + +执行带 `-f` 参数的 `reboot` 命令来强制重启 Linux 设备(这类似按压 CPU 上的电源键) + +``` +# reboot -f + +``` + + * **`-f, --force:`** 立刻强制中断, 切断电源或重启 + +### 方案 - 3: 如何通过 init 命令关闭和重启 Linux 系统 + +init(initialization 的简写) 是系统启动的第一个进程. + +他将会检查 /etc/inittab 文件并决定 linux 运行级别. 同时, 授权用户在 Linux 设备上执行关机或重启 操作. 这里存在从 0 到 6 的七个运行等级. + +**建议阅读 :** +**(#)** [如何检查 Linux 上所有运行的服务][3] + +执行一下 init 命令关闭系统. +``` +# init 0 + +``` + + * **`0:`** 中断 – 关闭系统. + +运行下面的 init 命令重启设备 +``` +# init 6 + +``` + + * **`6:`** 重启 – 重启设备. + +### 方案 - 4: 如何通过 halt 命令关闭和重启 Linux 系统 + +halt 命令用来切断电源或关闭远程 Linux 设备或本地主机. +中断所有进程并关闭 cpu +``` +# halt + +``` + +### 方案 - 5: 如何通过 poweroff 命令关闭和重启 Linux 系统 + +poweroff 命令用来切断电源或关闭远程 Linux 设备或本地主机. Poweroff 很像 halt, 但是它可以关闭设备自身的单元(等和其他 PC 上的任何事物). 它会为 PSU 发送 ACPI 指令, 切断电源. + +``` +# poweroff + +``` + +### 方案 - 6: 如何通过 systemctl 命令关闭和重启 Linux 系统 + +Systemd 是一款适用于所有主流 Linux 发型版的全新 init 系统和系统管理器, 而不是传统的 SysV init 系统. + +systemd 兼容与 SysV 和 LSB 脚本. 它能够替代 sysvinit 系统. systemd 是内核启动的第一个进程, 并持有序号为 1 的进程 PID. + +**建议阅读 :** +**(#)** [chkservice – 一款终端下系统单元管理工具][4] + +它是一切进程的父进程, Fedora 15 是第一个适配安装 systemd 的发行版. +It’s a parent process for everything and Fedora 15 is the first distribution which was adapted systemd instead of upstart. + +systemctl 是命令行下管理系统, 守护进程, 开启服务(如 start, restart, stop, enable, disable, reload & status)的主要工具. + +systemd 使用 .service 文件而不是 bash 脚本(SysVinit 用户使用的). systemd 将所有守护进程归与自身的 Linux cgroups 用户组下, 您可以浏览 /cgroup/systemd 文件查看系统层次等级 + +``` +# systemctl halt +# systemctl poweroff +# systemctl reboot +# systemctl suspend +# systemctl hibernate + +``` + +-------------------------------------------------------------------------------- + +via: https://www.2daygeek.com/6-commands-to-shutdown-halt-poweroff-reboot-the-linux-system/ + +作者:[Prakash Subramanian][a] +选题:[lujun9972][b] +译者:[cyleft](https://github.com/cyleft) +校对:[校对者ID](https://github.com/校对者ID) + +本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出 + +[a]: https://www.2daygeek.com/author/prakash/ +[b]: https://github.com/lujun9972 +[1]: https://www.2daygeek.com/11-methods-to-find-check-system-server-uptime-in-linux/ +[2]: https://www.2daygeek.com/tuptime-a-tool-to-report-the-historical-and-statistical-running-time-of-linux-system/ +[3]: https://www.2daygeek.com/how-to-check-all-running-services-in-linux/ +[4]: https://www.2daygeek.com/chkservice-a-tool-for-managing-systemd-units-from-linux-terminal/