Nas326 Clean CLI Shutdown

Options
2»

All Replies

  • Mijzelf
    Mijzelf Posts: 2,635  Guru Member
    First Anniversary 10 Comments Friend Collector First Answer
    Options
    But as the box rewrites it's file store I cant think how to get logs saved so I can see what is happening.

    The only way I can think of is the serial port. Theoretically you could log to a flash partition, but by doing so you are (seriously?) influencing the shutdown.

    When you shutdown over telnet, with stick plugged and script running, everything is OK. How about letting the script shutdown the box using telnet?

    Have you looked at my shutdown daemon in Tweaks? It does about the same, only it's called once a minute from crond, instead of polling. Oh, and it calls poweroff.


  • Duracell
    Duracell Posts: 13  Freshman Member
    edited April 2019
    Options
    Mijzelf
    Thanks again. Thought about the serial interface but I'd have to set up a console.
    I'll have a look at your code, ta ... and I hadn't thought of telneting from the box itself :-) Worth a play.
    And while I was contemplating my fate I knocked up a "Network Monitoring Box" on an old RaspberryPI 1B that was sitting idle in my bits box. I put "raspbian stretch lite" on, apt installed loads of network tools. I wrote a small service that pings the network boxes and WOLs & telnet halts my Zyxels on "network idle". It only took a couple of hours to knock up and it could be a fun tool. And I would be able to remove my WOL daemon from all boxes and my watch&start code on the router (for the TV's - no WOL on a TV!).
    I put a listing at the end for a hoot! Surprisingly it worked!! After 3.5 decades in the business (& retired for 10 - yup I'm an IT dinosaur!) I never trust my own quick code to do that!!
    I'll still like to know what the disk issue is ... may be its some form of incompatibility with the hard drives? 2 * 6tb Seagate ST6000VN0033 IronWolf Nas. As I say the same code is fine on a NAS325v2. Same USB stick model but different hard drives. The firmware is updated of course (eg PHP is not complete on the 325 - no PDO, but ok on 326!) so it may be an issue in the 326 firmware.

    #!/bin/sh
    ########################################################################
    # Rodina.Dum Network Monitor Service
    # This service pings the Rodina.Dum Network Ip address for media and
    # pc clients in the range 192.168.11.30-192.168.11.59
    # When any of these clients appear on the network the server will
    # initaiate a WakeOnLan pings for the 3 NAS servers at
    # 192.168.11.20 192.168.11.21 & 192.168.11.22
    # If no IP addresses in that range respond within a 10 minute session
    # WOL pings will be stopped  and the NAS boxes closed.
    # Note that 192.168.11.20 & 192.168.11.21 are Zyxel Nas boxes
    # and require manual closing via a telnet command. 192.168.11.22 is a
    # Buffalo server and self closes when WOL pings are not received
    ########################################################################
    # Variables
    LOGFILE="/home/pi/netmond.log";
    STARTDAY=$(date +%d);
    ENDDAY=$(date +%d);
    STARTTIME=$(date +%s);
    ENDTIME=$(date +%s);
    TIMEDIFF=0;
    NETIP="192.168.11.";
    HOSTIP="0";
    FULLIP="0";
    RNASIP="0";
    RUSER="root";
    RPASS="joli0001";
    RCMD="halt &";
    RBYE="exit";
    RNASIP0="192.168.11.20";
    RNASIP1="192.168.11.21";
    RNASIP2="192.168.11.22";
    DEVICESTATUS=0;
    #Change Log file on startup
    savelog -l -t -c 5 $LOGFILE;
    echo $(date) "NetMonD starting" >> $LOGFILE;
    echo $(date) "NetMonD log rotated" >> $LOGFILE;
    # start of main ETERNAL loop
    while true; do
    # Check to see if the log file needs to be rotated
      ENDDAY=$(date +%d);
      if [ $ENDDAY -ne $STARTDAY ]; then
    # Date has changed
    # Reset the day counter
        STARTDAY=$(date +%d);
    # Rotate the logs
        savelog -l -t -c 5 $LOGFILE;
        echo $(date) "NetMonD Continues" >> $LOGFILE;
        echo $(date) "NetMonD log rotated" >> $LOGFILE;
      fi
    # Loop Ping to see if any of the monitored ip range boxes are on
      DEVICESTATUS=0;
      HOSTIP=30;
      while [ $HOSTIP -lt 60 ]; do
        FULLIP=$NETIP$HOSTIP;
        if ping -c 2 $FULLIP; then
          echo $(date) "$FULLIP ON = WOL" >> $LOGFILE;
          wakeonlan c8:54:4B:78:ae:04;
          wakeonlan 4c:9e:ff:40:96:77;
          wakeonlan -i 192.168.11.22 -p 2304 4c:e6:76:96:bb:bc;
    # Set device on flag and reset both time counters     
          DEVICESTATUS=1;
          STARTIME=$(date +%s);
          ENDTIME=$(date +%s);
        fi
        HOSTIP=$((HOSTIP+1));
      done
    # We now know if anything is switched on
    # And if so we have sent wake up pings to the servers
    # But if DEVICESTATUS=0 then nowt is switched on
      if [ $DEVICESTATUS -eq 0 ]; then
    #  Set end time only as no device is on
        ENDTIME=$(date +%s);
        echo $(date) "Nothing found" >> $LOGFILE;
      fi
      TIMEDIFF=$(($ENDTIME-$STARTTIME));
    # if 10 minutes has passed it time to halt the Zyxel boxes
    # This is done by a telnet session to call the halt command
      if [ $TIMEDIFF -gt 600 ]; then
    # Stop the ever growing number
        TIMEDIFF=601;
        if ping -c 2 $RNASIP0; then
    # Zyxel 0 is up so shut it   
          ( echo open ${RNASIP0}
          sleep 2
          echo ${RUSER}
          sleep 2
          echo ${RPASS}
          sleep 2
          echo ${RCMD}
          echo $(RBYE)
          ) | telnet;
          echo $(date) "NetMonD $RNASIP0 Telnet shutdown issued" >> $LOGFILE;
          echo $(date) "as no devices discovered for 10 minutes" >> $LOGFILE;
        fi
      if ping -c 2 $RNASIP1; then
    # Zyxel 1 is up so shut it
          ( echo open ${RNASIP1}
          sleep 2
          echo ${RUSER}
          sleep 2
          echo ${RPASS}
          sleep 2
          echo ${RCMD}
          echo $(RBYE)
          ) | telnet;
          echo $(date) "NetMonD $RNASIP1 Telnet shutdown issued" >> $LOGFILE;
          echo $(date) "as no devices discovered for 10 minutes" >> $LOGFILE;
        fi
    # Buffalo will do itself :-) and telnet is closed (SSH open)
      fi
    # So after a complete round we wait a minute
    sleep 60;
    #End of main loop
    done



  • Duracell
    Duracell Posts: 13  Freshman Member
    Options
    The plot thickens!  Now I have a friend who has a NAS326 with 2* 1tb Seagate IronWoilf Nas drives.  I put the same shutdown code as mine on the same model usb stick and YUP it failed to close down cleanly!  So either a) the Seagate IronWolf drives are a problem as a range, b) that model of USB stick wont umount (my alternate stick didn't either but the NAS may just be USB fussy), or c) the NAS has issues about USB initiated (only way?) internal scripts calling poweroff.
  • Mijzelf
    Mijzelf Posts: 2,635  Guru Member
    First Anniversary 10 Comments Friend Collector First Answer
    Options
     (only way?)

    Certainly not. I wrote the 'RandomTools' package, which, among other goodies, supplies a 'init.d' like directory in which the scripts are executed on package start.

  • Duracell
    Duracell Posts: 13  Freshman Member
    Options
    Mijzelf
    Ah well in that case you wouldn't like to write a Sleep.On.Idle.Daemon per chance :-).  I did but the thing don't work :-) Story of my life!
    The problem I couldn't quickly over come (NAS325v2) was how to detect a lack of WOL Magic Packets. Too low down in the network stack?  That's why my code just pings an IP range to see if anything's on (Quick, dirty and effective!).  Other than that shutting down seemed a piece of cake until I bought the NAS326!
    I think the issue will remain if I have a USB stick inserted. So it would need to be hosted either as a package install or on a small share on the main drives.
    Any thoughts on how I would go about putting it on the hard drives rather than USB would be most welcome.  If nothing else, as a dinosaur, that fact that I have 8gb drive (cheapest) using 86kb is criminal! (But in odd symmetry, the first mainframe I was a os programmer on had 8gb of disc - it filled a very large room!) 
  • Mijzelf
    Mijzelf Posts: 2,635  Guru Member
    First Anniversary 10 Comments Friend Collector First Answer
    Options
    Ah well in that case you wouldn't like to write a Sleep.On.Idle.Daemon per chance

    I already did. It's in the 'Tweaks' package. And using the 'RandomTools' package you can re-use your own script. Instructions on how to install here.

    The problem I couldn't quickly over come (NAS325v2) was how to detect a lack of WOL Magic Packets.

    The 'Tweaks' package also contains 'Medion Tweaks' (which is installed, but not visible on a non-Medion), which has a 'Fake WOL'. The Medion doesn't have a way to properly shut it down, and so I wrote a Tweak which unmounts the filesystems, and then idles forever. It was a nice trick to be able to wake it up (actually reboot) on a WOL, for which I wrote a little tool, fakewol, which is included with Tweaks. Source here. I don't know if it works with all WOL tools. Theoretically it can be pure ethernet, but this tool expects an UDP package. 

    as a dinosaur
    I reach you my hand. I can remember the new PC my boss gave me when I had to develop some tools for WindowsNT 3.51. It had a whopping 1GB disk. How would I ever be able to find my files back?

  • Duracell
    Duracell Posts: 13  Freshman Member
    Options
    Mijzelf
    Wow, thanks :-) Appreciate that and will have a look at your code. This may well save me a lot of  time :-)
    WinNT3.5.1?  I haven't got NT but do have most Win images in VM's (VirtualBox) along with several other interesting OS's (CPM anyone!). Having started on punched cards I still find the command line easier than a gui!  There's something comforting about a line of green text you just don't get from a pop up box.
  • Duracell
    Duracell Posts: 13  Freshman Member
    Answer ✓
    Options
    Mijzelf
    OK, tested your code and you wont be surprised that on the 326 it worked super.  Still miffed as my code should have worked so the 326 has a sticky usb dongle!  I'll keep digging :-)
  • Duracell
    Duracell Posts: 13  Freshman Member
    Options
    Milzelf
    Tried your code and it worked super of course.  So my problem is removed (and that of the box I set up for a friend!)
    But I am still miffed. My code SHOULD have been fine and the only real change in circumstance is that I had a USB dongle inserted. I did catch a glimpse that the NAS326 does have sticky usb issues (if I can ever find it again). So I'll keep looking to see what I can find out.
    Thanks.

Consumer Product Help Center