I have a QNAP NAS (TS-453A) that only gets used occasionally. When it’s not being accessed, I want it to automatically go to sleep so that it doesn’t consume power unnecessarily. I’m OK with having to wait for the system to resume and the disks to spin up again before accessing files.
The only method of controlling when a QNAP QTS powered NAS goes to sleep is either by manually putting the device to sleep or scheduling a sleep time via the web interface.
To solve this issue for me, I have written a shell script which checks for certain system conditions, and if it detects that the system is idle then it will suspend. The conditions it checks for are:
- > 30 minutes since resumed/booted
- < 1.7 load average over 5, 10 and 15 minutes
- No clients connected over SMB
- No clients connected over NFS
- < 40 packets per second send/received over 3 minutes
To install on a QNAP QTS powered NAS (tested on TS-453a running QTS 5.0.1):
- Copy the script to an area on a shared drive. It doesn’t have to be public, but it needs to be in a location that won’t be wiped by a QTS upgrade.
- Install vnstat. This is required for determining network activity; if you don’t care about this you can comment out the line beginning
check_packets_thresholdtowards the bottom of the script, and skip to step 3.
- Install entware-std from the Qnapclub store. This is required for the vnstat program which is used to determine network activity. If you don’t know how to do that, read this guide.
- From an SSH shell, install vnstat:
opkg install vnstat
- Make the script executable. You will need to first know the script’s location:
chmod +x /share/CACHEDEV2_DATA/Misc/suspendIfInactive.sh
- Perform a dry-run using the ‘-d’ option to make sure that everything is working. This will output the checks that have been made and whether the system would be suspended, but will not actually suspend yet:
- If all goes well, add the script to the crontab by adding the following line to
*/5 * * * * /share/CACHEDEV2_DATA/Misc/suspendIfInactive.sh
You might be tempted to edit it by running crontab -e, but don’t as it will not persist after a QTS upgrade!