1,
我们用ubuntu做的一台服务器,设置了每天半夜重启一次。
最近,有客户反映服务没有起来,我ssh上去一看,放在/etc/rc.local里的命令全部没有执行。只好手工启动服务。
后来,其他客户也陆续反映过类似情况,害得我只好每天一早挨个登陆客户的服务器,查看/etc/rc.local有没有执行。但这问题不是每次出现,很不好抓。
2,
今天下决心解决这问题,顺着启动流程查看配置文件。/etc/rc.local是在/etc/init.d/rc.local中调用的:
do_start() {
if [ -x /etc/rc.local ]; then
log_begin_msg "Running local boot scripts (/etc/rc.local)"
/etc/rc.local
log_end_msg $?
fi
}
但log_begin_msg是打印到console的,我们根本没有接console,就算接了,我也没法跑到客户那里去看。
3,
我把各种log都调出来看,一番大海捞针后,在/var/log/syslog里看到:
Feb 12 17:02:53 dytune-ipcc ntpdate[3298]: can't find host ntp.ubuntu.com
Feb 12 17:02:53 dytune-ipcc ntpdate[3298]: no servers can be used, exiting
顿时引起警觉,因为我们/etc/rc.local里第一个命令就是ntpdate。
于是在自己机器上做试验,把网线拔掉,不停reboot。果然,每次/etc/rc.local里的命令都没有执行,而在console上,看到了"Running local boot scripts (/etc/rc.local)",说明问题确实是ntpdate失败引起的。
照理说,ntp失败后,应该自己退出就算了,应该接着执行下面的命令,但他却连/etc/rc.local一起退出了,这个原因还要继续研究,也希望高手有以教我。
4,
现在,我把客户服务器上的ntpdate都改到最后一行去了,再继续观察。
/etc/rc.loca有时候没有执行的问题及分析
-
- 帖子: 2841
- 注册时间: 2006-09-11 22:47
Re: /etc/rc.loca有时候没有执行的问题及分析
你可考虑把客户的 syslog 转发到你机器上,在/etc/syslog.conf 配置文件里面可以进行配置。
至于脚本,它有一种运行模式是:任何一个命令返回非零就退出。所以估计你的rc.local是以这种方式被运行的。
至于脚本,它有一种运行模式是:任何一个命令返回非零就退出。所以估计你的rc.local是以这种方式被运行的。
- dailu
- 帖子: 4
- 注册时间: 2009-02-11 18:47
Re: /etc/rc.loca有时候没有执行的问题及分析
谢楼上,重去看了/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.
应该就是这意思吧。
#!/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.
应该就是这意思吧。
- BigSnake.NET
- 帖子: 12522
- 注册时间: 2006-07-02 11:16
- 来自: 廣州
- 联系:
Re: /etc/rc.loca有时候没有执行的问题及分析
/bin/sh -e
就是这个 -e 嘛..
就是这个 -e 嘛..
^_^ ~~~
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。
要理解递归,首先要理解递归。
地球人都知道,理论上,理论跟实际是没有差别的,但实际上,理论跟实际的差别是相当大滴。