rc.local VS systemd in Linux 7.x

問題:Centos 7.3環(huán)境,把命令放到 /etc/rc.local后,發(fā)現(xiàn)并沒有在服務器重啟后自動執(zhí)行。

/etc/rc.local 7.x 后有變化

[root@localhost ~]# 
[root@localhost ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 6.7 (Santiago)
[root@localhost ~]# 
[root@localhost ~]# cat /etc/rc.local 
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

[root@huayd1 huayd]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@huayd1 huayd]# cat /etc/rc.local 
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

注意到 7.x的環(huán)境,多了這么一句描述:

Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure

除此之外,還有一個區(qū)別,6.x的版本中,明確說明,這個腳本是在其他所有的啟動腳本之后執(zhí)行:

This script will be executed after all the other init scripts.

但7.x的描述有了變化,不在保證 /etc/rc.local一定是在最后執(zhí)行。

this script will NOT be run after all other services.

實際上,從 7.x 版本開始,引入了 systemd 來管理服務,/etc/rc.local 是為向前兼容而保留。

--End
Mason

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容