mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-30 18:55:13 +08:00
🌴 Sync 2026-03-05 23:51:42
This commit is contained in:
1 parent
97c049ed0a
commit
0acff03804
14253 files changed
+3893239
No files matched your search
@@ -0,0 +1,11 @@
|
||||
|
||||
config smartinfo 'main'
|
||||
option enabled '1'
|
||||
list device '/dev/sda'
|
||||
option log_enabled '1'
|
||||
option log_path '/tmp/DiskLog'
|
||||
option time_unit 'day'
|
||||
option time_step '1'
|
||||
option touch_enabled '1'
|
||||
option touch_path '/tmp'
|
||||
|
||||
Executable
+15
@@ -0,0 +1,15 @@
|
||||
#!/bin/sh /etc/rc.common
|
||||
START=95
|
||||
|
||||
boot() {
|
||||
return 0
|
||||
}
|
||||
|
||||
start() {
|
||||
/usr/lib/smartinfo/smart_checker.sh > /dev/null 2>&1 &
|
||||
}
|
||||
|
||||
stop() {
|
||||
killall -9 smart_checker.sh
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2016 NVACG , 穿越蓝天/animefans_xj
|
||||
# af_xj@hotmail.com
|
||||
#
|
||||
#Licensed under the GNU GPL License, Version 3 (the "license");
|
||||
#you may not use this file except in compliance with the License.
|
||||
#you may obtain a copy of the License at
|
||||
#
|
||||
# http://www.gnu.org/licenses/gpl.txt
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/lib/smartinfo/smart_functions.sh
|
||||
|
||||
config_load "smartinfo"
|
||||
|
||||
init() {
|
||||
local enable time time_step time_unit log_enabled log_path touch_enable touch_path
|
||||
}
|
||||
|
||||
config_get enabled main enabled
|
||||
config_get time_step main time_step
|
||||
config_get time_unit main time_unit
|
||||
config_get log_enabled main log_enabled
|
||||
config_get log_path main log_path
|
||||
config_get touch_enabled main touch_enabled
|
||||
config_get touch_path main touch_path
|
||||
|
||||
echo "SMART CHECK SCRIPT"
|
||||
echo "Paramter ==================="
|
||||
echo "Enabled: $enabled"
|
||||
echo "Time Step: $time_step"
|
||||
echo "Time Unit: $time_unit"
|
||||
echo "Log: $log_enabled"
|
||||
echo "Log ath: $log_path"
|
||||
echo "Warn: $touch_enabled"
|
||||
echo "Warn Path: $touch_path"
|
||||
|
||||
if [ $enabled -ne 1 ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
|
||||
# 根据选定的时间间隔生成秒数
|
||||
case $time_unit in
|
||||
"minute")
|
||||
let time=time_step*60
|
||||
;;
|
||||
"hour")
|
||||
let time=time_step*3600
|
||||
;;
|
||||
"day")
|
||||
let time=time_step*86400
|
||||
;;
|
||||
"week")
|
||||
let time=time_step*604800
|
||||
;;
|
||||
*)
|
||||
let time=time_step*60
|
||||
;;
|
||||
esac
|
||||
|
||||
echo "Calculated Time: $time"
|
||||
echo ""
|
||||
|
||||
|
||||
main_process() {
|
||||
do_smart_check $1
|
||||
local RETVAL=$?
|
||||
local Device=`echo $1 |awk -F/ '{print $NF}'`
|
||||
local Model
|
||||
# 如果指定的磁盘在线则获取型号
|
||||
[ -d /sys/class/block/$Device ] && Model=`cat /sys/class/block/$Device/device/vendor``cat /sys/class/block/$Device/device/model`
|
||||
# 如果路径不存在则创建目录
|
||||
[ $log_enabled ] && ! [ -d $log_path ] && mkdir -p $log_path
|
||||
[ $touch_enabled ] && ! [ -d $touch_path ] && mkdir -p $touch_path
|
||||
case $RETVAL in
|
||||
0)
|
||||
# 设备健康
|
||||
[ $log_enabled ] && [ -d $log_path ] && echo `date '+%Y-%m-%d %H:%M'`" [$Model]: Passed Disk Check." >> $log_path/smartinfo_$Device.log
|
||||
[ -f $touch_path/$Device-DiskDamaged ] && rm $touch_path/$Device-DiskDamaged
|
||||
;;
|
||||
1)
|
||||
# 设备故障
|
||||
logger -p daemon.warn -t smartinfo "Device $1 S.M.A.R.T status Failed!"
|
||||
[ $log_enabled ] && [ -d $log_path ] && echo `date '+%Y-%m-%d %H:%M'`" [$Model]: Disk Damaged." >> $log_path/smartinfo_$Device.log
|
||||
[ $touch_enabled ] && [ -d $touch_path ] && touch $touch_path/$Device-DiskDamaged
|
||||
;;
|
||||
2)
|
||||
# 设备离线
|
||||
logger -p daemon.warn -t smartinfo "Device $1 Offline."
|
||||
[ $log_enabled ] && [ -d $log_path ] && echo `date '+%Y-%m-%d %H:%M'`" : Disk Offline." >> $log_path/smartinfo_$Device.log
|
||||
[ -f $touch_path/$Device-DiskDamaged ] && rm $touch_path/$Device-DiskDamaged
|
||||
;;
|
||||
3)
|
||||
# 不支持S.M.A.R.T
|
||||
[ $log_enabled ] && [ -d $log_path ] && echo `date '+%Y-%m-%d %H:%M'`" [$Model]: Unsupport S.M.A.R.T." >> $log_path/smartinfo_$Device.log
|
||||
[ -f $touch_path/$Device-DiskDamaged ] && rm $touch_path/$Device-DiskDamaged
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
|
||||
while [ true ]
|
||||
do
|
||||
echo `date '+%Y-%m-%d %H:%M'`" Execute the S.M.A.R.T Check."
|
||||
# 执行S.M.A.R.T检测
|
||||
config_list_foreach main device main_process
|
||||
|
||||
# 循环延迟
|
||||
sleep $time
|
||||
done
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2016 NVACG , 穿越蓝天/animefans_xj
|
||||
# af_xj@hotmail.com
|
||||
#
|
||||
#Licensed under the GNU GPL License, Version 3 (the "license");
|
||||
#you may not use this file except in compliance with the License.
|
||||
#you may obtain a copy of the License at
|
||||
#
|
||||
# http://www.gnu.org/licenses/gpl.txt
|
||||
|
||||
do_smart_check() {
|
||||
# 看看指定的设备是否在线
|
||||
if [ -b $1 ]; then
|
||||
# 如果在线,看看是否支持S.M.A.R.T。支持,则对其执行SMART检测,判断输出是否包含PASSED
|
||||
result=`/usr/sbin/smartctl -d sat -H $1`
|
||||
if [ $? -eq "2" ]; then
|
||||
# 不支持S.M.A.R.T
|
||||
return 3
|
||||
fi
|
||||
|
||||
result=`echo $result | grep -c PASSED`
|
||||
if [ $result -ne 0 ]; then
|
||||
#无故障
|
||||
return 0
|
||||
else
|
||||
#故障
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
# 设备离线
|
||||
return "2"
|
||||
fi
|
||||
}
|
||||
|
||||
do_simple_smart_check() {
|
||||
# 看看指定的设备是否在线
|
||||
if [ -b $1 ]; then
|
||||
# 如果在线,则对其执行SMART检测,判断输出是否包含PASSED
|
||||
result=`/usr/sbin/smartctl -d sat -H $1`
|
||||
if [ $? -eq "2" ]; then
|
||||
# 不支持S.M.A.R.T
|
||||
echo "$1:Unsupported"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
result=`echo $result | grep -c PASSED`
|
||||
if [ $result -ne 0 ]; then
|
||||
echo "$1:OK"
|
||||
else
|
||||
echo "$1:Failed"
|
||||
fi
|
||||
else
|
||||
# 如果不在线则输出设备离线
|
||||
echo "$1:Offline"
|
||||
fi
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/bin/sh
|
||||
# Copyright (C) 2016 NVACG , 穿越蓝天/animefans_xj
|
||||
# af_xj@hotmail.com
|
||||
#
|
||||
#Licensed under the GNU GPL License, Version 3 (the "license");
|
||||
#you may not use this file except in compliance with the License.
|
||||
#you may obtain a copy of the License at
|
||||
#
|
||||
# http://www.gnu.org/licenses/gpl.txt
|
||||
|
||||
. /lib/functions.sh
|
||||
. /usr/lib/smartinfo/smart_functions.sh
|
||||
|
||||
config_load "smartinfo"
|
||||
|
||||
# 执行S.M.A.R.T检测
|
||||
config_list_foreach main device do_simple_smart_check
|
||||
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"luci-app-smartinfo": {
|
||||
"description": "Grant UCI access for luci-app-smartinfo",
|
||||
"read": {
|
||||
"uci": [ "smartinfo" ]
|
||||
},
|
||||
"write": {
|
||||
"uci": [ "smartinfo" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"config": "smartinfo",
|
||||
"init": "smartinfo"
|
||||
}
|
||||
Reference in new issue
Block a user