ubuntu系統(tǒng)中/etc/rc.local和/etc/init.d/rc.local的區(qū)別詳解
前言
我們在ubuntu下要把一個程序加入開機啟動,一般可以通過修改rc.local來完成,但ubuntu下有兩個rc.local文件。分別是/etc/rc.local和/etc/init.d/rc.local??梢钥匆幌聝蓚€文件的內(nèi)容找到他倆的關(guān)系:
/etc/init.d/rc.local
#! /bin/sh
### BEGIN INIT INFO
# Provides: rc.local
# Required-Start: $all
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop:
# Short-Description: Run /etc/rc.local if it exist
### END INIT INFO
PATH=/sbin:/usr/sbin:/bin:/usr/bin
. /lib/init/vars.sh
. /lib/lsb/init-functions
do_start() {
if [ -x /etc/rc.local ]; then
[ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
/etc/rc.local
ES=$?
[ "$VERBOSE" != no ] && log_end_msg $ES
return $ES
fi
}
case "$1" in
start)
do_start
;;
restart|reload|force-reload)
echo "Error: argument '$1' not supported" >&2
exit 3
;;
stop)
;;
*)
echo "Usage: $0 start|stop" >&2
exit 3
;;
esac
從注釋可以看出該腳本運行在2 3 4 5的啟動級別,只能處理start的參數(shù),然后執(zhí)行start,如果有/etc/rc.local文件的話則執(zhí)行/etc/rc.local。如果要把開機啟動的程序放/etc/init.d/rc.local文件里,記住千萬別一股腦寫文件最后面就行了,因為在case語句塊里腳本就會退出。
/etc/rc.local
#!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # In order to enable or disable this script just change the execution # bits. # # By default this script does nothing. exit 0
這個腳本里面基本沒有內(nèi)容,就是寫個模板讓你放開機自啟動程序的。把你的程序?qū)懺趀xit 0行的前面就行了。
所以要添加開機啟動項,只需在/etc/rc.local文件中添加就行了。
ubuntu的啟動級別:
0 關(guān)機
1 單用戶
2-5 多用戶圖形界面
6 重啟
對應(yīng)每個啟動級別,/etc/目錄下都對應(yīng)一個像/etc/rc5.d/這樣的目錄,下面是一些腳本,這些腳本基本都是對應(yīng)/etc/init.d/目錄下的軟鏈接,命名里面的數(shù)字代表優(yōu)先級,啟動時這些腳本都會執(zhí)行一遍。
備注:我的系統(tǒng)為ubuntu 15.04
總結(jié)
好了,以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學(xué)習(xí)或者工作能帶來一定的幫助,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。
相關(guān)文章
Linux(Ubuntu 18.04)上安裝Anaconda步驟詳解
Anaconda是最受歡迎的python數(shù)據(jù)科學(xué)和機器學(xué)習(xí)平臺,用于大規(guī)模數(shù)據(jù)處理,預(yù)測分析和科學(xué)計算。這篇文章主要介紹了Linux(Ubuntu 18.04)上安裝Anaconda的方法,需要的朋友可以參考下2018-11-11
ubuntu下kvm 命令行安裝64位ubuntu報"Couldn''t find hvm kernel for Ubu
這篇文章主要介紹了ubuntu下kvm 命令行安裝64位ubuntu報"Couldn't find hvm kernel for Ubuntu tree."的問題分析的相關(guān)資料,需要的朋友可以參考下2016-11-11

