Jump to content

Shutting down a NAS gracefully


dbraner

Recommended Posts

Ich habe im Keller ein NAS mit 2 SAT-Karten und dem Recordingservice. Das NAS ist nur aktiv, wenn es benötigt wird. Sonst ist es im Standby und wird bei Bedarf per Wake On LAN aufgeweckt. Da ich immer wieder gefragt werde, wie das automatische Standby realisiert wird, damit keine verbundenen Clients "abgehängt" werden, möchte ich hier mal einige Script-Teile als Anregung für eigene Entwicklungen posten.

 

Das Script wird per Taskplaner alle 10 Minuten gestartet.

 

Hier nun einige Tipps, wie man bestimmte Zustände ermitteln kann, um festzustellen, ob der Server ohne Beeinträchtigung eines Clients in den Standby geschickt werden kann.

 

Prüfen auf aktive Netzwerkverbindungen (die IP in Zeile 2 durch die eigene ersetzen, bei englischem Windows HERGESTELLT durch ESTABLISHED ersetzen):

   rem -- Check active network connections
  netstat -n | findstr "^.*TCP.*192\.168\.1\.5.*HERGESTELLT" >nul
  if %errorlevel% gtr 0 goto :Shutdown
  goto :NoShutdown

 

Prüfen auf aktive Aufnahme (auch hier ist Standby eine schlechte Idee, erfordert die Installation von wget). Die Pfade in den Variablen RECSTATUS und STATUSURL bitte auf eigene Umgebung anpassen:

   rem -- Check active recordings
  set RECSTATUS=C:\Tools\Var\status.xml
  set STATUSURL=http://127.0.0.1:8080/api/status.html
  wget -q %STATUSURL% -O %RECSTATUS% >nul
  type %RECSTATUS% | find /i "<recordcount>0</recordcount>" >nul
  if %errorlevel% equ 0 goto :Shutdown
  goto :NoShutdown

 

Den Server in einem bestimmten Zeitfenster niemals runterfahren:

   rem -- Uptime hours: UPSTART <= TIME < UPEND, i.e. 19-23 Uhr
  set UPSTART=19
  set UPEND=23
  rem -- Check up hours
  set HOUR=%TIME:~0,2%
  if %UPSTART% equ %UPEND% goto :Shutdown
  if %HOUR% lss %UPSTART% goto :Shutdown
  if %HOUR% geq %UPEND% goto :Shutdown
  goto :NoShutdown

 

Das eigentliche Standby (erfordert PSTools von Microsoft):

:Shutdown
  rem -- Write lock file to prevent standby on first execution
  echo Lock >C:\Temp\sdmon.lck
  rem -- Activate standby mode
  psshutdown -d -t 10 -v 00
:NoShutdown

 

Außerdem sollte man noch sicherstellen, dass bei der ersten Ausführung des Scripts der Server auf keinen Fall in Standby geht, da beim Aufwachen aus dem Standby (zumindest bei Windows XP) das Script immer ausgeführt wird. Dazu legt man einfach beim Standby eine Datei an, die dann beim Aufwachen wieder gelöscht wird.

 

   rem -- Check for first call after wakeup. Will be ignored. Should be inserted at the beginning of the script
  if not exist C:\Temp\sdmon.lck goto :CheckOtherConditions
  del C:\Temp\sdmon.lck
  goto :NoShutdown
:CheckOtherConditions
  rem Hier werden die anderen Standby-Bedingungen getestet

 

Die Standby Bedingungen lassen sich natürlich ausbauen, z.B. testen ob EPG-Update aktiv, usw.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...