QNAP non va in standby: capiamolo con lo script blkdevMonitor.sh

Da pochi giorni sono un possessore di un NAS QNAP e mi sono imbattuto il un classico problema: gli HDDs non vanno in standby.

Sui forum QNAP si parla di uno script bash da lanciare via ssh, che ahimè, non è più scaricabile.

Per fortuna, girando nelle pieghe del web (aka google cache), sono riuscito a farlo riemergere dal black hole.

Ed eccolo qui in tutta la sua “splentitudine”:

#!/bin/sh
#================================================================
# Copyright (C) 2008 QNAP Systems, Inc.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#----------------------------------------------------------------
#
# blkdevMonitor_v2.sh
#
#	Abstract: 
#		A program of testing purpose on monitor block device
#
#	HISTORY:
#		2013/05/15	-	Created	- Kent
# 
#================================================================
/sbin/daemon_mgr klogd.sh stop "/etc/init.d/klogd.sh start"
/usr/bin/killall dd 2>/dev/null 1>/dev/null

MD_DEVIVES="md9 md13 md0 md1 md2"
SD_DEVIVES="sda sdb sdc sdd sde sdf sdg sdh"
Do_Log=0
MAXRUN=100
FORCE_STANDBY=0
BLKDEV_LOG=/root/blkdevMonitor_v2.log

analyse_kmsg()
{
	_klog=/.klog
	/bin/touch $_klog
	_standby=1

	# read /proc/kmsg
	while [ 1 ]; do
		/bin/dd if=/proc/kmsg of=$_klog bs=1 count=10240 2>/dev/null 1>/dev/null
		for i in $MD_DEVIVES; do
			/bin/cat $_klog | /bin/grep $i | /bin/grep "dirtied inode"
			if [ $? = 0 ]; then
				/bin/cat $_klog | /bin/grep $i | /bin/grep "dirtied inode" >> $BLKDEV_LOG
				_standby=0
			fi
			/bin/cat $_klog | /bin/grep $i | /bin/grep "block"
			if [ $? = 0 ]; then
				/bin/cat $_klog | /bin/grep $i | /bin/grep "block" >> $BLKDEV_LOG
				_standby=0
			fi
		done
		for i in $SD_DEVIVES; do
			/bin/cat $_klog | /bin/grep $i | /bin/grep "dirtied inode"
			if [ $? = 0 ]; then
				/bin/cat $_klog | /bin/grep $i | /bin/grep "dirtied inode" >> $BLKDEV_LOG
				_standby=0
			fi
			/bin/cat $_klog | /bin/grep $i | /bin/grep "block"
			if [ $? = 0 ]; then
				/bin/cat $_klog | /bin/grep $i | /bin/grep "block" >> $BLKDEV_LOG
				_standby=0
			fi
		done
		if [ $_standby = 0 ]; then
			return 1
		fi
	done
}

_countdown()
{
	/bin/sync;/bin/sync
	/bin/echo -n "Countdown: "
	cntdown=$1
	while [ ${cntdown} -gt 0 ]; do
		/bin/sleep 1
		/bin/echo -n "${cntdown} "
		cntdown=$[$cntdown-1]
	done
	echo
}

_check_standby()
{
	for i in $SD_DEVIVES; do
		/sbin/hdparm -C /dev/${i} 2>>/dev/null | /bin/grep active
		if [ $? -eq 0 ]; then
			echo /dev/${i}
			echo "Some process was waked up HDD..."
			return 1	# HDD is active
		fi
	done
	return 0
}

/bin/echo "===== Welcome to use blkdevMonitor_v2 on `/bin/date` ====="
case "$1" in
	-h)
	/bin/echo "Usage:"
	/bin/echo "  $0 [N]"
	/bin/echo "  N means that monitor block devices N times and generate N log files.(Default N = 100)"
	exit 0
	;;
esac

/bin/echo "Turn off/on VM block_dump & Clean dmesg"
/bin/echo 0 > /proc/sys/vm/block_dump
/bin/dmesg -c 2>/dev/null 1>/dev/null
/bin/dmesg -c 2>/dev/null 1>/dev/null
/bin/dmesg -c 2>/dev/null 1>/dev/null

_cnt=20
while [ ${_cnt} -gt 0 ]; do
	/bin/sync
	/bin/dmesg -c 2>/dev/null 1>/dev/null
	_cnt=$[$_cnt-1]
done
/bin/echo 1 > /proc/sys/vm/block_dump
/bin/date > /dev/null
_countdown 3
# ignore 10240 bytes
/bin/dd if=/proc/kmsg of=/dev/null bs=1 count=10240 2>/dev/null 1>/dev/null

/bin/echo "Start..."

[ "x$1" != "x" ] && MAXRUN=$1
_cnt=0

# remove log
/bin/rm -f $BLKDEV_LOG

while [ ${_cnt} -lt ${MAXRUN} ]; do
	echo "============= $_cnt/$MAXRUN test, `/bin/date` ==============="
	echo "============= $_cnt/$MAXRUN test, `/bin/date` ===============" >> $BLKDEV_LOG
	if [ $FORCE_STANDBY = 1 ]; then
		_check_standby
		if [ $? != 0 ]; then
			for i in $SD_DEVIVES; do
				# force standby
				/sbin/hdparm -y /dev/${i} 2>/dev/null 1>/dev/null
				if [ $? = 0 ]; then
					echo "Issuing standby command in /dev/${i}"
				else
					echo "/dev/${i} not found"
				fi
			done
		fi
		/bin/sleep 20
	fi
	analyse_kmsg
	_cnt=$[$_cnt+1]
	echo
	echo >> $BLKDEV_LOG
done

/bin/echo "Turn off block_dump"
/bin/echo 0 > /proc/sys/vm/block_dump

Utilizzandolo, ho capito che il mio problema era nell’app di videosorveglianza (che comunque non stavo usando)

Lascia un commento

Il tuo indirizzo email non sarà pubblicato.

The maximum upload file size: 30 MB. You can upload: image, audio, video, document, spreadsheet, interactive, text, archive, code, other. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here