unRaid script to automatically spin up drives when network media player is used


Recommended Posts

Attached is a  zip file containing a script for the unRaid server that may help somebody who uses network media players that time-out waiting for the unRaid disks to spin up.

 

I have  two Al-Tech MG-35  media players.  They work very well on my LAN and allow me to access the ISO images of movies held on the unRaid server when I'm in my den and bedroom.

 

The MG-35 is capable of playing from its internal hard-disk, or from a network share.  Unfortunately, it does not allow sufficient time when accessing a file to allow the unRaid server to spin up its disks.  Instead, it times-out, decides the share folder is not accessible on the lan, and removes the share folder from its file browser display.  The only way to get it back is to exit back to the main select screen, select "Network Media" a second time, then select from the list of machines with shared folders a second time, then to select "Tower" (the unRaid server) a second time, then to select the "Movies" folder a second time, and lastly, to select the movie a second time.

 

With any luck, the drive will have spun up to speed... if not... I have to do it all a third time...  >:(

 

To make life a bit easier, I wrote a script to poll my network looking for my MG-35 media players.  If either one  powered on, it is detected, and the unRaid drives are spun up.  This way, the MG-35 does not time-out, and it is much easier on  me and my family.  I select a movie, and it plays...  ;D

 

To install this, unzip it to the same folder on your flash drive where bzroot, bzimage, syslinux.cfg reside.  If you "telnet" into unRaid, this will be found at /boot

Edit: I replaced the attached zip file.  The original attachment was outdated and did not work once the security was applied and a password added. 

 

Then, using Word-Pad  (not NOTEPAD, or MS-WORD) edit it to enter in the IP addresses of your media player(s).  This script  expects them to be at fixed addresses.  It also expects them to respond to a network "ping" command.

 

netcat is not needed with new version of script, it no longer uses hdparm either.

There are two possible methods to determine if the drives are currently spinning, one variable in the script can be set to yes/no to choose one or the other.  Odds are you will not need to change the setting you find in the file.  I currently have it set to read the status from the unRaid management web-page.  As an alternative, it can use the hdparm -C /dev/hdx command.  I know the hdparm command works with my all IDE based unRaid array.  I don't know if it works with an SATA based array.

 

You will also need a copy  of  "nc" (netcat).  You can find a copy in the thread describing "Email Notification of unRaid status"

http://lime-technology.com/forum/index.php?topic=911.0  Put it in the same folder on your flash drive as bzroot, bzimage, syslinux.cfg if you have not yet put it there from the installation of one of my other scripts.

next, type the following command to make the script executable:

chmod +x spin_drives.sh

 

Lastly, add a line to the end of your "go" script to invoke the spin_drives.sh script every time you reboot the server.

 

Mine now looks like this:

#!/bin/bash

# Start the Management Utility

/usr/local/sbin/emhttp &

sleep  30

for i in /dev/md*

do

  blockdev --setra 2048 $i

done

cp /boot/smtp_check_unraid.sh /etc/cron.hourly/

/boot/spin_drives.sh &

 

If you want to invoke this from the telnet command you will need to invoke it in a way so it does not terminate when you close the telnet window.

 

To do that you need to use the "nohup" command like this:

nohup /boot/spin_drives.sh >/dev/null 2>/dev/null &

 

The script will not spin up drives unless the array is in a "Started" state.  It will also only allow one instance of itself to be run at a time.

It creates a lock file in /var/lock/ to track if it is running.  It also logs every time it spins up the drives in /var/log/spin_up.log

 

This has made the MG-35 much easier to use with network based media for my family.  I no longer get time-outs as drives spin-up.

Once I power off my media players, the drives spin down as usual after their normal delay.

 

Joe L.

 

Link to comment

I know the hdparm command works with my all IDE based unRaid array.  I don't know if it works with an SATA based array.

 

Hi Joe,

 

your script worked perfectly for me.  I chose the 'hdparm' method on a mixed IDE & Sata array and it worked equally well on both types of drives.

 

Many thanks for another excellent script,

 

Mark.

Link to comment

Hi Joe,

 

I think I've come across a limitation of your Spin-Up script.  It would appear that the lock file is still present after a reboot so when the 'go' script tries to run the spin-up script it think an instance is already running and doesn't appear to run.

 

I'm not 100% sure this is what is happening, but everything worked fine yesterday but doesn't appear to be working today after a reboot.

 

As a test I stopped my array via the browser, manually deleted the '/var/lock/spin_up_drives' lock file via telnet and rebooted with the Media Player turned off.  The 'spin_up_drives' flag file was not created.

 

I then started the media player and the 'spin_up_dives' file was created.

 

I turned off the media player again, stopped the array (without manually deleting the 'spin_up_drives' lock file) and rebooted a 2nd time.  The 'spin_up_drives' lock file was still present which I assume is stopping the script running because it thinks there is already an instance running.

 

Is there a way to compare the date&time of 'spin_up_drives' to the date & time of the last reboot?  or some other method to check whether an instance of the script is still running?

 

Thanks,

 

Mark.

Link to comment

Hi Joe,

 

I think I've come across a limitation of your Spin-Up script.  It would appear that the lock file is still present after a reboot so when the 'go' script tries to run the spin-up script it think an instance is already running and doesn't appear to run.

 

I'm not 100% sure this is what is happening, but everything worked fine yesterday but doesn't appear to be working today after a reboot.

 

As a test I stopped my array via the browser, manually deleted the '/var/lock/spin_up_drives' lock file via telnet and rebooted with the Media Player turned off.  The 'spin_up_drives' flag file was not created.

 

I then started the media player and the 'spin_up_dives' file was created.

 

I turned off the media player again, stopped the array (without manually deleting the 'spin_up_drives' lock file) and rebooted a 2nd time.  The 'spin_up_drives' lock file was still present which I assume is stopping the script running because it thinks there is already an instance running.

 

Is there a way to compare the date&time of 'spin_up_drives' to the date & time of the last reboot?  or some other method to check whether an instance of the script is still running?

 

Thanks,

 

Mark.

Mark,

Did you by any chance move the lock file to a different folder?  I create the lockfile in /var/lock.  That folder exists only in memory and should be entirely back to its original state when unRaid is rebooted.  In other words, I don't know how the file can stay around through a reboot.

 

The only way for it to have persistence would be if it were stored on the flash drive, or one of your disk drives.

Something else is probably the underlying cause of the issue.

 

To see if the spin_drives.sh script is running, type

ps -ef

 

The output will look something like this..

.

root      1211    1  0 Sep21 tty5    00:00:00 /sbin/agetty 38400 tty5 linux

root      1214    1  0 Sep21 tty6    00:00:00 /sbin/agetty 38400 tty6 linux

root      1686    1  0 Sep23 ?        00:00:00 /bin/bash /boot/spin_drives.sh

root    18242 27482  0 Sep24 ?        00:00:17 /usr/sbin/smbd -D -l /dev/null

root    20677  1007  0 Sep24 ?        00:00:00 in.telnetd: 192.168.2.6

root    20678 20677  0 Sep24 pts/0    00:00:00 -bash

root    22329    2  0 Sep22 ?        00:00:18 [unraidd]

root    22388    2  0 Sep22 ?        00:00:00 [reiserfs/0]

root    22392    1  0 Sep22 ?        00:02:14 shfs /mnt/user 0

root    26367  1686  0 12:21 ?        00:00:00 ping -q -c 1 192.168.2.21

root    26368  1686  0 12:21 ?        00:00:00 grep 1 received,

root    26369 20678  0 12:21 pts/0    00:00:00 ps -ef

root    27482    1  0 Sep24 ?        00:00:00 /usr/sbin/smbd -D -l /dev/null

root    27483 27482  0 Sep24 ?        00:00:00 /usr/sbin/smbd -D -l /dev/null

 

In my case, there are the main script has process ID 1686 (second column in above listing) , and it has two children processes (third column = 1686) that are the "ping" and "grep" command looking for the string to be matched.

 

if you type:

cat /var/lock/spin_up_drives

 

you will see it contains the process ID of the script that created it.

 

So... I can determine if the lock file is valid by reading its contents and then looking at the process list to determine if it is a valid file.

I might be able to add that.... but, the file should never survive a reboot.  (It should stay running when you stop and re-start the array, it will just not do anything until the array is in a started state)

 

To stop the spin_drives script, the easiest way is to use the "ps -ef" command to find the process ID of the script (in my case 1686) and send it a kill signal like this:

kill 1686

 

you could also do this to have the kill use the value in the lock file

cat /var/lock/spin_up_lock | xargs kill

 

When sent a kill signal, the script will automatically remove the lock file.  (Do not use "kill -9", just plain "kill")

 

It might be possible that you rebooted, the script was invoked before the array was started.  If the array is not in a started state, the script sleeps for 20 seconds before checking again.  It continues to check every 20 seconds. During the interim, it will not spin up drives.

 

Once the array has been in a started state for 20 seconds or more, it should spin up the drives.  Once it spins up the drives, it goes to sleep for 500 seconds.

 

So, perhaps you stopped the array after it had done its initial spin up, while it was sleeping 500 seconds and then re-started the array before the 500 seconds was up.  If that is the case, then it would not notice your media player for the remainder of the 500 second interval.

 

The ps -ef command should give you some idea of what it is doing when invoked from the "go" script.  If you see "Sleep 20, or Sleep 500" you will know what it is up to.

 

The sleep intervals I choose were purely arbitrary... feel free to adjust them.  I figured if I just spun up the drives, no need to do anything for a while.

 

Joe L.

Link to comment

Hi Joe,

 

I haven't moved the lock file anywhere, it is entirely possible that I acted too quickly, before the file had been created the first time.  I'll do more research:)

 

The main symptom I have is that yesterday I manually invoked the script for the first time (as per the instructions in this thread) and check the status of my disks which were powered down.  I switched on my media player and all the drives spun up as they should and navigation of the player was just right.  I powered off and after an hour all were asleep again.

 

After a reboot this morning I have a running instance of /bin/bash /boot/spin_drives.sh listed, but the drives are not spinning up & down as they did yesterday.  I was hunting for a reason why this may have been.

 

Thanks,

 

Mark.

Link to comment

Linux 2.6.20.

root@Tower:~# ps -ef

UID        PID  PPID  C STIME TTY          TIME CMD

root        1    0  0 16:16 ?        00:00:02 init

root        2    1  0 16:16 ?        00:00:00 [ksoftirqd/0]

root        3    1  0 16:16 ?        00:00:00 [events/0]

root        4    1  0 16:16 ?        00:00:00 [khelper]

root        5    1  0 16:16 ?        00:00:00 [kthread]

root        48    5  0 16:16 ?        00:00:00 [kblockd/0]

root        49    5  0 16:16 ?        00:00:00 [kacpid]

root      131    5  0 16:16 ?        00:00:00 [ksuspend_usbd]

root      134    5  0 16:16 ?        00:00:00 [khubd]

root      136    5  0 16:16 ?        00:00:00 [kseriod]

root      159    5  0 16:16 ?        00:00:00 [pdflush]

root      160    5  0 16:16 ?        00:00:00 [pdflush]

root      161    5  0 16:16 ?        00:00:02 [kswapd0]

root      162    5  0 16:16 ?        00:00:00 [aio/0]

root      351    5  0 16:16 ?        00:00:00 [scsi_eh_0]

root      352    5  0 16:16 ?        00:00:00 [usb-storage]

root      429    1  0 16:16 ?        00:00:00 /sbin/udevd --daemon

root      600    5  0 16:16 ?        00:00:00 [ata/0]

root      604    5  0 16:16 ?        00:00:00 [ata_aux]

root      605    5  0 16:16 ?        00:00:00 [scsi_eh_1]

root      606    5  0 16:16 ?        00:00:00 [scsi_eh_2]

root      782    5  0 16:16 ?        00:00:00 [scsi_eh_3]

root      783    5  0 16:16 ?        00:00:00 [scsi_eh_4]

root      784    5  0 16:16 ?        00:00:00 [scsi_eh_5]

root      785    5  0 16:16 ?        00:00:00 [scsi_eh_6]

root      953    1  0 16:16 ?        00:00:00 /usr/sbin/syslogd -m0

root      956    1  0 16:16 ?        00:00:00 /usr/sbin/klogd -c 3 -x

root      1054    1  0 16:16 ?        00:00:00 /usr/sbin/inetd

root      1065    1  0 16:16 ?        00:00:00 /usr/sbin/crond -l10

daemon    1067    1  0 16:16 ?        00:00:00 /usr/sbin/atd -b 15 -l 1

root      1070    1  0 16:16 ?        00:00:00 /usr/sbin/acpid

root      1076    1  0 16:16 ?        00:00:00 /usr/sbin/ifplugd -i eth0 -fwI -

root      1108    1  0 16:16 ?        00:00:00 /usr/local/sbin/emhttp

root      1114    5  0 16:16 ?        00:00:00 [mdrecoveryd]

root      1138    5  0 16:16 ?        00:00:01 [unraidd]

root      1207    5  0 16:16 ?        00:00:00 [reiserfs/0]

root      1236    1  0 16:16 ?        00:00:00 /usr/sbin/nmbd -D

root      1238    1  0 16:16 ?        00:00:00 /usr/sbin/smbd -D

root      1239  1238  0 16:16 ?        00:00:00 /usr/sbin/smbd -D

root      1252    1  0 16:17 ?        00:00:00 /bin/bash /boot/spin_drives.sh

root      1253    1  0 16:17 tty1    00:00:00 /sbin/agetty 38400 tty1 linux

root      1254    1  0 16:17 tty2    00:00:00 /sbin/agetty 38400 tty2 linux

root      1255    1  0 16:17 tty3    00:00:00 /sbin/agetty 38400 tty3 linux

root      1267    1  0 16:17 tty4    00:00:00 /sbin/agetty 38400 tty4 linux

root      1270    1  0 16:17 tty5    00:00:00 /sbin/agetty 38400 tty5 linux

root      1271    1  0 16:17 tty6    00:00:00 /sbin/agetty 38400 tty6 linux

root      7746  1238  3 17:01 ?        00:07:45 /usr/sbin/smbd -D

root    18269  1054  0 20:50 ?        00:00:00 in.telnetd: 10.0.0.130

root    18270 18269  0 20:50 pts/0    00:00:00 -bash

root    18293  1252  0 20:50 ?        00:00:00 sleep 2

root    18294 18270  0 20:50 pts/0    00:00:00 ps -ef

 

I have a running spin_drives.sh script, but no child 'ping' or 'grep', instead on PID1252 I have a child 'sleep 2' when media player is off & 'sleep 500' when it is on?

 

Strange?

 

Thanks,

 

Mark.

 

Link to comment

Linux 2.6.20.

root@Tower:~# ps -ef

UID        PID  PPID  C STIME TTY          TIME CMD

root        1    0  0 16:16 ?        00:00:02 init

root        2    1  0 16:16 ?        00:00:00 [ksoftirqd/0]

root        3    1  0 16:16 ?        00:00:00 [events/0]

root        4    1  0 16:16 ?        00:00:00 [khelper]

root        5    1  0 16:16 ?        00:00:00 [kthread]

root        48    5  0 16:16 ?        00:00:00 [kblockd/0]

root        49    5  0 16:16 ?        00:00:00 [kacpid]

root      131    5  0 16:16 ?        00:00:00 [ksuspend_usbd]

root      134    5  0 16:16 ?        00:00:00 [khubd]

root      136    5  0 16:16 ?        00:00:00 [kseriod]

root      159    5  0 16:16 ?        00:00:00 [pdflush]

root      160    5  0 16:16 ?        00:00:00 [pdflush]

root      161    5  0 16:16 ?        00:00:02 [kswapd0]

root      162    5  0 16:16 ?        00:00:00 [aio/0]

root      351    5  0 16:16 ?        00:00:00 [scsi_eh_0]

root      352    5  0 16:16 ?        00:00:00 [usb-storage]

root      429    1  0 16:16 ?        00:00:00 /sbin/udevd --daemon

root      600    5  0 16:16 ?        00:00:00 [ata/0]

root      604    5  0 16:16 ?        00:00:00 [ata_aux]

root      605    5  0 16:16 ?        00:00:00 [scsi_eh_1]

root      606    5  0 16:16 ?        00:00:00 [scsi_eh_2]

root      782    5  0 16:16 ?        00:00:00 [scsi_eh_3]

root      783    5  0 16:16 ?        00:00:00 [scsi_eh_4]

root      784    5  0 16:16 ?        00:00:00 [scsi_eh_5]

root      785    5  0 16:16 ?        00:00:00 [scsi_eh_6]

root      953    1  0 16:16 ?        00:00:00 /usr/sbin/syslogd -m0

root      956    1  0 16:16 ?        00:00:00 /usr/sbin/klogd -c 3 -x

root      1054    1  0 16:16 ?        00:00:00 /usr/sbin/inetd

root      1065    1  0 16:16 ?        00:00:00 /usr/sbin/crond -l10

daemon    1067    1  0 16:16 ?        00:00:00 /usr/sbin/atd -b 15 -l 1

root      1070    1  0 16:16 ?        00:00:00 /usr/sbin/acpid

root      1076    1  0 16:16 ?        00:00:00 /usr/sbin/ifplugd -i eth0 -fwI -

root      1108    1  0 16:16 ?        00:00:00 /usr/local/sbin/emhttp

root      1114    5  0 16:16 ?        00:00:00 [mdrecoveryd]

root      1138    5  0 16:16 ?        00:00:01 [unraidd]

root      1207    5  0 16:16 ?        00:00:00 [reiserfs/0]

root      1236    1  0 16:16 ?        00:00:00 /usr/sbin/nmbd -D

root      1238    1  0 16:16 ?        00:00:00 /usr/sbin/smbd -D

root      1239  1238  0 16:16 ?        00:00:00 /usr/sbin/smbd -D

root      1252    1  0 16:17 ?        00:00:00 /bin/bash /boot/spin_drives.sh

root      1253    1  0 16:17 tty1    00:00:00 /sbin/agetty 38400 tty1 linux

root      1254    1  0 16:17 tty2    00:00:00 /sbin/agetty 38400 tty2 linux

root      1255    1  0 16:17 tty3    00:00:00 /sbin/agetty 38400 tty3 linux

root      1267    1  0 16:17 tty4    00:00:00 /sbin/agetty 38400 tty4 linux

root      1270    1  0 16:17 tty5    00:00:00 /sbin/agetty 38400 tty5 linux

root      1271    1  0 16:17 tty6    00:00:00 /sbin/agetty 38400 tty6 linux

root      7746  1238  3 17:01 ?        00:07:45 /usr/sbin/smbd -D

root    18269  1054  0 20:50 ?        00:00:00 in.telnetd: 10.0.0.130

root    18270 18269  0 20:50 pts/0    00:00:00 -bash

root    18293  1252  0 20:50 ?        00:00:00 sleep 2

root    18294 18270  0 20:50 pts/0    00:00:00 ps -ef

 

I have a running spin_drives.sh script, but no child 'ping' or 'grep', instead on PID1252 I have a child 'sleep 2' when media player is off & 'sleep 500' when it is on?

 

Strange?

 

Thanks,

 

Mark.

 

not strange at all.  It sleeps 2 seconds each time through the loop when the media players are not on-line.  You would need to catch exactly the right instant in time to see the ping and grep using ps -ef.

 

When the media player is on, after spinning up the drives again a sleep is invoked, but this time for 500 seconds.

 

Joe L.

 

The basic logic in structured english pseudo-code is

loop forever

  get_status of unRaid array

  if unRaid array is not started

    sleep 20 seconds

  end if

 

  if unRaid array is started

  if media player is online

    if disks are not spinning

      spin them up

      sleep 500 seconds

    end if

    if the disks are spinning

      sleep 10 seconds

    end if

  end if

  end if

 

  sleep 2 seconds , then loop to get status, etc once more

end loop

Link to comment
  • 2 weeks later...

Oops... this script stopped working on unRaid version 4.2.1

 

Why did it stop working... easy... Tom fixed the management page's need for a password.

 

If you have upgraded to 4.2.1 AND if you have implemented a "root" password (as I had), this script cannot "log in" to get drive status or to spin up the drives.  Instead, it gets this as the response:

 

        HTTP/1.1 401 Unauthorized

        WWW-Authenticate: Basic realm='unRAID SMU'

 

The short term solution is to go to the "Users" page in the management utility and press "Apply" in the set of fields for "root" while leaving its affiliated  password fields blank.  This will erase the password.  unRaid will no longer prompt you for a password on the management page, or when using telnet, and this spin-up script will again work.

 

The long-term solution is to either add the ability to log into the unRaid management page using an ID/PASSWORD supplied by the script, or to identify the best way to spin up the drives without using the management page at all.

 

For now, I removed my unRaid server's root password.  I'll work on a long term script as I find time in the next few days.

 

Joe L.

Link to comment
  • 2 months later...

Oops... this script stopped working on unRaid version 4.2.1

 

Why did it stop working... easy... Tom fixed the management page's need for a password.

 

If you have upgraded to 4.2.1 AND if you have implemented a "root" password (as I had), this script cannot "log in" to get drive status or to spin up the drives.  Instead, it gets this as the response:

 

        HTTP/1.1 401 Unauthorized

        WWW-Authenticate: Basic realm='unRAID SMU'

 

The short term solution is to go to the "Users" page in the management utility and press "Apply" in the set of fields for "root" while leaving its affiliated  password fields blank.  This will erase the password.  unRaid will no longer prompt you for a password on the management page, or when using telnet, and this spin-up script will again work.

 

The long-term solution is to either add the ability to log into the unRaid management page using an ID/PASSWORD supplied by the script, or to identify the best way to spin up the drives without using the management page at all.

 

For now, I removed my unRaid server's root password.  I'll work on a long term script as I find time in the next few days.

 

Joe L.

 

Hi Joe,

 

Did you get any further with the root password compatible version of this script?  I'm really needing to implement some security and would love to have this script still running.  How about scripting for a specific additon user of, say "autospin" that could have a specific password in the script?  I know it's a back door, but that's better than an open door isn't it?

 

Thanks,

 

Mark.

Link to comment

Oops... this script stopped working on unRaid version 4.2.1

 

Why did it stop working... easy... Tom fixed the management page's need for a password.

 

If you have upgraded to 4.2.1 AND if you have implemented a "root" password (as I had), this script cannot "log in" to get drive status or to spin up the drives.  Instead, it gets this as the response:

 

        HTTP/1.1 401 Unauthorized

        WWW-Authenticate: Basic realm='unRAID SMU'

 

The short term solution is to go to the "Users" page in the management utility and press "Apply" in the set of fields for "root" while leaving its affiliated  password fields blank.  This will erase the password.  unRaid will no longer prompt you for a password on the management page, or when using telnet, and this spin-up script will again work.

 

The long-term solution is to either add the ability to log into the unRaid management page using an ID/PASSWORD supplied by the script, or to identify the best way to spin up the drives without using the management page at all.

 

For now, I removed my unRaid server's root password.  I'll work on a long term script as I find time in the next few days.

 

Joe L.

 

Hi Joe,

 

Did you get any further with the root password compatible version of this script?  I'm really needing to implement some security and would love to have this script still running.  How about scripting for a specific additon user of, say "autospin" that could have a specific password in the script?  I know it's a back door, but that's better than an open door isn't it?

 

Thanks,

 

Mark.

Actually, I re-wrote the script to not have to use the web-management page at all.  I guess I never got back to updating this thread.  Sorry. Since it does not need to log in, it does not need to deal with the web-admin page password, even if one is assigned.

 

Anyway, below is the replacement script.  I added a lot of comments, so hopefully it wont be too hard for you to figure it out.

I did use a lot of Unix commands and features... Think of this a a mini-example of what you can do with shell scripts.

 

Joe L.

 

#!/bin/bash

######################################################################

#

# Spin up the unRaid disks when a media player is detected on line.

# (it is on line if it responds to a "ping" command over the network)

#

# Joe L.

# January 5, 2008

######################################################################

 

# List the media player IP addresses here.

# separate the IP addresses by spaces if there are more then one

mp_ip="192.168.2.21 192.168.2.22"

 

# Determine if the unRaid array is on-line or not.  If not currently

# started, we do not want to be spinning up any drives.

get_status() {

    cmd status | strings >/tmp/$$spin_up_status

    STATUS=`grep mdState /tmp/$$spin_up_status | cut -d "=" -f2`

    PHYSICAL_DISKS=`grep "^rdevName.*=" /tmp/$$spin_up_status |

        cut -d "=" -f2`

}

 

# function to issue commands to the unRaid "md" device. 

# specifically, we will use it to get the status of the array

cmd() {

    echo $* >/proc/mdcmd

    cat /proc/mdcmd

}

 

spin_up_drives() {

    # loop through the drives spinning them up

    # by reading a single "random" block from each disk

    # in turn.  We use "dd" commands in the background so

    # all the disks will be spun up in parallel

    # since the physical disks are listed three times, three random blocks are read from each drive. This should be enough

    # to ensure at least one of the blocks was not in the disk cache memory.

    for i in $PHYSICAL_DISKS $PHYSICAL_DISKS $PHYSICAL_DISKS

    do

        # determine the number of blocks on the drive

        blocks=`df -k /dev/$i | grep -v Filesystem|

        sed "s/\([^ ]*\) *\([^ ]*\) .*/\2/"`

 

        # calculate a (random) block number to be read somewhere

        # between block 1 and the max blocks on the drive

        skip_b=$(( 1+(`dd if=/dev/urandom count=1 2>/dev/null |

        cksum | cut -f1 -d" "`)%($blocks) ))

   

        # read the random block from the disk.  We use a random

        # block to try to ensure it is not in the cache memory

        # if the block was in the cache memory, the disk would

        # not spin up.

        dd if=/dev/$i of=/dev/null \

        count=1 bs=1k skip=$skip_b >/dev/null 2>&1 &

    done

}

 

sleep_checking_status() {

    seconds_to_sleep=$1

    test_interval=10

    while  ( test $seconds_to_sleep -gt 0 )

    do

      get_status

      if [ "$STATUS" != "STARTED" ]

      then

          break

      fi

      sleep $test_interval

      seconds_to_sleep=$(( $seconds_to_sleep - $test_interval ))

    done

}

 

# create a lockfile so we do not start two of these spin_up processes

lockfile="/var/lock/spin_up_drives"

 

if ( set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null;

then

  trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT

 

  echo "`date` ****** spin_drives.sh started" >/var/log/spin_up.log

 

  # loop forever

  while true

  do

    get_status

    if [ "$STATUS" != "STARTED" ]

    then

        # if the array is not started, sleep a few seconds and loop to

        # check status once more

        sleep 2

    else

        # The array is started, see if any of the media players are

        # on-line. If they are, spin up the drives if we need to.

 

        mp_online="no"  # initialize to "no" until we learn otherwise

        # ping each of the media servers to determine if online

        for i in $mp_ip

        do

            # ping the media server, if it answers, it is online

            out=`ping -q -c 1 $i 2>/dev/null`

            echo "$out" | grep "1 received," 1>/dev/null 2>&1

            if [ "$?" = "0" ]

            then

                mp_online="yes"

                # if one is online, we do not need to ping

                # any others, break out of the "for" loop.

                break;

            fi

        done

 

        # if any media players are online, spin up the drives

        # and then sleep checking for status changes and we'll

        # see if they are still online next time through the loop.

        if [ "$mp_online" = "yes" ]

        then

            spin_up_drives

            # we just spun up the drives, we don't need to do much

            # for the next 600 seconds unless the

            # array status changes, so sleep looking for changes

            sleep_checking_status 600

        fi

 

        sleep 5

    fi

  done

 

    rm -f "$lockfile"

    trap - INT TERM EXIT

else

    echo "Failed to acquire lockfile: $lockfile."

    echo "Held by $(cat $lockfile)"

fi

Link to comment

Not sure if it was the new script or something else, but my drives didn't spin down again after the media player is turned off and a hour on inactivity.

 

This morning all my HDDs were still spinning and the mediaplayer was off & not responding to ping requests.

 

I'll try & look into this today.

 

Mark.

 

BTW.  What would happen if you were to select "Spin Down All HDDs" whilst you were writing to one?  I don't like using that button in case some remote script is writing to the unraid server.

Link to comment

My drives do spin down...  In fact, I watched it spin them down twice yesterday as we enjoyed a movie in the morning and another in the evening.

 

There is not much that the script does that can affect spin-down.  If the media device does not answer the ping, it should not set the mp_online="yes" and not be doing any access to any disks.  The script does not "spin up" drives the same way the button on the management console does. It does it by reading from the drives themselves, same as any other drive access.  It sounds like you might still be reading from the disks.

 

Try typing

smbstatus

to see if Samba is holding any files open from your media player session.

 

Not sure what would happen if the spin-down button was pressed while a drive was being read... I'd guess it the drive would just spin up as soon as another block of data was read.

 

I'll be curious to see what you learn.

 

Joe L.

Link to comment

Drives definitely not spinning down afterwards Joe,

 

:~# smbstatus

Try typing

smbstatus

to see if Samba is holding any files open from your media player session

 

Samba version 3.0.26a

PID    Username      Group        Machine

-------------------------------------------------------------------

 

Service      pid    machine      Connected at

-------------------------------------------------------

disk4        9565  study1      Mon Jan  7 20:32:22 2008

disk1        9565  study1      Mon Jan  7 18:10:31 2008

 

No locked files

 

Nothing there other than from my desktop PC.

 

"/var/lock/spin_up_drives" still exists BTW.

 

/var/logs/spin_up.log only has 1 entry

 

"Sun Jan  6 10:58:03 GMT 2008 ****** spin_drives.sh started"

 

Any ideas?

 

Thanks,

 

Mark.

Link to comment

The lock file will exist until you kill the process that created it.

 

So... how many spin-up processes are running on your machine?  (should only be the one you just modified)

Type

ps -f

and you should see something like this if you invoked the script from a telnet prompt.

root@Tower:/boot# ps -f

UID        PID  PPID  C STIME TTY          TIME CMD

root      5768 26324  0 Jan05 pts/0    00:00:16 /bin/bash .//spin_drives.sh

root    10318  5768 99 Jan06 pts/0    23:32:12 /bin/bash .//spin_drives.sh

root    11422 26324  0 17:05 pts/0    00:00:00 ps -f

root    26324 26323  0 Jan05 pts/0    00:00:00 -bash

 

the /var/logs/spin_up.log  file would only have one entry.  I took all the other log writing lines out of the script when I re-wrote it.

So... for the drives to remain spinning something must be accessing them.  To see if it is the spin_up script, you can kill it and wait an hour or so.

 

so first get the process ID from the lock file

cat /var/lock/spin_up_drives

5768

 

The number it returns is the process ID of the script.  You can kill the script by typing

kill 5768  <--- use your process ID in place of 5768

 

Then, we'll add in a few more lines to write to the log and try to figure out what is going on.  The script is pretty simple, so it should not be too difficult to figure it out.

 

Joe L.

Link to comment

Hi Joe,

 

This is bizarre,

 

I have no running instances of your script at all visible with ps -f, I can see 1 running with ps -ef.

 

I have no idea what is causing all my drives to be accessed, but I'm wonder whether it is your script after all.

 

I'm new to Vista for my desktop and I had 2 mapped drives, 1 mapped to disk1 and another mapped to a user share called "music".  Whenever my desktop PC comes out of any kind of powersave mode I can no longer access the mapped drive to the user share.  If I navigate to the hdd that contains that user share directory via "My Network Places" the access to the user share is restored.

 

It may be that something is searching all locations to try and re-establish a link to the database, either itunes or Slimserver perhaps.  I'll do some further digging tomorrow.  This has only just started happening since I've been playing with getting this spin-up script running, but I think that may well be a coincidence.

 

I'll dig deeper tomorrow as it's past 2300 and I start work really early tomorrow.

 

Many thanks,

 

Mark.

Link to comment

Hi Joe,

 

I rebooted the server and manually spun down the HDDs.  I turned on the MediaPlayer and all HDDs spin up.  I switched off the MediaPlayer and waited an hour (90 minutes actually) and the HDDs remain spinning.  I manually spin them down and they remain spun down.

 

with:- ps -ef

 

UID        PID  PPID  C STIME TTY          TIME CMD

root      1511    1  0 14:26 ?        00:00:00 /bin/bash /boot/spin_drives.sh

root    28328  1511  0 18:36 ?        00:00:00 /bin/bash /boot/spin_drives.sh

root    28329 28328  0 18:36 ?        00:00:00 ping -q -c 1 10.0.0.7

root    28330 28293  0 18:36 pts/0    00:00:00 ps -ef

 

Looks like 2 instances of spin_drives.sh appear to be running.  I have not manually started one.

 

With:- cat /var/lock/spin_up_drives

 

I get the ID 1511

 

After:- Kill 1511

 

No "/boot/spin_drives.sh" is running at the "/var/lock/spin_up_drives" lock has gone.

 

Shall I reboot now?

 

Thanks,

 

Mark.

 

Link to comment

The two process IDs are related for spin_drives.  The PPID of one is the ID of the other.  Basically, the function calls are executed in a second process.  So, nothing out of the ordinary there.

 

The experiment now is...

kill your existing script.

Add these lines in RED below to your script, or create a script with a slightly different name and add them to it and then...

Press the button to spin down the drives (if they are spinning)

Start the newly altered script once more.  And let me know how you are starting it...  let it run.

Start the media player... the drives should spin up.

Turn off the media player. 

wait 61 minutes or more ... the drives should spin down.

if not, kill the script... then wait 61 minutes more (or longer) do the drives spin down now?

 

You can then

tail -f /var/log/spin_up.log

and see what it is doing.

 

Joe L.

 

#!/bin/bash

######################################################################

#

# Spin up the unRaid disks when a media player is detected on line.

# (it is on line if it responds to a "ping" command over the network)

#

# Joe L.

# January 5, 2008

######################################################################

 

# List the media player IP addresses here.

# separate the IP addresses by spaces if there are more then one

mp_ip="192.168.2.21 192.168.2.22"

 

# Determine if the unRaid array is on-line or not.  If not currently

# started, we do not want to be spinning up any drives.

get_status() {

    cmd status | strings >/tmp/$$spin_up_status

    STATUS=`grep mdState /tmp/$$spin_up_status | cut -d "=" -f2`

    PHYSICAL_DISKS=`grep "^rdevName.*=" /tmp/$$spin_up_status |

        cut -d "=" -f2`

}

 

# function to issue commands to the unRaid "md" device.

# specifically, we will use it to get the status of the array

cmd() {

    echo $* >/proc/mdcmd

    cat /proc/mdcmd

}

 

spin_up_drives() {

    # loop through the drives spinning them up

    # by reading a single "random" block from each disk

    # in turn.  We use "dd" commands in the background so

    # all the disks will be spun up in parallel

    # since the physical disks are listed three times, three random blocks are read from each drive. This should be enough

    # to ensure at least one of the blocks was not in the disk cache memory.

    for i in $PHYSICAL_DISKS $PHYSICAL_DISKS $PHYSICAL_DISKS

    do

        # determine the number of blocks on the drive

        blocks=`df -k /dev/$i | grep -v Filesystem|

        sed "s/\([^ ]*\) *\([^ ]*\) .*/\2/"`

 

        # calculate a (random) block number to be read somewhere

        # between block 1 and the max blocks on the drive

        skip_b=$(( 1+(`dd if=/dev/urandom count=1 2>/dev/null |

        cksum | cut -f1 -d" "`)%($blocks) ))

 

        # read the random block from the disk.  We use a random

        # block to try to ensure it is not in the cache memory

        # if the block was in the cache memory, the disk would

        # not spin up.

        dd if=/dev/$i of=/dev/null \

        count=1 bs=1k skip=$skip_b >/dev/null 2>&1 &

echo "`date` ****** spin_drives.sh reading block $skip_b from $i " >>/var/log/spin_up.log 

    done

}

 

sleep_checking_status() {

    seconds_to_sleep=$1

    test_interval=10

    while  ( test $seconds_to_sleep -gt 0 )

    do

      get_status

      if [ "$STATUS" != "STARTED" ]

      then

          break

      fi

      sleep $test_interval

      seconds_to_sleep=$(( $seconds_to_sleep - $test_interval ))

      echo "`date` ****** spin_drives.sh sleeping  $seconds_to_sleep " >>/var/log/spin_up.log 

    done

}

 

# create a lockfile so we do not start two of these spin_up processes

lockfile="/var/lock/spin_up_drives"

 

if ( set -o noclobber; echo "$$" > "$lockfile") 2> /dev/null;

then

  trap 'rm -f "$lockfile"; exit $?' INT TERM EXIT

 

  echo "`date` ****** spin_drives.sh started" >/var/log/spin_up.log

 

  # loop forever

  while true

  do

    get_status

    if [ "$STATUS" != "STARTED" ]

    then

        # if the array is not started, sleep a few seconds and loop to

        # check status once more

        sleep 2

    else

        # The array is started, see if any of the media players are

        # on-line. If they are, spin up the drives if we need to.

 

        mp_online="no"  # initialize to "no" until we learn otherwise

        # ping each of the media servers to determine if online

        for i in $mp_ip

        do

echo "`date` ****** spin_drives.sh pinging $i " >>/var/log/spin_up.log 

            # ping the media server, if it answers, it is online

            out=`ping -q -c 1 $i 2>/dev/null`

            echo "$out" | grep "1 received," 1>/dev/null 2>&1

            if [ "$?" = "0" ]

            then

  echo "`date` ****** spin_drives.sh media player $i is online, output of ping follows..." >>/var/log/spin_up.log

  echo "$out" >>/var/log/spin_up.log

                mp_online="yes"

                # if one is online, we do not need to ping

                # any others, break out of the "for" loop.

                break;

            fi

        done

 

echo "`date` ****** spin_drives.sh mp_online: $mp_online" >>/var/log/spin_up.log 

        # if any media players are online, spin up the drives

        # and then sleep checking for status changes and we'll

        # see if they are still online next time through the loop.

        if [ "$mp_online" = "yes" ]

        then

            spin_up_drives

            # we just spun up the drives, we don't need to do much

            # for the next 600 seconds unless the

            # array status changes, so sleep looking for changes

            sleep_checking_status 600

        fi

echo "`date` ****** spin_drives.sh sleeping 5 seconds " >>/var/log/spin_up.log 

        sleep 5

    fi

  done

 

    rm -f "$lockfile"

    trap - INT TERM EXIT

else

    echo "Failed to acquire lockfile: $lockfile."

    echo "Held by $(cat $lockfile)"

fi

 

Link to comment

Just to add.. I changed scripts after Mark mentioned it had been updated. Last night watched a film, turned off the mediaplayer (both me and Mark use TVIX 4100's) and went to bed... In the Morning when I checked the unraid webpage I also noticed that all the drives were up...

 

Very strange :)

Link to comment

I'm having some computer trouble again so can't test this at the moment :(

 

Hopefully, tonight or tomorrow.

 

I switched to Vista at Christmas (why?!!!!!) and after an incident free few weeks my mediaplayer (TVix) can no longer see any media from the server.  I know it's config stuff, but taking up my time.  The share is seen, just nothing on it.

 

Obviously some permissions issue.

 

Will report back on the auto-spinup soon,

 

Thanks,

 

Mark.

Link to comment

I am also testing with the additional logging statements.

 

So far, it is behaving exactly as expected.  I am not sure the spin-down times are  exactly an hour, but they did eventually spin down (it did not seem to happen exactly an hour after I turned off the media player, but several hours later when I looked, the drives were spun down)

My log looked like this as the process started and waited for me to turn the media player on:

Thu Jan 10 09:36:37 EST 2008 ****** spin_drives.sh started
Thu Jan 10 09:36:37 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 09:36:40 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 09:36:43 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 09:36:43 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 09:36:48 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 09:36:51 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 09:36:54 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 09:36:54 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 09:36:59 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 09:37:02 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 09:37:05 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 09:37:05 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 09:37:10 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 09:37:13 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 09:37:16 EST 2008 ****** spin_drives.sh mp_online: no

Then, once the player was detected:

Thu Jan 10 09:41:19 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 09:41:19 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh media player 192.168.2.21 is online, output of ping follows...
PING 192.168.2.21 (192.168.2.21) 56(84) bytes of data.

--- 192.168.2.21 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 9.541/9.541/9.541/0.000 ms
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh mp_online: yes
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 153061 from hda
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 253845 from hdb
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 157719 from hdc
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 133678 from hdd
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 237391 from hde
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 144858 from hdf
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 239516 from hdg
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 71636 from hdh
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 206191 from hdi
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 168052 from hda
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 199162 from hdb
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 186316 from hdc
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 230045 from hdd
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 186388 from hde
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 158717 from hdf
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 29062 from hdg
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 245306 from hdh
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 6158 from hdi
Thu Jan 10 09:41:24 EST 2008 ****** spin_drives.sh reading block 172447 from hda
Thu Jan 10 09:41:25 EST 2008 ****** spin_drives.sh reading block 58994 from hdb
Thu Jan 10 09:41:25 EST 2008 ****** spin_drives.sh reading block 2736 from hdc
Thu Jan 10 09:41:25 EST 2008 ****** spin_drives.sh reading block 220786 from hdd
Thu Jan 10 09:41:25 EST 2008 ****** spin_drives.sh reading block 73104 from hde
Thu Jan 10 09:41:25 EST 2008 ****** spin_drives.sh reading block 185878 from hdf
Thu Jan 10 09:41:25 EST 2008 ****** spin_drives.sh reading block 170148 from hdg
Thu Jan 10 09:41:25 EST 2008 ****** spin_drives.sh reading block 170834 from hdh
Thu Jan 10 09:41:25 EST 2008 ****** spin_drives.sh reading block 26615 from hdi
Thu Jan 10 09:41:35 EST 2008 ****** spin_drives.sh sleeping  590
Thu Jan 10 09:41:45 EST 2008 ****** spin_drives.sh sleeping  580
Thu Jan 10 09:41:55 EST 2008 ****** spin_drives.sh sleeping  570
Thu Jan 10 09:42:05 EST 2008 ****** spin_drives.sh sleeping  560
Thu Jan 10 09:42:15 EST 2008 ****** spin_drives.sh sleeping  550
Thu Jan 10 09:42:25 EST 2008 ****** spin_drives.sh sleeping  540
Thu Jan 10 09:42:35 EST 2008 ****** spin_drives.sh sleeping  530
Thu Jan 10 09:42:45 EST 2008 ****** spin_drives.sh sleeping  520
Thu Jan 10 09:42:55 EST 2008 ****** spin_drives.sh sleeping  510
Thu Jan 10 09:43:05 EST 2008 ****** spin_drives.sh sleeping  500
Thu Jan 10 09:43:15 EST 2008 ****** spin_drives.sh sleeping  490
Thu Jan 10 09:43:25 EST 2008 ****** spin_drives.sh sleeping  480
Thu Jan 10 09:43:35 EST 2008 ****** spin_drives.sh sleeping  470

... same lines counting down for 600 seconds ... player is still online, so more disk blocks are read to keep the drives spinning

Thu Jan 10 09:50:56 EST 2008 ****** spin_drives.sh sleeping  30
Thu Jan 10 09:51:06 EST 2008 ****** spin_drives.sh sleeping  20
Thu Jan 10 09:51:16 EST 2008 ****** spin_drives.sh sleeping  10
Thu Jan 10 09:51:26 EST 2008 ****** spin_drives.sh sleeping  0
Thu Jan 10 09:51:26 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh media player 192.168.2.21 is
online, output of ping follows...
PING 192.168.2.21 (192.168.2.21) 56(84) bytes of data.

--- 192.168.2.21 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.357/0.357/0.357/0.000 ms
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh mp_online: yes
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 98364 from hda
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 26724 from hdb
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 207093 from hdc
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 139467 from hdd
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 100086 from hde
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 83711 from hdf
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 179609 from hdg
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 246624 from hdh
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 165361 from hdi
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 174578 from hda
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 83635 from hdb
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 4946 from hdc
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 205835 from hdd
Thu Jan 10 09:51:31 EST 2008 ****** spin_drives.sh reading block 111657 from hde
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 6516 from hdf
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 78650 from hdg
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 35369 from hdh
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 249148 from hdi
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 110430 from hda
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 99789 from hdb
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 70168 from hdc
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 137172 from hdd
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 170525 from hde
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 143931 from hdf
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 23746 from hdg
Thu Jan 10 09:51:32 EST 2008 ****** spin_drives.sh reading block 228196 from hdi
Thu Jan 10 09:51:42 EST 2008 ****** spin_drives.sh sleeping  590
Thu Jan 10 09:51:52 EST 2008 ****** spin_drives.sh sleeping  580
Thu Jan 10 09:52:02 EST 2008 ****** spin_drives.sh sleeping  570
Thu Jan 10 09:52:12 EST 2008 ****** spin_drives.sh sleeping  560
Thu Jan 10 09:52:22 EST 2008 ****** spin_drives.sh sleeping  550
Thu Jan 10 09:52:32 EST 2008 ****** spin_drives.sh sleeping  540
Thu Jan 10 09:52:42 EST 2008 ****** spin_drives.sh sleeping  530
Thu Jan 10 09:52:52 EST 2008 ****** spin_drives.sh sleeping  520
Thu Jan 10 09:53:02 EST 2008 ****** spin_drives.sh sleeping  510
Thu Jan 10 09:53:12 EST 2008 ****** spin_drives.sh sleeping  500
Thu Jan 10 09:53:22 EST 2008 ****** spin_drives.sh sleeping  490
Thu Jan 10 09:53:32 EST 2008 ****** spin_drives.sh sleeping  480
Thu Jan 10 09:53:42 EST 2008 ****** spin_drives.sh sleeping  470
Thu Jan 10 09:53:52 EST 2008 ****** spin_drives.sh sleeping  460
Thu Jan 10 09:54:02 EST 2008 ****** spin_drives.sh sleeping  450
Thu Jan 10 09:54:12 EST 2008 ****** spin_drives.sh sleeping  440
Thu Jan 10 09:54:22 EST 2008 ****** spin_drives.sh sleeping  430
Thu Jan 10 09:54:32 EST 2008 ****** spin_drives.sh sleeping  420
Thu Jan 10 09:54:42 EST 2008 ****** spin_drives.sh sleeping  410

I then shut the media player off. and waited...

Thu Jan 10 10:00:53 EST 2008 ****** spin_drives.sh sleeping  40
Thu Jan 10 10:01:03 EST 2008 ****** spin_drives.sh sleeping  30
Thu Jan 10 10:01:13 EST 2008 ****** spin_drives.sh sleeping  20
Thu Jan 10 10:01:23 EST 2008 ****** spin_drives.sh sleeping  10
Thu Jan 10 10:01:33 EST 2008 ****** spin_drives.sh sleeping  0
Thu Jan 10 10:01:33 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 10:01:38 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 10:01:41 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 10:01:44 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 10:01:44 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 10:01:49 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 10:01:52 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 10:01:55 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 10:01:55 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 10:02:00 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 10:02:03 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 10:02:06 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 10:02:06 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 10:02:11 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 10:02:14 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 10:02:17 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 10:02:17 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 10:02:23 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 10:02:26 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 10:02:29 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 10:02:29 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 10:02:34 EST 2008 ****** spin_drives.sh pinging 192.168.2.21

 

Once I had shut down the media player, it went back to pinging the media player addresses to find one online.

An hour later, the drives were still spinning according to the web-interface. Several hours later they were spun down.

 

Oh yes, the log will grow quickly with a line added every 5 or 10 seconds, so don't leave the debugging lines in place once we figure out what is happening.

 

Joe L.

Link to comment

I caught it misbehaving... now, to narrow in on the cause.

I watched a movie, then shut my media player down.  The logging has continued to track what the script is doing and what do you know,this time I see a really weird set of lines in the log file...

Around 16:50 I was still watching my movie.  The 600 second count down continued until it was time to see if the media player was still on-line.  It found that it was still active at 16:51:58.

Thu Jan 10 16:50:52 EST 2008 ****** spin_drives.sh sleeping  60
Thu Jan 10 16:51:03 EST 2008 ****** spin_drives.sh sleeping  50
Thu Jan 10 16:51:13 EST 2008 ****** spin_drives.sh sleeping  40
Thu Jan 10 16:51:23 EST 2008 ****** spin_drives.sh sleeping  30
Thu Jan 10 16:51:33 EST 2008 ****** spin_drives.sh sleeping  20
Thu Jan 10 16:51:43 EST 2008 ****** spin_drives.sh sleeping  10
Thu Jan 10 16:51:53 EST 2008 ****** spin_drives.sh sleeping  0
Thu Jan 10 16:51:53 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh media player 192.168.2.21 is
online, output of ping follows...
PING 192.168.2.21 (192.168.2.21) 56(84) bytes of data.

--- 192.168.2.21 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.724/0.724/0.724/0.000 ms
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh mp_online: yes
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 228926 from hda
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 78235 from hdb
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 160664 from hdc
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 252267 from hdd
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 144031 from hde
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 109165 from hdf
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 80593 from hdg
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 166499 from hdh
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 46131 from hdi
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 219046 from hda
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 16783 from hdb
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 15054 from hdc
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 154769 from hdd
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 161242 from hde
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 11799 from hdf
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 159440 from hdg
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 31810 from hdh
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 108199 from hdi
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 120739 from hda
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 54047 from hdb
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 96978 from hdc
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 65891 from hdd
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 141438 from hde
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 103860 from hdf
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 25441 from hdg
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 211895 from hdh
Thu Jan 10 16:51:58 EST 2008 ****** spin_drives.sh reading block 215175 from hdi
Thu Jan 10 16:52:08 EST 2008 ****** spin_drives.sh sleeping  590
Thu Jan 10 16:52:18 EST 2008 ****** spin_drives.sh sleeping  580
Thu Jan 10 16:52:28 EST 2008 ****** spin_drives.sh sleeping  570
Thu Jan 10 16:52:38 EST 2008 ****** spin_drives.sh sleeping  560
Thu Jan 10 16:52:48 EST 2008 ****** spin_drives.sh sleeping  550
Thu Jan 10 16:52:58 EST 2008 ****** spin_drives.sh sleeping  540
Thu Jan 10 16:53:08 EST 2008 ****** spin_drives.sh sleeping  530
Thu Jan 10 16:53:19 EST 2008 ****** spin_drives.sh sleeping  520
Thu Jan 10 16:53:29 EST 2008 ****** spin_drives.sh sleeping  510
Thu Jan 10 16:53:39 EST 2008 ****** spin_drives.sh sleeping  500

Somewhere in this 600 second delay I shut down the media player, the last 40 seconds are shown below.

We now check every 5 seconds looking for a successful ping of either of my media players.

Thu Jan 10 17:01:20 EST 2008 ****** spin_drives.sh sleeping  40
Thu Jan 10 17:01:30 EST 2008 ****** spin_drives.sh sleeping  30
Thu Jan 10 17:01:40 EST 2008 ****** spin_drives.sh sleeping  20
Thu Jan 10 17:01:50 EST 2008 ****** spin_drives.sh sleeping  10
Thu Jan 10 17:02:00 EST 2008 ****** spin_drives.sh sleeping  0
Thu Jan 10 17:02:00 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 17:02:05 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 17:02:08 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 17:02:11 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 17:02:11 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 17:02:16 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 17:02:19 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 17:02:22 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 17:02:22 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 17:02:27 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 17:02:30 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 17:02:33 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 17:02:33 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 17:02:38 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 17:02:41 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 17:02:44 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 17:02:44 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 17:02:49 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 17:02:52 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 17:02:55 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 17:02:56 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 17:03:01 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 17:03:04 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 17:03:07 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 17:03:07 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 17:03:12 EST 2008 ****** spin_drives.sh pinging 192.168.2.21

Then, after about an hour and twenty minutes, the log showed that the mp_online flag was set to "yes." It also showed me the output of the previous "ping" which was UNSUCCESSFUL.  Now, my media player is still off... so the ping is correct.

It should not be possible for mp_online to be set to yes though.... The "grep" must have had an exit status of "0"

 

Since the script thinks the media player is online (the mp_online flag was set to "yes"), even though the media player is not online, it spins up the drives by reading blocks of data from them.

Thu Jan 10 18:23:43 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 18:23:48 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 18:23:51 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 18:23:54 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 18:23:54 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 18:23:59 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 18:24:02 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 18:24:05 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 18:24:05 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 18:24:10 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 18:24:13 EST 2008 ****** spin_drives.sh media player 192.168.2.21 is
online, output of ping follows...
PING 192.168.2.21 (192.168.2.21) 56(84) bytes of data.

--- 192.168.2.21 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
Thu Jan 10 18:24:13 EST 2008 ****** spin_drives.sh mp_online: yes
Thu Jan 10 18:24:13 EST 2008 ****** spin_drives.sh reading block 6742 from hda
Thu Jan 10 18:24:13 EST 2008 ****** spin_drives.sh reading block 68407 from hdb
Thu Jan 10 18:24:13 EST 2008 ****** spin_drives.sh reading block 45628 from hdc
Thu Jan 10 18:24:13 EST 2008 ****** spin_drives.sh reading block 62698 from hdd
Thu Jan 10 18:24:13 EST 2008 ****** spin_drives.sh reading block 22053 from hde
Thu Jan 10 18:24:13 EST 2008 ****** spin_drives.sh reading block 91854 from hdf
Thu Jan 10 18:24:13 EST 2008 ****** spin_drives.sh reading block 243631 from hdg

It then goes to sleep for 600 seconds, and checks for one or two more ping cycles before again seeming to detect a successful ping and again reading a series of blocks from the drives.

Thu Jan 10 18:33:55 EST 2008 ****** spin_drives.sh sleeping  20
Thu Jan 10 18:34:05 EST 2008 ****** spin_drives.sh sleeping  10
Thu Jan 10 18:34:15 EST 2008 ****** spin_drives.sh sleeping  0
Thu Jan 10 18:34:15 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 18:34:21 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 18:34:24 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 18:34:27 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 18:34:27 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 18:34:32 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 18:34:35 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 18:34:38 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 18:34:38 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 18:34:43 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 18:34:46 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 18:34:49 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 18:34:49 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 18:34:54 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 18:34:57 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 18:35:00 EST 2008 ****** spin_drives.sh mp_online: no
Thu Jan 10 18:35:00 EST 2008 ****** spin_drives.sh sleeping 5 seconds
Thu Jan 10 18:35:05 EST 2008 ****** spin_drives.sh pinging 192.168.2.21
Thu Jan 10 18:35:08 EST 2008 ****** spin_drives.sh pinging 192.168.2.22
Thu Jan 10 18:35:11 EST 2008 ****** spin_drives.sh media player 192.168.2.22 is
online, output of ping follows...
PING 192.168.2.22 (192.168.2.22) 56(84) bytes of data.

--- 192.168.2.22 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
Thu Jan 10 18:35:11 EST 2008 ****** spin_drives.sh mp_online: yes
Thu Jan 10 18:35:11 EST 2008 ****** spin_drives.sh reading block 118516 from hda
...

 

OK, so the code involved is here... the output of the "ping" is captured in a variable "out"  It is then echoed and piped to the "grep" command.  I throw the output of the grep away, but I am expecting it to correctly set its exit status to either 1 or 0.  (0 = pattern matched, 1 = it was not matched).  I am looking for "1 received" in the ping output indicating 1 ping was returned.

        # The array is started, see if any of the media players are

        # on-line. If they are, spin up the drives if we need to.

 

        mp_online="no"  # initialize to "no" until we learn otherwise

        # ping each of the media servers to determine if online

        for i in $mp_ip

        do

echo "`date` ****** spin_drives.sh pinging $i " >>/var/log/spin_up.log

            # ping the media server, if it answers, it is online

            out=`ping -q -c 1 $i 2>/dev/null`

            echo "$out" | grep "1 received," 1>/dev/null 2>&1

            if [ "$?" = "0" ]

            then

  echo "`date` ****** spin_drives.sh media player $i is online, output of ping follows..." >>/var/log/spin_up.log

  echo "$out" >>/var/log/spin_up.log

                mp_online="yes"

                # if one is online, we do not need to ping

                # any others, break out of the "for" loop.

                break;

            fi

        done

 

echo "`date` ****** spin_drives.sh mp_online: $mp_online" >>/var/log/spin_up.log

Now, $? is supposed to be set to the exit status of the last command in the pipeline of commands... Either it is not, or "grep" is returning success when it should not.  I'll need to try an alternate way of checking the output of the ping command.

 

I did not expect to find an error in the exit status of the "grep" command.  It was far more likely I made a mistake in my logic... Wierd....  Even more interesting is that it is sporadic. Most of the time the exit status is set correctly.

 

Joe L.

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.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.