spinning disks up/down using TCP over network


Recommended Posts

I have an extensive home theater and all media (movies, TV shows) is on my unraid tower. The theater app runs on a small PC and has a movie browser that id very much like Kelaidescape. Most of the time I am just watching TV and not using the unraid repository.  When I go to watch a movie, there is a significant delay since I normally keep all disks spun down. I would like to be able to send a command over the network (HTTP GET) to spin up all the disks not waiting for the disks to spin up.

 

In general the ability to send commands that are simple buttons on the WEB GUI page would be greatly appreciated.  I used to be able to do this  with a command such as:

     GET /update.htm?cmdSpinupAll=Spin%20Up HTTP/1.1 plus the necessary http clauses

Link to comment
  • 2 weeks later...

I wrote a REST Api for Unraid that I have been experimenting with. It has the functionality you are looking for. I haven't released it yet, but you are more than welcome to give it a try.

 

It runs as a docker container and exposes APIs for managing the server. These endpoints are also secured with your local credentials as well. For example
{{host}}:{{port}}/api/disks/up

{{host}}:{{port}}/api/disks/down

Link to comment

Hitch,

welcome to the unraid community.

I would be very interested in trying this. I am not at all familiar with Docker containers.  Is there somewhere I can retrieve it from.?

Not being familiar with docker containers I don't want to hold you up from the completion of the project.  When do you expect to have it completed as an installable container perhaps as a Community applications.?  I would like to see the source code so I know what is going on. If a donation would enable you to complete this more rapidly, let me know. 

Link to comment

Hey Barry, I have a stable docker image uploaded you could use. I can guide you through the required configuration under the docker tab, should only take a few minutes to get it up and running. As far as getting it approved under the Community Applications, i know they have some sort of review process and I haven't taken a dive into that process yet, but plan to! PM me your github account and I will add you to the repository for your review.

 

I appreciate your support but that will not be necessary 🙂 . Writing an application that helps people is rewarding enough for me. Any feedback you have will help me make a better application!

Edited by hitch
Link to comment
On 12/1/2020 at 9:33 AM, barrygordon said:

I have an extensive home theater and all media (movies, TV shows) is on my unraid tower. The theater app runs on a small PC and has a movie browser that id very much like Kelaidescape. Most of the time I am just watching TV and not using the unraid repository.  When I go to watch a movie, there is a significant delay since I normally keep all disks spun down. I would like to be able to send a command over the network (HTTP GET) to spin up all the disks not waiting for the disks to spin up.

 

In general the ability to send commands that are simple buttons on the WEB GUI page would be greatly appreciated.  I used to be able to do this  with a command such as:

     GET /update.htm?cmdSpinupAll=Spin%20Up HTTP/1.1 plus the necessary http clauses

Look at the '/usr/local/emhttp/emcmd' script.  You could use like this:

 

emcmd "cmdSpinupAll=apply"  # spin up all hdd's

emcmd "cmdSpindownAll=apply"  # spin 'em down

emcmd "cmdSpinup=disk1"  # spin up disk1.  If disk1 was a member of a spinup group all disks of the group would spin up.

Link to comment
On 12/1/2020 at 9:33 AM, barrygordon said:

In general the ability to send commands that are simple buttons on the WEB GUI page would be greatly appreciated.  I used to be able to do this  with a command such as:

     GET /update.htm?cmdSpinupAll=Spin%20Up HTTP/1.1 plus the necessary http clauses

That still works but you are missing the csrf token, look at that emcmd script.

Link to comment

Limetech,

 

Thanks for the reply. I have been a lime tech user for a very long time. I get uptimes measured in years, only going down for updates.

I found emcmd script at /usr/local/emhttp/plugins/dynamix/scripts/.  The script looks like:

 

#!/usr/bin/php
<?PHP
require_once "/usr/local/emhttp/webGui/include/publish.php";
function emhttp_command($cmd)
{
    $var = parse_ini_file("/var/local/emhttp/var.ini");
    $cmd .= "&csrf_token={$var['csrf_token']}";
    return curl_socket("/var/run/emhttpd.socket", "http://localhost/update", $cmd);
}
$result = emhttp_command($argv[1]);
if ($result === "") exit(0);
echo "$result".PHP_EOL;
exit(1);
?>
 

I am not at all conversant with PHP so I would not know where to start.

A sample of the httpget command to properly (with the necessary csrf, and how to get the current csrf) access the spin states and/or spin up/down the drives would help me a great deal. I can see the csrf token in /var/local/emhttp/var .ini.

 

TIA,

Barry

Link to comment
2 hours ago, barrygordon said:

A sample of the httpget command to properly (with the necessary csrf, and how to get the current csrf) access the spin states and/or spin up/down the drives would help me a great deal. I can see the csrf token in /var/local/emhttp/var .ini.

Ok location of 'emcmd' moved in 6.9, probably you're on 6.8 right?

 

I guess I'm confused about what you're doing.  If you have created your own little app to spin up the drives, I assumed you know enough to figure out how to add the csrf token.  How were you doing this before and I guess now it's broken?  Why not just fire up webGUI and click 'Spin up' button?

 

Link to comment
  • 3 weeks later...

I had done this a long long time ago (IIRC unraid 4).  I never wrote anything on the unRaid system.  I always did what I wanted using TCP/IP and GET . . .   I have no idea how to include a csrf token, nor what one looks like.   All I need is an example of using GET over TCP/IP.

 

I am working with member hitch who is developing a container app to handle TCP/IP commands. That app works quite however here is a problem with the app that has been documented as a 6.8.x problem and is fixed in 6.9.  The problem seems to be an inordinate number of accesses to the disk containing the container.  As soon as 6.9 becomes a stable release I will move to it.

 

I don't want to use the web and push the 'Spin up' button.  My theater is controlled by an app I wrote. It controls devices such as the nVidia Shield, the Fire TV cube, a Dune HD Player and TiVo boxes. It has its own extensive movie/video librarian with all the content stored on the unRaid server. When I select the librarian to browse the library (prior to selecting the movie/video I want to watch)  I would like to spin up all the disks on the unRaid server. This way the delay when selecting the movie to play and initiating the read from unRaid is significantly shortened (almost 0 ms)  and makes for an improved experience. The disk spin up would be overlapped with the browsing of the library.

 

I will try what you have suggested (emcmd) using Telnet, but I am much more comfortable using TCP/IP. 

 

 

Link to comment
14 minutes ago, barrygordon said:

I will try what you have suggested (emcmd) using Telnet, but I am much more comfortable using TCP/IP. 

 

You *might* want to also consider looking at something akin to https://forums.unraid.net/topic/91450-alexa-unraid-voice-control-how-to/

(Although its geared towards Alexa, but the concept is the same.  Drop a file into dropbox and have the server act upon it).  No CSRF's involved assuming you can upload a file from your app to drop box, and you'd be able to start / do anything you want at all.

Link to comment

I have written a small standalone exe that will spin up all the unraid disks using emcmd via Telnet.  It will be launched when I want to watch a movie and have started the movie librarian.  The spin up will be overlapped by the the action of the user selecting the movie to watch.  I have set a spin down of any disk after an hour of no activity

Edited by barrygordon
update
Link to comment
  • 2 months later...

I am still interested in asynchronously spinning the disks up/down using TCP/IP .  Here is a sample of the prototype command I would send in unRaid version 4. 

"GET /update.htm?cmdSpindownAll=Spin%20Down HTTP/1.1" + vbCrLf + All.

 

If someone could show me how to change the command to include the CSRF token that would be greatly appreciated

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.