[HOWTO] Updated: Get Roksbox working with FreeNAS 8.2

Discussion in 'Hacking' started by joelrondeau, Jan 29, 2012.

  1. joelrondeau New Member

    Member Since:
    Jan 28, 2012
    Message Count:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Occupation:
    Software Engineer
    Location:
    Glendale, WI
    joelrondeau, Jan 29, 2012

    This guide is for FreeNAS 8.0.X. The 8.2.X guide is the next post.

    Roksbox is a private channel for the Roku media player that is used to stream local content to the Roku.

    I've been serving up my video files from a Windows 7 machine using IIS, but really wanted to use the NAS. I figured I'd have to wait for the plugins in 8.2, but when 8.0.3 p1 was released and I saw the multimedia release, I thought it might be available. Once I discovered it wasn't, I wondered if I could just use lighttpd to serve it up for me.

    My theory was that I would need to create a directory under the existing FreeNAS www structure, and if I could access it via a web browser, then Roksbox probably could too. Initial attempts were showing no promise, so I started checking out some of the python scripts and that's when I found that FreeNAS appeared to be willing to serve up anything under the media directory without a problem. From there it was just a matter of adding the required mime type(s) and adding the directories.

    Instructions:
    Use SSH to login to your FreeNAS (obviously, enable SSH on the FreeNAS if you haven't already).

    Login as root and mount as read/write.
    Code (text):
    1.  
    2. su
    3. mount -wu /
    4.  
    Now, modify lighttpd.conf to add the necessary mime types and turn on directory browsing. lighttpd.conf is in 2 places. I don't know if you could just modify the second place and reboot. I do know that just modifying the first place won't survive a reboot. As it is, I modified both and after a reboot, it was correct. Also, if someone wants to figure out a way to do this with sed, feel free. I just used vi.

    To add mime types to lighttpd.conf, go to the area that starts with "mimetype.assign" and add lines for each mime type. For example:
    ".mp4" => "audio/mpeg"
    ".m4v" => "video/mpeg"

    Directory browsing is only necessary if not using xml files for everything. You must reboot for this to take effect. To enable it, find the following two lines in lighttpd.conf and uncomment (remove the #):
    #dir-listing.activate = "enable"
    #dir-listing.encoding = "utf-8"

    Code (text):
    1.  
    2. cd /etc/local/lighttpd
    3. vi lighttpd.conf
    4. cd /conf/base/etc/local/lighttpd
    5. vi lighttpd.conf
    6.  
    Finally (for FreeNAS), create a symbolic link for your videos, music and photos under the media directory. In my case, I store my videos at /mnt/d0/movies/M4V, music at /mnt/d0/music and photos at /mnt/d0/pictures.
    Then, go back to readonly.

    Code (text):
    1.  
    2. cd /usr/local/www/freenasUI/media
    3. ln -s /mnt/d0/movies/M4V videos
    4. ln -s /mnt/d0/music music
    5. ln -s /mnt/d0/pictures photos
    6. mount -ru /
    7.  
    Roksbox settings:
    Set the media IP address to match your FreeNAS.
    Set the media root folder to "media"
    Set the video folder path to "videos"
    Set the music folder path to "music"
    Set the photo folder path to "photos"

    I use an xml file (Videos.xml) to store my video information. For each video, start the path with media/videos/
    I do not use an xml file for music or photos. I expect similar settings are necessary.
  2. joelrondeau New Member

    Member Since:
    Jan 28, 2012
    Message Count:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Occupation:
    Software Engineer
    Location:
    Glendale, WI
    joelrondeau, Aug 28, 2012

    This guide is for 8.2.X. The 8.0.X guide is the previous post.

    Note: I now have new directions for using a BSD jail. They are here:
    http://forums.freenas.org/showthread.php?10558-HOWTO-Serve-up-media-to-Roksbox-from-a-FreeNAS-jail

    Roksbox is a private channel for the Roku media player that is used to stream local content to the Roku.

    The main difference between the 8.2.X and 8.0.X instructions is that 8.0.X used lighttpd, while 8.2.X uses nginx.

    The proper answer for doing this on 8.2.X would be to run a FreeBSD jail and serve up the files from there. I have not set up jails yet and this was relatively easy, so here we go...

    Instructions:
    Use SSH to login to your FreeNAS (obviously, enable SSH on the FreeNAS if you haven't already).

    Login as root and mount as read/write.
    Code (text):
    1.  
    2. su
    3. mount -wu /
    4.  
    Now, modify nginx.conf to add the media directory (we'll create that later) and turn on autoindexing. Autoindexing is only necessary if you do not use xml files for everything. I'm using vi to modify the nginx.conf file.

    Go into nginx.conf and after the section that starts with
    location /static
    Add the following lines:

    location /media {
    alias /usr/local/www/media;
    autoindex on;
    }
    Code (text):
    1.  
    2. cd /usr/local/etc/nginx
    3. vi nginx.conf
    4.  
    Finally (for FreeNAS), create the media directory and add symbolic links for your videos, music and photos under the media directory. In my case, I store my videos at /mnt/d0/movies/M4V, music at /mnt/d0/music and photos at /mnt/d0/pictures. Then, go back to readonly.
    Code (text):
    1.  
    2. cd /usr/local/www
    3. mkdir media
    4. cd media
    5. ln -s /mnt/d0/movies/M4V videos
    6. ln -s /mnt/d0/music music
    7. ln -s /mnt/d0/pictures photos
    8. mount -ru /
    9.  
    Roksbox settings:
    Set the media IP address to match your FreeNAS.
    Set the media root folder to "media"
    Set the video folder path to "videos"
    Set the music folder path to "music"
    Set the photo folder path to "photos"

    I use an xml file (Videos.xml) to store my video information. For each video, start the path with media/videos/
    I do not use an xml file for music or photos. I expect similar settings are necessary.
  3. Ftaylor74 New Member

    Member Since:
    Sep 30, 2012
    Message Count:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Ftaylor74, Sep 30, 2012

    joelrondeau,
    Your post is great so thanks. For some reason though, I'm having no luck accessing videos in the media folders I set up. Background, I am new to FreeNas, Linux/unix so I am probably doing something wrong. I managed to update the nginx.conf file without difficulty, and created the media directory, so I now have a /usr/local/www/media folder. The symbolic links to the videos, music and photo folders appear to be in place. I've gone into Roksbox and set the media path to /192.168.2.8:0080/ (I read somewhere that Freenas uses port 80 for its webserver port). I have not yet discovered a way within FreeNas to see or change that value. In fact I haven't seen a webserver service at all. Finally, Ive added two video folders,each containing a single mkv video file.
    Anyway, Roksbox canno seem to find the files. Any ideas that you have would be greatly appreciated. Thanks
  4. joelrondeau New Member

    Member Since:
    Jan 28, 2012
    Message Count:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Occupation:
    Software Engineer
    Location:
    Glendale, WI
    joelrondeau, Oct 1, 2012

    There are a couple of things to try here. Depending on what works, I'll try to get the HowTo updated.

    First, go to a PC, open a web browser and check http://192.168.2.8/media/movies and see if you get a directory listing. If you don't, the first thing to do is reboot the FreeNas server, just to make sure it doesn't need to be reset to have the media directories served up correctly. If you still don't see a directory listing, it's time to check the FreeNas setup (go through the HowTo guide again and verify everything is as it should be). Once you verify everything works from a PC, you can feel confident the FreeNas side is set up correctly and start worrying about the Roksbox side.

    Second, go back into Roksbox and set the media path to http://192.168.2.8 (I just checked my setting). It is not necessary to use the :0080 at the end. By default FreeNas will server at port 80 and Roksbox will connect to port 80. Also make sure that the Video Folder Path matches what worked in the web browser. Make sure the case matches, as the FreeNas server is case sensitive.

    If everything looks correct, my next suggestion is to follow the Roksbox website's example for creating an xml file and try that method. If Rockbox finds an xml file but doesn't do the directory search correctly, then it's probably an nginx setting. I'm going to see if I have similar problems (I always use the xml file for videos).

    Update: I can confirm that I have the same problem with correct settings without using the xml file. I know that I did not have this problem with 8.0.X, so it appears to be an nginx thing. I'll look into it, but it's possible someone else with more nginx knowledge may have the answer.
  5. Ftaylor74 New Member

    Member Since:
    Sep 30, 2012
    Message Count:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Ftaylor74, Oct 3, 2012

    Thanks for getting back with me on this.
    I attempted to use the web browser to view the media/movies directory listing, but had no luck. Each time it takes me to the FreeNas webgui login page. I imagine that Roksbox is running into the same problem. I will try creating an XML directory, as you suggest, but I'm not sure how or where to install it. .../www/media/ ? I'm very new to linx (I think that is what I am using when I shell to the root directory.

    Oh, one last thing, you mention using SSH to login to FreeNas. Is that necessary for modifying the files structures and to edit nginx.conf, or is it only a 'best practices' kind of thing. My Freenas is behind a firewall, and I 'expect' to be the only one with access to the server, although who knows. In any case, it seems that SSH has to be disabled in order for Roksbox to communicate with the webserver, because I didn't see any instructions for passing a key from Roksbox to access the server.

    Thanks again for taking the time to look at my problem
  6. joelrondeau New Member

    Member Since:
    Jan 28, 2012
    Message Count:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Occupation:
    Software Engineer
    Location:
    Glendale, WI
    joelrondeau, Oct 4, 2012

    If you are getting the FreeNas webgui login page, that leads me to believe that your nginx.conf file is not set up correctly. If I go to a fake directory on my Nas, like http://192.168.2.8/fakedir then I get the webgui login page. However, if I go to a fake directory under media, like http://192.168.2.8/media/fakedir then I get a 404 error. So right now, nginx doesn't think that your media directory should be accessible.

    Roksbox doesn't use an XML directory. It is just a single xml file in the media/videos directory. Given the issues I've had without the xml file, this is the way to go (unless someone can figure out the issue. I haven't figured it out yet). However, don't worry about this until you can get a web browser to see the directories properly. Otherwise, you're right, right now Roksbox is just seeing the login page.

    As for the SSH bit, that is only for shell access, not for Roksbox. I generally use PuTTY to connect (via SSH) for shell access. As long as you have a way to get shell access without SSH (you could use the shell available from the GUI if you want), there's no reason to turn it on.
  7. Ftaylor74 New Member

    Member Since:
    Sep 30, 2012
    Message Count:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Ftaylor74, Oct 4, 2012

    Your test of fakedir was very useful. (and thanks for confirming my suspicions abbout SSH. That seemed like an unnecessary complication in my quest to get roksbox talking to FreeNas. Maybe when I'm smarter on this I will attempt to enable SSH, but for now, its one less thing to worry about.)

    After I read your note, I went back into shell and took a look at nginx.conf. Sure enough, the location /media { code snippet was missing from the file. I re-entered the /media alias info, saved the .conf file and exited the shell and FreeNas. I entered the http:// address in firefox, and voila, the browser showed the media folder, and the three subfolders, music, photos and videos. (without going to the login screen). However, when I clicked on the video folder, I got the 404 error. Likewise when I clicked on the music and video folders, I got the same result. But at least i was able to connect with media, so I assumed I was getting closer.

    I closed out the browser and went into Freenas and entered the shell. By mistake, I typed in cd /media, and I was surprised to be taken to the [root@freenas ~]/media folder. When I listed the contents of the directory, lo and behold there were the symbolic links to the video, photo and music folders (/mnt/data/videos, /mnt/data/photos, /mnt/data/music). I was surprised because I was pretty sure that I had placed those links in the /usr/local/www/media folder. I navigated to what I thought was the right location for the media folder and sure enough it was there and the symbolics links were also in place. What the heck?

    So I did something stupid. I used the rm command to remove the /media folder from the root directory, rebooted and then went to the browser to find the /media folder. Unfortunately, the command brought me back to the login screen, and despite numerous tweeks and retries, I have not been able to get the browser to find the media folder since.

    I think two things are happening. First, I think that my reboots are resetting the nginx.conf to its original configuration I lose the "location /media {" code segment. Second, I don't think that nginx is being activated, or at least, it is not reading the nginx.conf file where the alias for the /media folder is read.

    Oh, one other thought. While I was browsing through the nginx folder I saw the mime type file. I opened it up and noticed that their is no mime type for .mkv files. Someday, I think I'm going to get this server working properly, and when I do, I hope to serve .mkv files. Is it necessary to add the mime type to get it to work? I think it probably is required (but not a guarantee that it will work).

    Thanks again for your help.
    Regards
  8. Ftaylor74 New Member

    Member Since:
    Sep 30, 2012
    Message Count:
    4
    Likes Received:
    0
    Trophy Points:
    0
    Ftaylor74, Oct 4, 2012

    Ok, itrs confirmed. Each time I reboot, i lose the code section

    location /media{
    alias /usr/local/www/media;
    autoindex on;
    }

    That can't be a good thing. It explains a lot. I've been rebooting to make sure that the nginx.conf file gets read, and each time the location /media snippet gets dropped. Weird.
  9. joelrondeau New Member

    Member Since:
    Jan 28, 2012
    Message Count:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Occupation:
    Software Engineer
    Location:
    Glendale, WI
    joelrondeau, Oct 5, 2012

    Going to try to go through these one by one.
    First, the /media folder:
    I do have a /media folder. It is empty. I can't say for sure whether I created it (I don't think so), or if it was there from the start (my guess). I doubt this has anything to do with your issues.

    Second, the mime types:
    If I go to /usr/local/etc/nginx and look at mime.types, I can see (very close to the bottom), a line that reads
    video/x-m4v m4v;
    I've never messed with this file, so barring the upgrade from 8.0.4 to 8.2.0 being smart enough to use my 8.0.4 mime type changes (really, I can't imagine someone took the time to do that), I expect it to be there for you as well.

    Now as for nginx.conf getting reset on a reboot: That is actually what I expected would happen to me, and I was very surprised that it didn't. I expected it based on my 8.0.X guide, where I had to modify lighttpd.conf in 2 places to get it to survive a reboot.
    The only time nginx.conf has been reset on me was when I installed a bsd jail.

    Give this a try:
    Follow the instructions again, except that you can skip the bit about setting up the directories.
    After you modify the nginx.conf file, go to /conf/base/etc/local/nginx and modify that nginx.conf file the same way. Then see if it survives a reboot. That is what I would have expected to do, except that my system worked without doing it.
  10. ANTT7374 New Member

    Member Since:
    Dec 16, 2012
    Message Count:
    2
    Likes Received:
    0
    Trophy Points:
    0
    ANTT7374, Dec 24, 2012

    Hi joelrondeau,

    I really appreciate your instructions above. I am also new to the FreeNAS/BSD front so am still in the look before I leap mode. I'm running FreeNAS 8.3 and have Firefly and miniDLNA running. Streaming is just fine from miniDLNA to both my PS3 and Samsung BluRay player, but now trying (unsuccessfully) to get my movies streaming to my Roku 2 XS.

    Before I go all crazy and start following this guide verbatim, I just thought I'd check to see if there were any important caveats that you were aware of for 8.3?

    Thanks, and Merry Christmas or Happy Holidays!
  11. joelrondeau New Member

    Member Since:
    Jan 28, 2012
    Message Count:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Occupation:
    Software Engineer
    Location:
    Glendale, WI
    joelrondeau, Dec 25, 2012

    First off, the Roku does not support DLNA, so you won't be able to use miniDLNA to send movies to the Roku.

    I haven't upgraded to 8.3 yet. I do not expect any major differences between 8.2 and 8.3, but I won't know until I do it. I still haven't diagnosed the issue with reading directories from nginx (I use xml files), so that probably won't work, unless 8.3 changes nginx functionality.
  12. ANTT7374 New Member

    Member Since:
    Dec 16, 2012
    Message Count:
    2
    Likes Received:
    0
    Trophy Points:
    0
    ANTT7374, Dec 25, 2012

    Thanks, joelrondeau,

    I know Roku doesn't support DLNA (sure would be nice, though, wouldn't it! lol), but I was hoping that I could use the same folders/mount points already setup with miniDLNA instead of making a new structure. I *think* that creating mount points via the UI is the same thing as using the ln shell command?

    I may revisit this later, but for now I decided to return the Roku because it's primary purpose was supposed to be to stream media (h.264 encoded video, MP3s, and family photos) from my FreeNAS box to the family room TV. I decided to but a different device that will work out of the box with FreeNAS and save me some headaches. Funny how although I've been a computer programmer for 18+ years it's all been in the Microsoft realm and this *nix stuff makes my head hurt! :)

    Happy holidays!
    Thad
  13. cyberjock Forum Guard Dog/Admin

    Member Since:
    Mar 25, 2012
    Message Count:
    10,486
    Likes Received:
    463
    Trophy Points:
    83
    cyberjock, Dec 25, 2012

    If you used Plex the Roku would work exactly how you want. You would need to setup a Plex server however which you don't sound like you would be too interested in.
  14. joelrondeau New Member

    Member Since:
    Jan 28, 2012
    Message Count:
    13
    Likes Received:
    0
    Trophy Points:
    1
    Occupation:
    Software Engineer
    Location:
    Glendale, WI
    joelrondeau, Dec 28, 2012

    I have finally upgraded to 8.3 and discovered that my nginx.conf file is reset on every NAS reboot (someone complained of this in a post about my 8.2 guide). I have a workaround for it, but I also finally took the time to make a jail for serving up the files. It was fairly straightforward and doesn't have the non-XML file problems. I hope to have a guide (in the non-hacking section of the forum) by Jan 1st. I'll include links from here when that's done.

    Here is the link for the BSD jail instructions:
    http://forums.freenas.org/showthread.php?10558-HOWTO-Serve-up-media-to-Roksbox-from-a-FreeNAS-jail

    As for Plex, I tried it out but found that I preferred Roksbox. I may try it out again (it's been over a year).

Share This Page