shutdown (关闭或重新启动该系统)

瑞兹 发表于 2020-12-07 09:43
浏览次数:
在手机上阅读

在类Unix操作系统,shutdown命令关闭或重新启动该系统。

查看英文版

目录

1 shutdown 运行系统环境

2 shutdown 描述

3 shutdown 语法

4 shutdown 例子

shutdown 运行系统环境

Unix&Linux

shutdown 描述

shutdow命令使以安全的方式关闭系统。将通知所有已登录用户系统正在关闭,并且login操作被阻止。可以立即关闭系统,也可以在指定的延迟后关闭系统。

首先,通过信号 SIGTERM通知所有进程系统正在关闭。这使诸如vi的程序有时间保存正在编辑的文件,邮件和新闻处理程序有机会干净退出等。

shutdown通过发信号通知init进程来完成其工作,要求其更改运行级别。运行级别0用于停止系统,运行级别6用于重新引导系统,运行级别1用于将系统置于可以执行管理任务的状态(单用户模式)。除非指定-h-r选项,否则运行级别1是缺省值。

您的系统对于shutdown命令可能具有不同的选项集。查看您的文档以了解详细信息。

The shutdown command brings the system down in a secure way. All logged-in users are notified that the system is going down, and login operations are blocked. It is possible to shut the system down immediately, or after a specified delay.

All processes are first notified that the system is going down by the signal SIGTERM. This gives programs like vi time to save the file being edited, mail and news processing programs a chance to exit cleanly, etc.

shutdown does its job by signalling the init process, asking it to change the runlevel. Runlevel 0 is used to halt the system, runlevel 6 is used to reboot the system, and runlevel 1 is used to put the system into a state where administrative tasks can be performed (single-user mode). Runlevel 1 is the default, unless the -h or -r options are specified.

Your system may have a different set of options for the shutdown command; check your documentation for details.

查看英文版

查看中文版

shutdown 语法

shutdown [-akrhPHfFnc] [-t sec] time [message]

选件

-a 使用控制访问文件/etc/shutdown.allow来控制对shutdown命令的访问。有关更多信息,请参见下面的访问控制。
-k 不要关闭,而是像关闭一样发送警告消息。
-r shutdow后重新启动。
-h 指示系统关闭然后停止。
-P 指示系统关闭然后关闭电源。
-H 如果还指定了-h,则此选项指示系统放入支持它的系统上的引导监视器。
-f 重启后跳过fsck
-F 重启后强制执行fsck
-n 不要调用init来关闭进程;指示shutdow自行执行此操作。

不鼓励使用此选项,并且其结果并非总是可预测的。
-c 取消挂起的shutdow。(这不适用于“立即关闭”,后者不会在关闭之前等待。)使用此选项,无法给出时间参数,但是您仍然可以指定一条说明性消息,该消息将发送给所有用户。
-t sec init等待发送过程的警告和秒之间杀信号,改变到另一个运行级别之前。
time 时间参数指定何时执行shutdow操作。

时间可以不同的方式被格式化:

首先,它可以在格式的绝对时间HH 毫米,其中HH表示小时(1或2位,从023)和毫米表示小时的分钟(两位数)。

其次,它可以采用m的格式,其中m是等待的分钟数。

另外,单词现在与指定+0相同;它会立即关闭系统。
信息 将发送给所有用户的消息以及标准关闭通知。

细节

如果计划在将来shutdown,它将创建咨询文件/ etc / nologin,这将导致诸如login之类的程序不允许新用户登录。该文件是在关闭顺序开始前五分钟创建的。如果该文件在发出启动信号之前已停止(即已取消或出现问题),则shutdown会删除该文件。它还会在调用init更改运行级别之前将其删除。

-f标志的意思是“快速重启”。这只会创建一个咨询文件/ fastboot,当再次出现该文件时,系统可以对其进行测试。系统引导rc文件(“ rc”代表“ runcom”,是“ run命令”的缩写)可以测试该文件是否存在,并决定不运行fsck,因为系统已通过正确的方式关闭了。之后,引导过程应删除/ fastboot

-F标志的意思是“力量的fsck ”。这只会创建一个咨询文件/ forcefsck,再次出现该文件时,系统可以对其进行测试。引导rc文件可以测试该文件是否存在,并决定使用特殊的“ force”标志运行fsck,以便甚至检查正确卸载的文件系统。之后,引导过程应删除/ forcefsck

-n标志导致shutdow不调用初始化,但杀死所有正在运行的进程本身。然后shutdown将关闭quota,accounting和交换并卸载所有文件系统。

访问控制

如果在/ etc / inittab中存在适当的条目,则可以在按下Ctrl + Alt + Del组合键时从init调用shutdown。但是,这意味着可以物理访问控制台键盘的每个人都可以关闭系统。

为了防止这种情况,shutdow可以检查,看看是否被授权的用户登录,如果shutdow时调用-a参数(这个增加的调用关闭/ etc / inittab中),它会检查该文件在/ etc /shutdown.allow存在。然后,它将该文件中的登录名与在虚拟控制台上登录的人员列表进行比较(来自/ var / run / utmp)。仅当这些授权用户或root用户之一登录时,它才会继续。否则,它将写消息

关闭:没有授权用户登录

...到(物理)系统控制台。/etc/shutdown.allow的格式是每行一个用户名。允许使用空行和注释行(以开头)。目前,此文件中的用户数限制为32。

请注意,如果不存在/etc/shutdown.allow,则-a参数将被忽略。

停止与关机

-H选项仅设置init 环境变量 INIT_HALTHALT,和-P选项只是设置该变量POWEROFF。在关闭序列中最后一个调用halt的关闭脚本应该检查这些环境变量,并使用正确的选项调用halt,以使这些选项真正生效。

档案

/ fastboot
/ etc / inittab
/etc/init.d/halt
/etc/init.d/reboot
/etc/shutdown.allow

shutdown [-akrhPHfFnc] [-t sec] time [message]

Options

-a Control access to the shutdown command using the control access file /etc/shutdown.allow. See Access Control below for more information.
-k Do not shut down, but send the warning messages as if the shutdown were real.
-r Reboot after shutdown.
-h Instructs the system to shut down and then halt.
-P Instructs the system to shut down and then power down.
-H If -h is also specified, this option instructs the system to drop into boot monitor on systems that support it.
-f Skip fsck after reboot.
-F Force fsck after reboot.
-n Don't call init to do the shutdown of processes; instruct shutdown to do that itself.

The use of this option is discouraged, and its results are not always predictable.
-c Cancel a pending shutdown. (This does not apply to "shutdown now", which does not wait before shutting down.) With this option, it is not possible to give the time argument, but you can still specify an explanatory message that will be sent to all users.
-t sec Tell init to wait sec seconds between sending processes the warning and the kill signal, before changing to another runlevel.
time The time argument specifies when to perform the shutdown operation.

The time can be formatted in different ways:

First, it can be an absolute time in the format hh:mm, in which hh is the hour (1 or 2 digits, from 0 to 23) and mm is the minute of the hour (in two digits).

Second, it can be in the format +m, in which m is the number of minutes to wait.

Also, the word now is the same as specifying +0; it shuts the system down immediately.
message A message to be sent to all users, along with the standard shutdown notification.

Details

If a shutdown is scheduled for the future, it will create the advisory file /etc/nologin which causes programs such as login not to allow new user logins. This file is created five minutes before the shutdown sequence starts. shutdown removes this file if it is stopped before it can signal init (i.e. it is cancelled or something goes wrong). It also removes it before calling init to change the runlevel.

The -f flag means "reboot fast". This only creates an advisory file /fastboot which can be tested by the system when it comes up again. The system boot rc file ("rc" stands for "runcom", which is short for "run commands") can test if this file is present, and decide not to run fsck since the system has been shut down in the proper way. After that, the boot process should remove /fastboot.

The -F flag means "force fsck". This only creates an advisory file /forcefsck which can be tested by the system when it comes up again. The boot rc file can test if this file is present, and decide to run fsck with a special "force" flag so that even properly unmounted file systems get checked. After that, the boot process should remove /forcefsck.

The -n flag causes shutdown not to call init, but to kill all running processes itself. shutdown will then turn off quota, accounting, and swapping and unmount all file systems.

Access Control

shutdown can be called from init when the Ctrl+Alt+Del key combination is pressed, if there exists an appropriate entry in /etc/inittab. This would mean that everyone who has physical access to the console keyboard can shut the system down, however.

To prevent this, shutdown can check to see if an authorized user is logged in. If shutdown is called with the -a argument (add this to the invocation of shutdown in /etc/inittab), it checks to see if the file /etc/shutdown.allow is present. It then compares the login names in that file with the list of people that are logged in on a virtual console (from /var/run/utmp). Only if one of those authorized users or root is logged in, it will proceed. Otherwise, it will write the message

shutdown: no authorized users logged in

...to the (physical) system console. The format of /etc/shutdown.allow is one username per line. Empty lines and comment lines (prefixed by a #) are allowed. Currently there is a limit of 32 users in this file.

Note that if /etc/shutdown.allow is not present, the -a argument is ignored.

Halting vs. Powering Off

The -H option just sets the init environment variable INIT_HALT to HALT, and the -P option just sets that variable to POWEROFF. The shutdown script that calls halt as the last thing in the shutdown sequence should check these environment variables and call halt with the right options for these options to actually have any effect.

Files

/fastboot
/etc/inittab
/etc/init.d/halt
/etc/init.d/reboot
/etc/shutdown.allow

查看英文版

查看中文版

shutdown 例子

shutdown 8:00

安排系统在上午8点关闭

shutdown 20:00

安排系统在晚上8点关闭

shutdown +15 "Upgrading hardware, downtime should be minimal"

安排系统在15分钟内关闭。除了警告用户系统已关闭的正常消息外,还将为他们提供有关硬件升级的描述性消息。

shutdown now

立即关闭系统。

shutdown -r now

立即关闭系统,然后自动重新引导它。

shutdown -P now

立即关闭系统,并自动关闭系统电源。

shutdown 8:00

Schedule the system to shut down at 8 A.M.

shutdown 20:00

Schedule the system to shut down at 8 P.M.

shutdown +15 "Upgrading hardware, downtime should be minimal"

Schedule the system to shut down in fifteen minutes. Along with the normal message alerting users that the system is shutting down, they will be given the descriptive message about a hardware upgrade.

shutdown now

Bring down the system immediately.

shutdown -r now

Bring down the system immediately, and automatically reboot it.

shutdown -P now

Bring down the system immediately, and automatically power off the system.

查看英文版

查看中文版

其他命令行

sysklogd | s2p | service | sag | set | setenv | setfacl | sfdisk | sha224sum | sha256sum | sha384sum | sha512sum | sleep | stat | startx | strftime | strip | swapoff | shred |

如此好文,分享给朋友
发表评论
验证码:
评论列表
共0条