考虑到R4S的固件版本已经有点老旧了,遂进行了固件更新。固件更新后产生了一个问题——我使用的固件移除了默认的风扇控制功能,所以我得自己加上去。
目前使用的风扇脚本内容如下:
/etc/init.d/pwm-fan
1
2
3
4
5
|
#!/bin/sh /etc/rc.common
START=99
start() {
nohup /usr/bin/pwm-fan.sh &
}
|
/usr/bin/pwm-fan.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/bin/sh
echo "Starting pwm-fan script" >> /tmp/pwm-fan.log
echo 0 > /sys/class/pwm/pwmchip1/export
echo 0 > /sys/class/pwm/pwmchip1/pwm0/enable
echo 50000 > /sys/class/pwm/pwmchip1/pwm0/period
echo 1 > /sys/class/pwm/pwmchip1/pwm0/enable
echo 46990 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
echo "Initial fan speed set" >> /tmp/pwm-fan.log
sleep 5
echo 49990 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
echo "Fan speed adjusted" >> /tmp/pwm-fan.log
while true
do
temp=$(cat /sys/class/thermal/thermal_zone0/temp)
echo "Current temperature: $temp" >> /tmp/pwm-fan.log
if [ "$temp" -gt 40000 ] ; then
echo 30000 > /sys/class/pwm/pwmchip1/pwm0/duty_cycle
echo "Temperature high, fan speed increased" >> /tmp/pwm-fan.log
fi
sleep 10
done
|
为了避免生成的/tmp/pwm-fan.log
越来越大,使用logrotate
对日志进行管理。执行 ls -l /tmp/pwm-fan.log*
后返回
1
2
3
|
-rw-r--r-- 1 root root 405 Apr 13 17:25 /tmp/pwm-fan.log
-rw-r--r-- 1 root root 50 Apr 13 17:23 /tmp/pwm-fan.log.1.gz
-rw-r--r-- 1 root root 306 Apr 13 17:23 /tmp/pwm-fan.log.2.gz
|
ogrotate
已经成功地对 /tmp/pwm-fan.log
进行了轮换。
- 日志文件现状:
○
/tmp/pwm-fan.log
: 这是当前正在写入的日志文件,大小为 405 字节。
○ /tmp/pwm-fan.log.1.gz
: 这是最近一次被轮换出去并压缩的日志文件,大小为 50 字节。
○ /tmp/pwm-fan.log.2.gz
: 这是更早一次被轮换出去并压缩的日志文件,大小为 306 字节。
- 日志轮换成功的迹象:
○ 日志文件名的变化(如
.1.gz
和 .2.gz
)表明日志文件已经被轮换并压缩。
○ 当前日志文件 /tmp/pwm-fan.log
的大小小于轮换前的大小,说明 logrotate
已经对其进行了截断或重置。
- 验证压缩:
○ 轮换后的日志文件都被压缩,这符合配置中的
compress
选项。