Ordinary low-cost UPS realizes automatic shutdown NAS when power failure
There is a method to let ordinary low-cost UPS realizes automatic shutdown NAS when power failure, if you UPS does not support notification function
What is the ordinary low-cost UPS? Ordinary low-cost UPS is the cheap UPS, no high-end USB or network interface, only the power interface, the only advantage is that the price is cheap, you can maintain the NAS power supply for a period of time when the power is off, but because there is no communication function, In the NAS UPS configuration, the power off automatic shutdown cannot be enabled, so you can’t power off the NAS power when power fail. It is dangerous to your NAS’s datas.
First of all, buy a cheap UPS with enough power for a few minute.
The idea, in fact, is very simple, ups only connected by NAS, router connect to the city power grid, the NAS at regular intervals Ping the IP address of the router to confirm whether the power is off. If there is no problem with the ping, there is power. If the power is suddenly cut off and the ping fails, it is considered to be powered off and the shutdown command is executed.
First winscp or putty into the NAS, create a poweroff.sh file under /usr/sbin/, the content is as follows:
#!/bin/sh ping -c 1 192.168.1.1 > /dev/null ret=$? if [ $ret - Eq 0 ] then Echo ' AC Power OK ! ' else echo ' AC Power maybe off, checking again after 4 minutes ! ' sleep 240 /usr/sbin/poweroff-2.sh fi
192.168.1.1 is your router IP
winscp modify the attribute to 0755, give executable permission, the above content , it is a detection script. If the ping path is working, it means that the main power is normal. If it is no feedback, it will be checked again. Why should it be detected again? Because it is possible that your route is restarted, or what else. The situation caused the temporary ping to be no feedback, so I have to check again and confirm that.
I am here for 4 minutes, usually 4 minutes is enough for restart the route. Of course, your ups must have power for this long time.
Also why should this poweroff.sh file be placed in the /usr/sbin/ directory, because I tried to put it in some directories of the NAS itself, such as /etc or /sbin, etc. The NAS will delete it when NAS restart, my NAS type is Q 419PII. So it can only be placed in a subdirectory under /usr/.
Continue to create the poweroff-2.sh file under /usr/sbin/ as follows:
#!/bin/sh ping -c 1 192.168.1.1 > /dev/null ret=$? if [ $ret -eq 0 ] then Echo ' AC Power OK ! ' else echo ' AC Power off, shut down NAS ! ' /sbin/poweroff fi
Similarly, the winscp modification attribute is 0755, giving the executable permission. This is to confirm the script again. If the ping route is still unreachable after 4 minutes, it will be shut down.
Then modify the /etc/config/crontab file, add a
*/5 * * * * /usr/sbin/poweroff.sh
is to execute the detection script every 5 minutes, save the shutdown and restart the NAS, through the above script, get The effect is that if the power is off, the NAS will automatically shut down within 9-14 minutes. If the router is only restarted, the NAS will not be shut down within 4 minutes (reconfirmed again. NAS connects to UPS, router to the main power, router ip address 192.168.1.1), thus protecting our hard disk and data, the risk of sudden power failure is minimized, I am pro-test effective (tested on Q 419PII, theoretically support other Q home NAS, but not guaranteed for other NAS.
You can modify the detection time according to your own router ip address and UPS capabilities.
In fact, you can also write a similar script in the router to achieve automatic start NAS, but there is problem with the network wake-up of the fake QS419PII . It can’t be realized.