[TUT] UGREEN als Nut-Server & Raspberry Pi als Nut-Client einrichten

  • Keine.
    Yes

    Ausgangslage

    Ein Raspberry Pi soll vom UGREEN NAS den Befehl zum Herunterfahren bekommen, wenn die USV das NAS über einen Stromausfall informiert.

    Voraussetzung

    Der Raspberry Pi, wie auch alle netzwerkrelevanten Komponenten (Switch, ggf. Router), müssen ebenfalls an der/einer USV hängen, sonst bekommt der Raspberry das über das Netzwerk versendete Kommando nicht mit - entweder weil er nicht mit dem Notstrom von der USV versorgt wird und/oder weil der Switch weg vom Fenster ist.

    Fangen wir an.

    Schritt 1: UGREEN NAS als NUT-Server

    Damit das NAS das Kommando an den Raspberry schicken kann, musst Du ihm sagen, dass er als NUT-Server fungieren soll.
    Aktiviere dazu den Punkt NUT-Server in Deinem UGREEN-NAS unter Systemsteuerung -> Hardware & Energie -> USV

    Schritt 2: NUT-Client auf dem Raspberry installieren

    Es braucht einen NUT-Client auf dem Raspberry (keinen Server). Dieser lauscht die ganze Zeit auf die IP und den Port des UGREEN NAS und wartet auf das Kommando zum Herunterfahren (möge es nie kommen!). Logge Dich auf der Konsole Deines Raspberry Pi ein und installiere das nötige Paket:

    • sudo apt install nut-client

    Nach der Installation wirst Du vermutlich eine Fehlermeldung bekommen:

    • ● nut-monitor.service - Network UPS Tools - power device monitor and shutdown controller
        Loaded: loaded (/lib/systemd/system/nut-monitor.service; enabled; vendor preset: enabled)
      Active: failed (Result: protocol) since Sat 2025-10-18 19:02:52 CEST; 22ms ago
      Process: 4572 ExecStart=/sbin/upsmon (code=exited, status=0/SUCCESS)
      Okt 18 19:02:52 raspberrypi systemd[1]: Starting Network UPS Tools - power device monitor and shutdown controller...
      Okt 18 19:02:52 raspberrypi upsmon[4572]: upsmon disabled, please adjust the configuration to your needs
      Okt 18 19:02:52 raspberrypi upsmon[4572]: Then set MODE to a suitable value in /etc/nut/nut.conf to enable it
      Okt 18 19:02:52 raspberrypi systemd[1]: nut-monitor.service: Can't open PID file /run/nut/upsmon.pid (yet?) after start: No such file or directory
      Okt 18 19:02:52 raspberrypi systemd[1]: nut-monitor.service: Failed with result 'protocol'.
      Okt 18 19:02:52 raspberrypi systemd[1]: Failed to start Network UPS Tools - power device monitor and shutdown controller.

    Was bedeutet das?

    • upsmon (der Monitor/Dienst) hat keine aktive Konfiguration, weil /etc/nut/nut.conf noch auf MODE=none steht.
    • Ohne gültigen MODE weiß NUT nicht, ob der Raspberry Standalone, Netclient oder Netserver sein soll.
    • Daher startet der Dienst nicht wirklich, er „meldet sich sofort ab“ und gibt diese Meldung aus.
    • Systemd erwartet beim Start eine PID-Datei von upsmon.
    • Da upsmon gar nicht richtig gestartet ist (wegen fehlendem MODE), existiert die Datei nicht.

    Lösung:

    • /etc/nut/nut.conf auf MODE=netclient setzen.
    • /etc/nut/upsmon.conf so anpassen, dass MONITOR ups0@<NAS-IP> ... slave stimmt.
    • Dienst neu starten

    Schritt 3: nut.conf editieren

    Editieren wir also zunächst einmal die nut.conf

    • sudo nano /etc/nut/nut.conf

    Füge ans Ende der Datei den Parameter MODE=netclient

    • # Network UPS Tools: example nut.conf
      #
      ##############################################################################
      # General section
      ##############################################################################
      # The MODE determines which part of the NUT is to be started, and which
      # configuration files must be modified.
      #
      # This file try to standardize the various files being found in the field, like
      # /etc/default/nut on Debian based systems, /etc/sysconfig/ups on RedHat based
      # systems, ... Distribution's init script should source this file to see which
      # component(s) has to be started.
      #
      # The values of MODE can be:
      # - none: NUT is not configured, or use the Integrated Power Management, or use
      #   some external system to startup NUT components. So nothing is to be started.
      # - standalone: This mode address a local only configuration, with 1 UPS 
      #   protecting the local system. This implies to start the 3 NUT layers (driver,
      #   upsd and upsmon) and the matching configuration files. This mode can also
      #   address UPS redundancy.
      # - netserver: same as for the standalone configuration, but also need
      #   some more network access controls (firewall, tcp-wrappers) and possibly a
      #   specific LISTEN directive in upsd.conf.
      #   Since this MODE is opened to the network, a special care should be applied
      #   to security concerns.
      # - netclient: this mode only requires upsmon.
      #
      # IMPORTANT NOTE:
      #  This file is intended to be sourced by shell scripts.
      #  You MUST NOT use spaces around the equal sign!

      MODE=netclient

    Das war es auch schon. Speichere die Datei und verlassen sie.

    Schritt 4: upsmon.conf editieren

    Nun müssen wir die Datei upsmon.confeditieren. Vorher aber brauchen wir IP, Username, Passwort und Name des NUT-Servers vom NAS. Denn diese müssen wir später in die upsmon.conf eintragen.

    Logge Dich via SSH auf dem NAS ein und öffne die Datei upsd.users.

    • sudo nano /etc/nut/upsd.users

    Die Datei sollte so oder so ähnlich aussehen:

    • [xxxxx]
      password = yyyyy
      upsmon master
      actions = SET
      instcmds = ALL

    Damit haben wir den Usernamen xxxxx und das Passwort yyyyy. Hinweis: Das sieht bei Dir anders aus.

    Merke dir diese Daten und schließe die Datei wieder.

    2. Nun musst Du herausfinden, wie die USV in der Config des NUT-Server Deines NAS heißt. Auf der Konsole des NAS gib ein:

    • sudo nano /etc/nut/upsmon.conf


    Suche nachfolgende Zeile (vermutlich ganz unten):

    • MONITOR ups0@localhost 1 xxxxx yyyyy master

    Der Name Deiner USV steht vor dem @-Zeichen. In meinem Fall lautet er ups0. Username ist xxxxx und Passwort yyyyy. Wie Du vielleicht bemerkt hast, sind Username und Passwort identisch mit den Daten aus /etc/nut/upsd.users

    Schreibe Dir den Namen der USV heraus, also bspsw. ups0

    3. Nun wechsele wieder auf die Konsole Deines Raspberrys und öffne die Datei upsmon.conf.

    Suche die Zeilen

    • # Examples: 
      #
      # MONITOR myups@bigserver 1 monmaster blah master
      # MONITOR su700@server.example.com 1 upsmon secretpass slave
      # MONITOR myups@localhost 1 upsmon pass master  (or slave)

    Trage darunter die Daten ein, die Du Dir gerade herausgeschrieben hast oder schreibe es ans Ende der Datei.

    • MONITOR NAME_USV@IP_ADRESSE_NAS 1 username password slave

    In meinem Fall sieht das so aus:

    • MONITOR ups0@192.168.0.166 1 xxxxx yyyyy slave

    Speichere und verlasse die Datei.

    Schritt 5: Neustart des Dienstes

    Nun starte den Nut-Client und den Monitor auf dem Raspberry neu und lass Dir den Status ausgeben.

    • sudo systemctl restart nut-client
    • sudo systemctl status nut-monitor

    Wenn alles gut gelaufen ist, wirst Du folgende Ausgabe sehen:

    • ● nut-monitor.service - Network UPS Tools - power device monitor and shutdown controller
        Loaded: loaded (/lib/systemd/system/nut-monitor.service; enabled; vendor preset: enabled)
        Active: active (running) since Sat 2025-10-18 19:25:04 CEST; 5s ago
       Process: 16363 ExecStart=/sbin/upsmon (code=exited, status=0/SUCCESS)
      Main PID: 16365 (upsmon)
         Tasks: 2 (limit: 4915)
        CGroup: /system.slice/nut-monitor.service
                ├─16364 /lib/nut/upsmon
                └─16365 /lib/nut/upsmon
      Okt 18 19:25:04 raspberrypi systemd[1]: Starting Network UPS Tools - power device monitor and shutdown controller...
      Okt 18 19:25:04 raspberrypi upsmon[16363]: fopen /var/run/nut/upsmon.pid: No such file or directory
      Okt 18 19:25:04 raspberrypi upsmon[16363]: UPS: ups0@192.168.0.166 (slave) (power value 1)
      Okt 18 19:25:04 raspberrypi upsmon[16363]: Using power down flag file /etc/killpower
      Okt 18 19:25:04 raspberrypi systemd[1]: nut-monitor.service: Can't open PID file /run/nut/upsmon.pid (yet?) after start: No such file or directory
      Okt 18 19:25:04 raspberrypi upsmon[16364]: Startup successful
      Okt 18 19:25:04 raspberrypi systemd[1]: nut-monitor.service: Supervising process 16365 which is not our child. We'll most likely not notice when it exits.
      Okt 18 19:25:04 raspberrypi upsmon[16365]: Init SSL without certificate database
      Okt 18 19:25:04 raspberrypi systemd[1]: Started Network UPS Tools - power device monitor and shutdown controller.

    Dein nut-monitor.service ist aktiv (running) und hat sich erfolgreich mit der USV auf dem NAS verbunden.

    Es gibt noch ein paar Fehlermelden, die aber keineswegs dramatisch sind.

    Was die Meldungen bedeuten

    • fopen /var/run/nut/upsmon.pid: No such file or directory → Das ist nur eine Warnung, weil systemd erwartet, dass upsmoneine PID-Datei erstellt. Viele aktuelle NUT-Versionen benutzen diese Datei nicht mehr, der Dienst läuft trotzdem.
    • Supervising process ... which is not our child → Ebenfalls harmlos, systemd bemerkt nur, dass upsmon ein eigener Prozess ist.

    Alles in allem: Dein Raspberry ist korrekt als NUT-Client eingerichtet und hört jetzt auf den NAS-Master.

    Schritt 6: Testen ob Du Daten bekommst

    Gib auf der Konsole des Raspberrys ein:

    • upsc NAME_DER_USV@IP_ADRESSE_DES_NAS

    Bei mir sieht das so aus:

    • upsc ups0@192.168.0.166

    Wenn dabei etwas herauskommt, das so ähnlich aussieht wie folgende Ausgabe, ist alles in Ordnung und Du solltest Werte wie battery.charge, ups.status, battery.runtime sehen.

    • Init SSL without certificate database
      battery.charge: 97
      battery.charge.low: 15
      battery.runtime: 2328
      battery.type: PbAc
      device.mfr: EATON
      device.model: Eaton 3S 850 
      device.serial: Blank
      device.type: ups
      driver.flag.ignorelb: enabled
      driver.name: usbhid-ups
      driver.parameter.pollfreq: 30
      driver.parameter.pollinterval: 2
      driver.parameter.port: auto
      driver.parameter.synchronous: auto
      driver.version: 2.8.0
      driver.version.data: MGE HID 1.46
      driver.version.internal: 0.47
      driver.version.usb: libusb-1.0.26 (API: 0x1000109)
      input.transfer.high: 264
      input.transfer.low: 184
      outlet.1.desc: PowerShare Outlet 1
      outlet.1.id: 1
      outlet.1.status: on
      outlet.1.switchable: no
      outlet.desc: Main Outlet
      outlet.id: 0
      outlet.switchable: yes
      output.frequency.nominal: 50
      output.voltage: 230.0
      output.voltage.nominal: 230
      ups.beeper.status: enabled
      ups.delay.shutdown: 20
      ups.delay.start: 30
      ups.firmware: 02.08.0010
      ups.load: 12
      ups.mfr: EATON
      ups.model: Eaton 3S 850 
      ups.power.nominal: 850
      ups.productid: ffff
      ups.realpower: 82
      ups.serial: Blank
      ups.status: OL
      ups.timer.shutdown: -1
      ups.timer.start: -1
      ups.type: offline / line interactive
      ups.vendorid: 0463


    Schritt 7: Real-Life-Test (not for the weak)

    Wenn Du mutig bist, kannst Du nun die USV vom Strom nehmen. Das bedeutet natürlich, dass das NAS dann ebenfalls am Notstrom hängt und abhängig von Deiner Konfiguration gleich oder verzögert herunterfährt. Mach das also nur, wenn Du Dir sicher bist, dass die USV das NAS auch zuverlässig mit Strom speist.

  • This threads contains 7 more posts that have been hidden for guests.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!