2

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 https://askubuntu.com/q/445612/26246 . I have no idea currently how to query nfs activity (or connected clients). – user.dz Apr 03 '18 at 22:15

1 Answers1

2

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.

#!/bin/bash
if [[ $(netstat -an | grep 192.168.178.22:2049) ]]; then
    env DISPLAY=:0 xset s reset
fi

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.

192.168.178.22 is the IP of my NAS and 2049 is the standard NFS port.