Error[8]: Undefined offset: 8, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

ubuntu系统中/etc/rc.local和/etc/init.d/rc.local的区别详解

前言

我们在ubuntu下要把一个程序加入开机启动,一般可以通过修改rc.local来完成,但ubuntu下有两个rc.local文件。分别是/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 "" in
 start)
 do_start
 ;;
 restart|reload|force-reload)
 echo "Error: argument '' not supported" >&2
 exit 3
 ;;
 stop)
 ;;
 *)
 echo "Usage: /etc/rc.local start|stop" >&2
 exit 3
 ;;
esac

从注释可以看出该脚本运行在2 3 4 5的启动级别,只能处理start的参数,然后执行start,如果有/etc/rc.local文件的话则执行/etc/rc.local。如果要把开机启动的程序放/etc/init.d/rc.local文件里,记住千万别一股脑写文件最后面就行了,因为在case语句块里脚本就会退出。

#!/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

ubuntu的启动级别:

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

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

备注:

  0   关机

  1   单用户

  2-5  多用户图形界面

  6   重启 

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

总结我的系统为ubuntu 15.04

[+++]

好了,以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
ubuntu系统中etcrc.local和etcinit.drc.local的区别详解_软件运维_内存溢出

ubuntu系统中etcrc.local和etcinit.drc.local的区别详解

ubuntu系统中etcrc.local和etcinit.drc.local的区别详解,第1张

ubuntu系统中/etc/rc.local和/etc/init.d/rc.local的区别详解

前言

我们在ubuntu下要把一个程序加入开机启动,一般可以通过修改rc.local来完成,但ubuntu下有两个rc.local文件。分别是/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 "" in
 start)
 do_start
 ;;
 restart|reload|force-reload)
 echo "Error: argument '' not supported" >&2
 exit 3
 ;;
 stop)
 ;;
 *)
 echo "Usage: /etc/rc.local start|stop" >&2
 exit 3
 ;;
esac

从注释可以看出该脚本运行在2 3 4 5的启动级别,只能处理start的参数,然后执行start,如果有/etc/rc.local文件的话则执行/etc/rc.local。如果要把开机启动的程序放/etc/init.d/rc.local文件里,记住千万别一股脑写文件最后面就行了,因为在case语句块里脚本就会退出。

#!/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

ubuntu的启动级别:

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

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

备注:

  0   关机

  1   单用户

  2-5  多用户图形界面

  6   重启 

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

总结我的系统为ubuntu 15.04

好了,以上就是这篇文章的全部内容了,希望本文的内容对大家的学习或者工作能带来一定的帮助,如果有疑问大家可以留言交流,谢谢大家对脚本之家的支持。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/903995.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-15
下一篇 2022-05-15

发表评论

登录后才能评论

评论列表(0条)

保存