问题:我们通常面临一个问题,即ubuntu操作系统被只读安装。原因很清楚,如 fstab on errors=remount-ro 中所述。
问:如果设备处于只读挂载状态,是否有任何机制可以重新启动设备。
尝试:我尝试编写如下脚本,该脚本将由看门狗监控。这有效,但如果脚本由于任何挂载点而返回出口 1 仍然是只读的,它会不断重新启动。我期望的是检查正常运行时间是否少于一天,那么即使任何挂载点都是只读的,它也不应该重新启动?
root@ubuntu1404:/home/ubuntu# cat /rofscheck.sh
#!/bin/bash
now=`date`
echo "------------"
echo "start : ${now}"
up_time=`awk '{print int($1)}' /proc/uptime`
#if uptime is less than 1 day then skip test
if [ "$up_time" -lt 86400 ]; then
echo "uptime is less ${now}, exit due to uptime"
exit 0
fi
grep -q ' ro' /proc/mounts > /dev/null 2>&1 || exit 0
# alert watchdog that fs is readonly.
exit 1
现在在/etc/watchdog.conf 中,下面的配置已经完成。
test-binary = /rofscheck.sh
要重现问题以只读挂载所有挂载的 fs,请运行以下命令:
$echo u > /proc/sysrq-trigger
紧急重新挂载只读。
这个脚本对我有用,即使它与你的非常相似。 我正在使用最新更新在 Ubuntu 14.04 64 位上运行它。
#!/bin/bash
now=$(date)
up_time=$(awk '{print int($1)}' /proc/uptime)
min_time=7200
#if uptime is less than 2 hours then skip test
if [ ${up_time} -lt ${min_time} ]; then
echo "uptime is ${up_time} secs, less than ${min_time} secs (now is ${now}): exit 0 due to uptime"
exit 0
fi
exit=$(grep ' ro,' /proc/mounts | wc -l)
if [ ${exit} -gt 0 ]; then
exit 1
else
exit 0
fi
请注意,我已将最小时间设置为变量,请在方便时进行调整。
一个小的重要通知: 我在我拥有的几个非常便宜的云服务器上使用此解决方案,我仅用于测试目的。 我还使用以下命令在每次重新启动时设置文件系统检查:
tune2fs -c 1 /dev/sda1
我永远不会在生产环境中使用这种看门狗用法。
希望这有帮助。 此致敬意。