您的位置:首页 > 运维架构

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

2016-08-19 15:58 483 查看
最近调试的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 ?也不明白最初的时候为啥可以正常执行。

暂且这样吧。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: