铅笔

在你的害怕中坚持的越多,你就会越自信
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

设置rc.local设置开机自启无效

Posted on 2021-10-14 20:52  黑色の铅笔  阅读(491)  评论(0编辑  收藏  举报
项目中设置了/etc/init.d/rc.local 开机启动后一直没有效果,后来找到问题是由于系统中存在了两个rc.local文件,将其改为写入到文件/etc/rc.local即可
1.判断一下rc.local有无执行权限,如果没有chmod +x一下
2.判断rc.local所处目录,如果是/etc/init.d目录下面的需验证一下/etc/rc.local文件有没有如果有的话,判断一下是不是软连接,如果不是则只会执行/etc/rc.local文件了
3.设置开机自启动的执行语句,如果是/etc/init.d/rc.local 一般卸载star()函数前面,如果写在最后面有可能还没执行到对应的语句就退出了;如果是/etc/rc.local 直接写在exit(0)前面即可
 
/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/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

  

 
这两个脚本里面都会对应的一些注释和说明,一定要仔细看一下,很有用!