默认动作
先来看看centos6.8的shutdown说明:
[root@localhost ~]# shutdown --help
Usage: shutdown [OPTION]... TIME [MESSAGE]
Bring the system down.
……
The system is brought down into maintenance (single-user) mode by default, you can change this with either the -r or -h option which specify a reboot or system halt respectively.
可以看出centos6.8的shutdown默认动作是进入单用户模式。若想真正地关机,需要添加 -h
选项。
在centos7中查阅shutdown手册:
[root@dev ~]# man shutdown
……
OPTIONS
……
-P, --poweroff
Power-off the machine (the default).
……
可以看到,centos7的shutdown默认动作是断电。所以在关机的时候就无需 -h
选项啦。
实现方式
centos6.8中shutdown是由单独的 upstart 包提供的:
[root@localhost ~]# which -a shutdown
/sbin/shutdown
[root@localhost ~]# ll /sbin/shutdown
-rwxr-xr-x. 1 root root 64496 May 11 2016 /sbin/shutdown
[root@localhost ~]# rpm -qf /sbin/shutdown
upstart-0.6.5-16.el6.x86_64
而在centos7中是却由 systemctl 来实现的:
[root@dev ~]# which -a shutdown
/usr/sbin/shutdown
[root@dev ~]# ll /usr/sbin/shutdown
lrwxrwxrwx. 1 root root 16 Oct 22 16:01 /usr/sbin/shutdown -> ../bin/systemctl
[root@dev ~]# rpm -qf /usr/bin/systemctl
systemd-219-67.el7.x86_64
至于为什么 systemctl 能表现出类似于两个指令的方式,是因为在 systemctl 执行时会对传入的指令名字进行判断,从而表现出不同的执行逻辑出来。具体参考:why-are-reboot-shutdown-and-poweroff-symlinks-to-systemctl
其实相关的 reboot、halt 等指令也是采用了这种实现方式。