ubuntu系統(tǒng)中/etc/rc.local和/etc/init.d/rc.local的區(qū)別詳解
我們?cè)趗buntu下要把一個(gè)程序加入開(kāi)機(jī)啟動(dòng),一般可以通過(guò)修改rc.local來(lái)完成,但ubuntu下有兩個(gè)rc.local文件。分別是/etc/rc.local和/etc/init.d/rc.local??梢钥匆幌聝蓚€(gè)文件的內(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
從注釋可以看出該腳本運(yùn)行在2 3 4 5的啟動(dòng)級(jí)別,只能處理start的參數(shù),然后執(zhí)行start,如果有/etc/rc.local文件的話則執(zhí)行/etc/rc.local。如果要把開(kāi)機(jī)啟動(dòng)的程序放/etc/init.d/rc.local文件里,記住千萬(wàn)別一股腦寫(xiě)文件最后面就行了,因?yàn)樵赾ase語(yǔ)句塊里腳本就會(huì)退出。
/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
這個(gè)腳本里面基本沒(méi)有內(nèi)容,就是寫(xiě)個(gè)模板讓你放開(kāi)機(jī)自啟動(dòng)程序的。把你的程序?qū)懺趀xit 0行的前面就行了。
所以要添加開(kāi)機(jī)啟動(dòng)項(xiàng),只需在/etc/rc.local文件中添加就行了。
ubuntu的啟動(dòng)級(jí)別:
0 關(guān)機(jī)
1 單用戶
2-5 多用戶圖形界面
6 重啟
對(duì)應(yīng)每個(gè)啟動(dòng)級(jí)別,/etc/目錄下都對(duì)應(yīng)一個(gè)像/etc/rc5.d/這樣的目錄,下面是一些腳本,這些腳本基本都是對(duì)應(yīng)/etc/init.d/目錄下的軟鏈接,命名里面的數(shù)字代表優(yōu)先級(jí),啟動(dòng)時(shí)這些腳本都會(huì)執(zhí)行一遍。
備注:我的系統(tǒng)為ubuntu 15.04
總結(jié)
好了,以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)本站的支持。
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。