【OpsDEV】关于Debian7系统启动时没有执行/etc/rc.local文件

最近调试的debian7系统突然出了些异常, rc.local貌似不会在启动时执行了,  很多开机任务没有正常启动, 因此不得不在这个问题上来折腾一番。

首先查了下当前的运行级别:

xiaomo:/home/xiaomo# runlevel
N 5
然后去到对应的/etc/rc5.d/目录查看:

xiaomo:/home/xiaomo# ls /etc/rc5.d/ -al
总用量 20
drwxr-xr-x   2 root root  4096 7月  18 14:58 .
drwxr-xr-x 138 root root 12288 8月  19 15:18 ..
-rw-r--r--   1 root root   677 4月   7  2015 README
lrwxrwxrwx   1 root root    19 7月  18 14:58 S01minissdpd -> ../init.d/minissdpd
lrwxrwxrwx   1 root root    14 7月  18 13:45 S01motd -> ../init.d/motd
lrwxrwxrwx   1 root root    17 7月  18 13:46 S01rsyslog -> ../init.d/rsyslog
lrwxrwxrwx   1 root root    15 7月  18 13:46 S02acpid -> ../init.d/acpid
lrwxrwxrwx   1 root root    17 7月  18 14:57 S02anacron -> ../init.d/anacron
lrwxrwxrwx   1 root root    13 7月  18 14:57 S02atd -> ../init.d/atd
lrwxrwxrwx   1 root root    14 7月  18 13:46 S02cron -> ../init.d/cron
lrwxrwxrwx   1 root root    14 7月  18 14:57 S02dbus -> ../init.d/dbus
lrwxrwxrwx   1 root root    15 7月  18 14:57 S02exim4 -> ../init.d/exim4
lrwxrwxrwx   1 root root    16 7月  18 14:57 S02gdomap -> ../init.d/gdomap
lrwxrwxrwx   1 root root    27 7月  18 14:58 S02speech-dispatcher -> ../init.d/speech-dispatcher
lrwxrwxrwx   1 root root    13 7月  18 14:58 S02ssh -> ../init.d/ssh
lrwxrwxrwx   1 root root    22 7月  18 14:57 S03avahi-daemon -> ../init.d/avahi-daemon
lrwxrwxrwx   1 root root    19 7月  18 14:57 S03bluetooth -> ../init.d/bluetooth
lrwxrwxrwx   1 root root    25 7月  18 14:58 S03network-manager -> ../init.d/network-manager
lrwxrwxrwx   1 root root    14 7月  18 14:57 S04cups -> ../init.d/cups
lrwxrwxrwx   1 root root    22 7月  18 14:57 S04cups-browsed -> ../init.d/cups-browsed
lrwxrwxrwx   1 root root    14 7月  18 14:58 S04gdm3 -> ../init.d/gdm3
lrwxrwxrwx   1 root root    15 7月  18 14:58 S04saned -> ../init.d/saned
lrwxrwxrwx   1 root root    18 7月  18 14:58 S05bootlogs -> ../init.d/bootlogs
lrwxrwxrwx   1 root root    18 7月  18 14:58 S06rc.local -> ../init.d/rc.local
lrwxrwxrwx   1 root root    19 7月  18 14:58 S06rmnologin -> ../init.d/rmnologin
然后找到/etc/init.d/rc.local:

xiaomo:/home/xiaomo# cat /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|status)
        # No-op
        exit 0
        ;;
    *)
        echo "Usage: $0 start|stop" >&2
        exit 3
        ;;
esac
该文件会先判断/etc/rc.local的权限再运行它, 看起来没有问题; 然后又看了一下/etc/rc.local的执行权限:

xiaomo:/home/xiaomo# ls -lh /etc/rc.local 
-rwxr-xr-x 1 root root 306 7月  18 13:45 /etc/rc.local
看起来也是没有问题, 这就纳闷了, 一脸懵逼。

。。。。。。
我以为是哪里的服务卡住了, 但貌似又没有。后来是不经意间在/etc/init.d/rc.local中将 

	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
改成了

	if [ -x /etc/rc.local ]; then
	        [ "$VERBOSE" != no ] && log_begin_msg "Running local boot scripts (/etc/rc.local)"
		/bin/bash /etc/rc.local
		ES=$?
		[ "$VERBOSE" != no ] && log_end_msg $ES
		return $ES
	fi

reboot后居然可以正常运行了。 抱歉自己学疏才浅, 暂时不太明白其中的道理, 既然有执行权限怎么还需要加/bin/bash ?也不明白最初的时候为啥可以正常执行。

暂且这样吧。

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值