Shutdown
shutdown -k
如何禁用登錄?
這是(至少在 Ubuntu 上)中的
-k
選項文件:man shutdown
-k Only send out the warning messages and disable logins, do not actually bring the system down.
我最初認為這將用於
pam_nologin
鎖定登錄。但是,我對其進行了測試,執行後沒有看到/etc/nologin
createdshutdown -k
。
- 如何
shutdown -k
禁用登錄?- 之後如何重新啟用登錄
shutdown -k
?
基於 Red Hat 的發行版的使用
我相信
-k
開關只是假裝系統正在關閉,因此會列印牆上的消息,但幾乎沒有其他作用。-k Don't halt, power-off, reboot, just write wall message.
要取消關閉事件:
$ sudo shutdown -c
來自 Ubuntu 的使用
當我嘗試在 Ubuntu 12.04 上使用上述命令時,我能夠執行以下命令:
$ sudo -i $ strace -s 2000 -o sdown.log shutdown -k 23:00 Broadcast message from manny@manny (/dev/pts/1) at 20:25 ... The system is going down for maintenance in 155 minutes! $ shutdown -c shutdown: Cannot find pid of running shutdown
查看
strace
日誌文件,sdown.log
我沒有看到任何似乎表明它實際上阻止使用者登錄的任何效果。$ grep open sdown.log open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 open("/lib/x86_64-linux-gnu/libnih.so.1", O_RDONLY|O_CLOEXEC) = 3 open("/lib/x86_64-linux-gnu/libnih-dbus.so.1", O_RDONLY|O_CLOEXEC) = 3 open("/lib/x86_64-linux-gnu/libdbus-1.so.3", O_RDONLY|O_CLOEXEC) = 3 open("/lib/x86_64-linux-gnu/libc.so.6", O_RDONLY|O_CLOEXEC) = 3 open("/lib/x86_64-linux-gnu/librt.so.1", O_RDONLY|O_CLOEXEC) = 3 open("/lib/x86_64-linux-gnu/libpthread.so.0", O_RDONLY|O_CLOEXEC) = 3 open("/usr/lib/locale/locale-archive", O_RDONLY|O_CLOEXEC) = 3 open("/usr/share/locale/locale.alias", O_RDONLY|O_CLOEXEC) = 3 open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en_US.utf8/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en_US/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en.UTF-8/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en.utf8/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale/en/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en_US.UTF-8/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en_US.utf8/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en_US/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en.UTF-8/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en.utf8/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/usr/share/locale-langpack/en/LC_MESSAGES/upstart.mo", O_RDONLY) = -1 ENOENT (No such file or directory) open("/etc/localtime", O_RDONLY|O_CLOEXEC) = 3 open("/var/run/shutdown.pid", O_RDONLY) = -1 ENOENT (No such file or directory)
所以我傾向於認為手冊頁的措辭是錯誤的,因為它說
-k
開關將禁用登錄。關閉源中的錯誤?
根據@Gilles 留下的評論,他將我們定向到 的來源
shutdown.c
,特別是來自以下 URL:http ://packages.ubuntu.com/trusty/admin/upstart 。該shutdown
實用程序目前是 Ubuntu 和 CentOS 上的 Upstart 軟體包的一部分。查看原始碼,
./util/shutdown.c
請注意用於控制是否啟用/禁用使用者登錄的文件是/etc/nologin
,正如您所懷疑的那樣。該文件只從函式寫入timer_callback()
。這個函式然後被這個計時器作為回調呼叫:/* Call a timer every minute until we shutdown */ NIH_MUST (nih_timer_add_periodic (NULL, 60, (NihTimerCb)timer_callback, message));
在函式內部有這個塊,當關閉前還剩不到 5 分鐘時,
timer_callack()
它似乎正在寫入文件:/etc/nologin
/* Write /etc/nologin with less than 5 minutes remaining */ if (delay <= 5) { FILE *nologin; nologin = fopen (ETC_NOLOGIN, "w"); if (nologin) { fputs (msg, nologin); fclose (nologin); } }
交換機,
-k
僅發送警告 1 次,然後退出。{ 'k', NULL, N_("only send warnings, don't shutdown"), NULL, NULL, &warn_only, NULL },
這裡退出:
if (warn_only) exit (0);