I'm currently running an old computer as a NAS in my basement. It has Ubuntu 16.04 (the normal version with GUI) installed, but no monitor / keyboard / mouse attached, so kind of headless.

I would like the NAS to shutdown when it's not in use and start via WOL when someone tries to access one of the NFS shares. Starting works like a charm, but the automatic shutdown isn't.

I was trying to use the power settings from the system settings to automatically suspend after 1 hour of inactivity, but this seems to ignore NFS activity. I've also tried using xscreensaver, which has the same problem.

Does anyone have an idea on how to solve this or had a similar problem?

  • 1
    There is a possibility to use xset s reset to reset idle time counter as in this post askubuntu.com/q/445612/26246 . I have no idea currently how to query nfs activity (or connected clients). – user.dz Apr 3 '18 at 22:15

Thank you for the pointer to xset s reset user.dz!

One can use netstat -an | grep serverip:nfsport to get all active (mounted) NFS shares. If this command outputs nothing the server can shutdown without interrupting any user.

Using the standard power settings to automatically suspend and a simple script (see below) that is run periodically with a cronjob I can achieve my desired behaviour.

if [[ $(netstat -an | grep ]]; then
    env DISPLAY=:0 xset s reset

This script runs the mentioned command and checks if any output is generated. If that is the case (at least one NFS share is mounted), the idle time is reset and therefore the suspend canceled. is the IP of my NAS and 2049 is the standard NFS port.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.