centos6.x 與 centos7.x 關於 shutdown 的區別

默認動作

先來看看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 等指令也是採用了這種實現方式。

發佈了10 篇原創文章 · 獲贊 16 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章