溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

ubuntu系統(tǒng)中/etc/rc.local和/etc/init.d/rc.local的區(qū)別有哪些

發(fā)布時(shí)間:2021-06-22 13:43:08 來(lái)源:億速云 閱讀:102 作者:小新 欄目:服務(wù)器

小編給大家分享一下ubuntu系統(tǒng)中/etc/rc.local和/etc/init.d/rc.local的區(qū)別有哪些,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

/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

以上是“ubuntu系統(tǒng)中/etc/rc.local和/etc/init.d/rc.local的區(qū)別有哪些”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI