[HOWTO] Install Serviio in Freenas 8.0.x

Discussion in 'Hacking' started by Stefan Reek, Aug 3, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Stefan Reek Guest

    Member Since:
    Stefan Reek, Aug 3, 2011

    Moderator Note: (Please read to end of thread before trying to follow this tutorial)


    I fooled around a bit to see if I could get Serviio to work on Freenas 8.0.1Beta4.
    As I noticed a lot of people asking for it, but no one that had actually managed to install it I expected it to be rather difficult, but thankfully it wasn't.

    I followed the steps as given in this thread on the serviio forums http://forum.serviio.org/viewtopic.php?f=14&t=2060
    But when I wanted to install the Diablo JRE I noticed there wasn't a FreeBSD 8.x version of it. I then read that the 7.x version could be used if the misc/compat7x port was installed.

    I haven't tried to install the JRE without this port, so I'm not quite sure if it's needed.
    But anyway, this is how you install it:

    (Make sure you are root and you have mounted your file system as read/write)
    Code (text):
    1.  
    2. su
    3. mount -urw /
    4.  
    First you'll have to get the ports by using
    Code (text):
    1. portsnap fetch -d <fetch dir>
    The ports have to be downloaded to you data disks as /var on the usb installation
    does not have enough space for it, so make sure <fetch dir> is on your data disks.

    Then you have to extract the ports using:
    Code (text):
    1. portsnap extract -d <fetch dir> -p <ports dir>
    The ports dir should be on your data disks as wel.

    now go to <ports dir>/misc/compat7x and run
    Code (text):
    1.  make install clean
    For me, that gave a file not found error that I solved by editing
    /usr/share/mk/bsd.port.mk

    Change the PORTSDIR? line to
    Code (text):
    1.  PORTSDIR?=<ports dir>
    then run the make command again.

    Now you'll need to add a lot of dependencies of serviio, enter the following commands:
    Code (text):
    1.  
    2. pkg_add -v -r xtrans
    3. pkg_add -v -r xproto
    4. pkg_add -v -r xextproto
    5. pkg_add -v -r javavmwrapper
    6. pkg_add -v -r ffmpeg
    7.  
    When that's done there's only one more dependency to get: the Java JRE
    go to this page and download the FreeBSD 7.x JRE for your architecture.
    In my case the file was called "diablo-jre-freebsd7.amd64.1.6.0.07.02.tbz"
    You'll need to store that somewhere on your data disks as well.
    Then go to the place where you stored the file and enter
    Code (text):
    1. pkg_add -v diablo-jre-freebsd7.amd64.1.6.0.07.02
    Make sure to change the filename if you got another architecture.

    This takes a while and will probably generate some warnings about some of your packages being to new, but you can safely ignore those.

    Ok, now that we've gotten all prerequisites of serviio installed we can now install serviio itself.
    Go to the serviio site and download the linux tar.gz file.
    Place this somewhere on your NAS, I put it in a data directory again.

    Go to the directory containing the file and unzip it:
    Code (text):
    1.  tar xvfz serviio-0.5.2-linux.tar.gz
    Now we have to replace the startup script with an edited version of it.
    Go to the bin folder and backup your old config file:
    Code (text):
    1. mv serviio.sh serviio.sh.old
    Then create a new serviio.sh file, using vi or nano or whatever editor you like and paste the following into it:
    Code (text):
    1.  
    2. #!/bin/sh
    3. ### ====================================================================== ###
    4. ##                                                                          ##
    5. ##  Serviio start Script                                                    ##
    6. ##                                                                          ##
    7. ### ====================================================================== ###
    8.  
    9. DIRNAME=`dirname $0`
    10. PROGNAME=`basename $0`
    11.  
    12. # OS specific support (must be 'true' or 'false').
    13. cygwin=false;
    14. darwin=false;
    15. linux=false;
    16. case "`uname`" in
    17.     CYGWIN*)
    18.         cygwin=true
    19.         ;;
    20.  
    21.     Darwin*)
    22.         darwin=true
    23.         ;;
    24.        
    25.     Linux)
    26.         linux=true
    27.         ;;
    28. esac
    29.  
    30. # For Cygwin, ensure paths are in UNIX format before anything is touched
    31. if $cygwin ; then
    32.     [ -n "$SERVIIO_HOME" ] &&
    33.         SERVIIO_HOME=`cygpath --unix "$SERVIIO_HOME"`
    34.     [ -n "$JAVA_HOME" ] &&
    35.         JAVA_HOME=`cygpath --unix "$JAVA_HOME"`    
    36. fi
    37.  
    38. # Setup SERVIIO_HOME
    39. if [ "x$SERVIIO_HOME" = "x" ]; then
    40.     # get the full path (without any relative bits)
    41.     SERVIIO_HOME=`cd $DIRNAME/..; pwd`
    42. fi
    43. export SERVIIO_HOME
    44.  
    45. # Setup the JVM
    46. if [ "x$JAVA" = "x" ]; then
    47.     if [ "x$JAVA_HOME" != "x" ]; then
    48.     JAVA="$JAVA_HOME/bin/java"
    49.     else
    50.     JAVA="java"
    51.     fi
    52. fi
    53.  
    54. # Setup the classpath
    55. SERVIIO_CLASS_PATH="$SERVIIO_HOME/lib/serviio.jar:$SERVIIO_HOME/lib/derby.jar:$SERVIIO_HOME/lib/jcs.jar:$SERVIIO_HOME/lib/concurrent.jar:$SERVIIO_HOME/lib/freemarker.jar:$SERVIIO_HOME/lib/httpcore.jar:$SERVIIO_HOME/lib/jaudiotagger.jar:$SERVIIO_HOME/lib/jul-to-slf4j.jar:$SERVIIO_HOME/lib/jcl-over-slf4j.jar:$SERVIIO_HOME/lib/log4j.jar:$SERVIIO_HOME/lib/sanselan.jar:$SERVIIO_HOME/lib/slf4j-api.jar:$SERVIIO_HOME/lib/slf4j-log4j12.jar:$SERVIIO_HOME/lib/org.restlet.jar:$SERVIIO_HOME/lib/org.restlet.ext.xstream.jar:$SERVIIO_HOME/lib/xstream.jar:$SERVIIO_HOME/config"
    56.  
    57. # Setup Serviio specific properties
    58. JAVA_OPTS="-Djava.net.preferIPv4Stack=true -Dderby.system.home=$SERVIIO_HOME/library -Dserviio.home=$SERVIIO_HOME -Dserviio.remoteHost=192.168.0.188"
    59.  
    60. # For Cygwin, switch paths to Windows format before running java
    61. if $cygwin; then
    62.     SERVIIO_HOME=`cygpath --path --windows "$SERVIIO_HOME"`
    63.     JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
    64.     SERVIIO_CLASS_PATH=`cygpath --path --windows "$SERVIIO_CLASS_PATH"`
    65. fi
    66.  
    67. # Execute the JVM in the foreground
    68. "$JAVA" -Xmx384M $JAVA_OPTS -classpath "$SERVIIO_CLASS_PATH" org.serviio.MediaServer "$@"        
    69.  
    Make sure to change the ip-address 192.168.0.188 to the ip-address of your NAS.

    That's it, you can now run
    Code (text):
    1.  ./serviio.sh &
    And serviio will run.

    Use the console from another pc to connect and set it up, you can find instructions to do so here.
  2. Offline

    emb

    Member Since:
    Jul 14, 2011
    Messages:
    3
    Message Count:
    3
    Likes Received:
    0
    Trophy Points:
    1
    emb, Aug 4, 2011

    A step by step tutorial would be greatly appreciated (when you have time). -- Thanks
  3. Offline

    Stefan Reek Guest

    Member Since:
    Stefan Reek, Aug 4, 2011

    Well I've found some time to expand the tutorial a bit, it now contains all the steps necessary to install serviio on your system.
    I hope the steps are clear enough. I'm curious to see if this works for you.

    If I have some time I'll try to see if I can make a nice startup script so you don't have to run the script manually everytime the system is rebooted.
  4. Offline

    emb

    Member Since:
    Jul 14, 2011
    Messages:
    3
    Message Count:
    3
    Likes Received:
    0
    Trophy Points:
    1
    emb, Aug 4, 2011

    I won't have time to try it out until tomorrow evening but I'm excited to give it a go. -- Many thanks.
  5. Offline

    emb

    Member Since:
    Jul 14, 2011
    Messages:
    3
    Message Count:
    3
    Likes Received:
    0
    Trophy Points:
    1
    emb, Aug 6, 2011

    I tried this last night and was not able to get past the ports install.
    I changed the PORTSDIR? to reflect my location and got past the "file not found" error but ended with this:
    Code (text):
    1. freenas02#  make install clean
    2. ===>  Installing for compat7x-amd64-7.3.703000.201008_1
    3. ===>   Generating temporary packing list
    4. ===>  Checking if misc/compat7x already installed
    5. (cd /mnt/vol01/storage/serviio/ports/misc/compat7x/work/compat7x-amd64-7.3.70300 0.201008/lib && install  -o  -g  -m  *.so.* /usr/local/lib/compat)
    6. install: invalid file mode: libalias.so.6
    7. *** Error code 64
    8.  
    9. Stop in /mnt/vol01/storage/serviio/ports/misc/compat7x.
    Any ideas?
  6. Offline

    Stefan Reek Guest

    Member Since:
    Stefan Reek, Aug 6, 2011

    When I run "make install clean" the command is:
    Code (text):
    1.  
    2. install  -o root -g wheel -m 444 *.so.* /usr/local/lib/compat
    3.  
    A quick look at the makefile shows that for some reason ${INSTALL_DATA} is not correct for you.
    You might be able to solve it by adding
    Code (text):
    1.  
    2. INSTALL_DATA=install -o root -g wheel -m 444
    3.  
    to the top of the Makefile in /mnt/vol01/storage/serviio/ports/misc/compat7x
    Or maybe below the line
    Code (text):
    1.  
    2. .include <bsd.port.pre.mk>
    3.  
    Let me know if that works

    I should also note that after rebooting I had to
    Code (text):
    1.  
    2. mount -urw /
    3. pkg_add -v -r javavmwrapper
    4.  
    To be able to start serviio again, so the solution is not perfect yet.

    I do have serviio and transmission working now on my system :D
  7. Offline

    VNMan

    Member Since:
    Aug 4, 2011
    Messages:
    5
    Message Count:
    5
    Likes Received:
    0
    Trophy Points:
    0
    VNMan, Aug 7, 2011

    I use csup to install serviio as serviio is available under fresh ports.

    packages needed

    xtrans
    xproto
    xextproto
    javavmwrapper
    diablojdk.....

    then compile and install serviio under /usr/ports/net/serviio...
  8. Offline

    joeschmuck Old Man

    Member Since:
    May 28, 2011
    Messages:
    2,566
    Message Count:
    2,566
    Likes Received:
    81
    Trophy Points:
    48
    Occupation:
    Electrical Engineer, Data Analysis, and Management
    Location:
    Virginia
    joeschmuck, Aug 8, 2011

    You make it sound easy. Could you update your posting to include a step by step guide. I know Stefan started this How To guide for which I am grateful. I will try it out next week when I return home.

    I am curious on two things: 1) how much of an impact did it have to the free file space on the Flash drive (boot), 2) What sized flash drives are you both using?
  9. Offline

    VNMan

    Member Since:
    Aug 4, 2011
    Messages:
    5
    Message Count:
    5
    Likes Received:
    0
    Trophy Points:
    0
    VNMan, Aug 8, 2011

    I think my method is almost the same but...
    OK here goes

    I find it much easier to ssh to the FreeNAS box than connect directly. I am sure there is a how to install ssh but here is my short version -

    First you need to activate ssh service on FreeNAS and create a user that is in the group "wheel". Then this is the only time you need to connect directly to FreeNAS, you need to login to FreeNAS and do

    Use putty to logon using ssh....

    Download Java jre / jdk and install as in the first post.

    From now on my method is a little different than Stefan's.

    Follow this guide herehttp://www.freebsd.org/doc/handbook/ports-using.html

    Since you download only portion of ports it is much smaller but you will miss two important directories and they are "Mk" and "Templates". These can be downloaded from FreeBSD website, I downloaded the whole ports.tar.gz file from ftp.freeBSD.org and extract the necessary directories and put them under /usr/ports/.

    now to compile serviio

    The Java jre /jdk that you installed is not compatible with FreeNAS 8.x, therefore you need the file lib map.conf under /etc/ which consists of two lines -


    Edit /etc/rc.conf for serviio service

    and insert these two lines -

    To start serviio service -

    You will now need to install serviio-console(client) to configure your serviio Media server !!!

    joeschmuck -

    1) Since serviio uses the directory /var/db/ to store its database, you need to mount the /var somewhere else. I use a separate memory stick for this.
    2) the boot drive that I have is 8.1 GB, modified so that FreeNAS uses 7 GB for first partition. Plus an extra 2GB memory stick especially for the /var/.
  10. Offline

    VNMan

    Member Since:
    Aug 4, 2011
    Messages:
    5
    Message Count:
    5
    Likes Received:
    0
    Trophy Points:
    0
    VNMan, Aug 8, 2011

    The contents of ports-supfile

    *default host=cvsup.de.freebsd.org
    *default base=/usr
    *default prefix=/usr
    *default release=cvs
    *default delete use-rel-suffix
    ports-net
  11. Offline

    Stefan Reek Guest

    Member Since:
    Stefan Reek, Aug 9, 2011

    Ah, I didn't know serviio was available under fresh ports.
    I might try this method myself if I have some time, thanks VNMan!
    The method I used takes about 300M on the USB stick, and some more on the data disks.
    The data on the data disks can be removed after the installation though.
    I use 8G USB stick, but have not modified it, so it uses only 2G.
  12. Offline

    Nihilator

    Member Since:
    Aug 17, 2011
    Messages:
    1
    Message Count:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Nihilator, Aug 17, 2011

    VNMan,

    Could you tell me how you got "/var" to mount on your 2GB memory stick? I have FreeNAS 8 (Full Install) and it mounts "/var" on a memory device "/dev/md2". What commands do I type if I want to mount "/var" on my memory stick (which is "/dev/da0s1d)?

    Once I do mount "/var" to my memory stick, how would I set it up to mount "/var" automatically? I can't use "etc/fstab", because "/etc" is also mounted as a memory device ("/dev/md0") and the changes you make are gone after a reboot.

  13. Offline

    GeoffLee

    Member Since:
    Aug 27, 2011
    Messages:
    11
    Message Count:
    11
    Likes Received:
    0
    Trophy Points:
    1
    GeoffLee, Sep 11, 2011

    Stefan,

    I accidentally installed the wrong version of Java (installed the 6.0 version instead of 7.0). How do I uninstall Java 6.0 from my system now? Sorry for the noob question!
  14. Offline

    Athanasios Kakargias Guest

    Member Since:
    Athanasios Kakargias, Sep 24, 2011

    I needed to add the following file
    /etc/libmap.conf
    with contents
    libz.so.4 libz.so.5
    to overcome this java crash:
    Error occurred during initialization of VM
    Unable to load ZIP library: /usr/local/diablo-jre1.6.0/lib/amd64/libzip.so

    No misc/compat7x ports used, actually no ports at all just the packages. no jdk either.
  15. Offline

    Damon Opacak Guest

    Member Since:
    Damon Opacak, Sep 25, 2011

    Thanks, got Serviio installed and working (mostly) due to this tutorial

    But for some reason, everytime I restart the Freenas box, I have to redo the 'pkg_add -v -r javavmwrapper' command, otherwise it fails to start Serviio. I'm not full bottle on freebsd, but is it replacing or removing usr on reboot?

    Also, is there any way in Freenas 8 I can get it to run the script to run serviio on startup? On freenas 7 I put scripts I wanted to run in advanced|postinit, but cant find in freenas 8. Just means everytime I boot my NAS box, I need to putty in and run ./serviio.sh &

    Any ideas?
  16. Offline

    Athanasios Kakargias Guest

    Member Since:
    Athanasios Kakargias, Sep 25, 2011

    java: error: can't find /usr/local/etc/javavms configuration file

    If you are on USB you need also before rebooting to

    Code (text):
    1. cp /etc/local/javavm* /conf/base/etc/local/
    2. echo libz.so.4 libz.so.5 > /conf/base/etc/libmap.conf
  17. Offline

    Damon Opacak Guest

    Member Since:
    Damon Opacak, Sep 25, 2011

    Thanks Anthanasios, any idea how to make the './serviio.sh &' command run on startup?
  18. Offline

    Athanasios Kakargias Guest

    Member Since:
    Athanasios Kakargias, Sep 25, 2011

    seems i totally missed VNMan's post and researched things he already said ;)

    anyway
    if you are running from usb and untared serviio to /usr/local/serviio or something similar
    in the JAVA_OPTS section of serviio.sh add those properties

    Code (text):
    1. -Dderby.stream.error.file=/var/derby.log
    2. -Dderby.system.home=/mnt/some_writable_directory_on_some_disk
    and

    Code (text):
    1. cp -R /usr/local/serviio/library/* /mnt/some_writable_directory_on_some_disk
    2.  
    this will keep derby happy for starters..
    also

    Code (text):
    1. rm -r /usr/local/serviio/log
    2. ln -s /var /usr/local/serviio/log
    3.  
    to redirect logs to /var


    as for autostart as VNMan says we need to play with rc.conf but in our case not the one in /etc/ but in /conf/base/etc... hang on im working on it right now
  19. Offline

    Athanasios Kakargias Guest

    Member Since:
    Athanasios Kakargias, Sep 26, 2011

    autostarting serviio

    ok since i couldn't find the rc script anywhere i made my own so if any bsd guru comes by don't be harsh :p

    fisrt create this file on /etc/rc.d/serviio and /conf/base/etc/rc.d/serviio
    with this content
    Code (text):
    1. #!/bin/sh
    2.  
    3. # PROVIDE: serviio
    4. # REQUIRE: LOGIN
    5. # KEYWORD: shutdown
    6.  
    7. . /etc/rc.subr
    8.  
    9. name="serviio"
    10. rcvar=`set_rcvar`
    11. eval "${rcvar}=\${${rcvar}:-'NO'}"
    12. serviio_msg=${serviio_msg:-"serviio not serving"}
    13.  
    14. pidfile="/var/run/${name}.pid"
    15.  
    16. start_cmd="${name}_start"
    17. stop_cmd="${name}_stop"
    18.  
    19. required_files="/usr/local/serviio-0.6/bin/serviio.sh"
    20.  
    21. load_rc_config $name
    22.  
    23. serviio_start()
    24. {
    25.     /bin/sh /usr/local/serviio-0.6/bin/serviio.sh &
    26.         echo "serviio up"
    27. }
    28.  
    29. serviio_stop()
    30. {
    31.     /bin/sh /usr/local/serviio-0.6/bin/serviio.sh -stop
    32.         echo "serviio down"
    33. }
    34.  
    35.  
    36. run_rc_command "$1"
    37.  
    file must be rx ie
    Code (text):
    1. chmod +x serviio
    and append in /etc/rc.conf and /conf/base/etc/rc.conf
    the line
    Code (text):
    1. serviio_enable="YES"
    I needed also to pinpoint $JAVA variable in serviio.sh like that
    Code (text):
    1.  
    2. # Setup the JVM
    3. if [ "x$JAVA" = "x" ]; then
    4.     if [ "x$JAVA_HOME" != "x" ]; then
    5.         JAVA="$JAVA_HOME/bin/java"
    6.     else
    7.         JAVA="/usr/local/bin/java"
    8.     fi
    9. fi
    10.  
    maybe this could done also by exporting JAVA in the rc script but not going back now ;)
  20. Offline

    Damon Opacak Guest

    Member Since:
    Damon Opacak, Sep 27, 2011

    Hey mate, cheers, but I installed Serviio onto my mounted volume /mnt/RAID/serviio, so im guessing I dont need to do the changes you suggested?
Thread Status:
Not open for further replies.

Share This Page