温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》
  • 首页 > 
  • 教程 > 
  • 服务器 > 
  • ubuntu系统中/etc/rc.local和/etc/init.d/rc.local的区别有哪些

ubuntu系统中/etc/rc.local和/etc/init.d/rc.local的区别有哪些

发布时间:2021-06-22 13:43:08 来源:亿速云 阅读:95 作者:小新 栏目:服务器

小编给大家分享一下ubuntu系统中/etc/rc.local和/etc/init.d/rc.local的区别有哪些,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

/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的参数,然后执行start,如果有/etc/rc.local文件的话则执行/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

这个脚本里面基本没有内容,就是写个模板让你放开机自启动程序的。把你的程序写在exit 0行的前面就行了。

所以要添加开机启动项,只需在/etc/rc.local文件中添加就行了。

ubuntu的启动级别:

  0   关机

  1   单用户

  2-5  多用户图形界面

  6   重启 

对应每个启动级别,/etc/目录下都对应一个像/etc/rc5.d/这样的目录,下面是一些脚本,这些脚本基本都是对应/etc/init.d/目录下的软链接,命名里面的数字代表优先级,启动时这些脚本都会执行一遍。

备注:我的系统为ubuntu 15.04

以上是“ubuntu系统中/etc/rc.local和/etc/init.d/rc.local的区别有哪些”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI