[Tutorial] Ruby 1.9.2, Rails 3.1 on QNAP 219P+

Post your questions about Web Server usage and Apache + PHP + MySQL/SQLite web applications.

[Tutorial] Ruby 1.9.2, Rails 3.1 on QNAP 219P+

Postby tkrajacic » Sun Oct 23, 2011 7:29 pm

This is a rewrite of my previous post with updated information.
See http://forum.qnap.com/viewtopic.php?f=32&t=45809

Now I am able to run ruby 1.9.2 and rails 3.1.1 on my QNAP 219P+
It took me 2 days to figure out most of the details to get it running and in the end I had to drop the whole rvm thing since it plain didn't work, but I hardwired the ruby installation and it works for me now.

Things that will be installed:
    Perl 5.8.9 with thread support
    Ruby 1.9.2 (latest)
    node.js & v8 (needed as javascript interpreters)
    rails 3.1.1
perl is only needed for autoreconf which is in turn used by rvm. So if you plan on compiling ruby on your own like I show below, you don't need it.

As a prerequisite I installed the following ipkg packages:
Code: Select all
ipkg install scons gawk sed autoconf git bash coreutils findutils libcurl libcurl-dev make configure python svn sqlite nano openssl openssl-dev

I think all of them are needed since Qnap's built in tools are incomplete and produce cryptic configure or compile errors.
(except for nano, which I just use to edit text files)

Just like in my first post create the following links for the compiler tools
Code: Select all
mkdir -p /home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/
cd /home/slug/optware/cs08q1armel/toolchain/arm-2008q1/bin/
ln -s /opt/bin/gcc arm-none-linux-gnueabi-gcc
ln -s /opt/bin/g++ arm-none-linux-gnueabi-g++


Download the needed sources to a directory on one of your disks (where there is enough space) and not into your home directory when you ssh to your NAS.
I have my stuff compiled under /shares/myname/Sources/ (and that is the directory where I cloned all the source repositories or downloaded the tar.gz archives)

Code: Select all
cd /shares/myname/Sources/
git clone https://github.com/v8/v8.git
cd v8
nano SConstruct

Now find and remove the lines -Wall -Werror because otherwise all warnings will be treated as errors and you won't get far. (and without -Wall the output is more clear)
Code: Select all
scons mode=release library=shared vfp3=off unalignedaccesses=off armeabi=soft mipsabi=softfloat

This is the most important thing on my NAS because otherwise I would get Segmentation faults when using the library.
This might not be necessary on non-ARM units, but then it is kinda trivial anyway I guess and you don't need that guide.

I then linked the created libraries like in my older post:
Code: Select all
ln -s /shares/myname/Sources/v8/libv8preparser.so /usr/lib/libv8preparser.so
ln -s /shares/myname/Sources/v8/libv8.so /usr/lib/libv8.so
This could probably done way better by specifying a prefix during compile or installing the libraries properly?

Further in my Sources directory:
I chose node.js instead of therubyracer, since therubyracer always produced segmentation faults later. Maybe I misconfigured it.
Code: Select all
git clone https://github.com/joyent/node.git
cd node
./configure --prefix=/opt


As for perl (this is not needed if you compile ruby without rvm)
only perl 5.8.9 works. All other version produce segmentation faults on my NAS during compile.
Code: Select all
curl -O http://www.cpan.org/src/5.0/perl-5.8.9.tar.gz
tar xfz perl-5.8.9.tar.gz
cd perl-5.8.9
sh Configure -Dusethreads -Dcc=gcc -Dprefix=/opt -de
Now we need to edit ext/Errno/Errno_pm.PL and comment out the line saying something like
Code: Select all
die "No error definitions found"
Just search for "definition" and it will be the first thing you find
Then continue:
Code: Select all
make
make install
It doesn't pass all test, that's why I didn't include make test, but it works well enough for autoconf.

So far you should have a working perl and node installation.
check with:
Code: Select all
perl -V
node
'node' should get you to the node prompt without any errors. You can close it with 'ctrl-c'

Now there are two different paths to choose.
Either compile ruby yourself, or use rvm to do so.
I tried both, and the compilation process worked fine both times and produced usable ruby 1.9.2 versions.

so you can compile it yourself:
* clone latest source or download source-archive
* cd into new directory
then:
Code: Select all
autoconf
./configure --prefix=/opt
make
make install
This took some time but doesn't produce any errors. If it does, then you probably didn't install all the ipkgs I listed. (especially gawk, sed, coreutils)
I am not sure if that is all since I never 'installed' my build. Maybe someone who goes this way can fill in some information here. (Probably set up PATH and GEM_HOME?)

For rvm I changed to bash and run the install script from the rvm website
before that though you will want to create ~/.rvmrc and add rvm_path=/opt/rvm to it! That way you don't have your rvm directory in your home, where you would run out of space immediately! You can do this with:
Code: Select all
echo 'rvm_path=/opt/rvm' >> ~/.rvmrc

I want to point out that rvm never really worked on my system and I only used it to build the latest ruby in the end, since nothing of rvm's functions worked and with some commands produced annoying error output from the Busybox commands. So in the end i deleted /etc/profile.d/rvm.sh and just set up my environment variables
Code: Select all
export GEM_HOME=/opt/rvm/rubies/ruby-1.9.2-head/lib/ruby/gems/1.9.1
export PATH=/opt/rvm/rubies/ruby-1.9.2-head/bin/:$PATH
Obviously change the paths to your version of ruby!

Make sure to uninstall the ipkg ruby version, which was giving me trouble with the gem directory.
Code: Select all
ipkg remove ruby


then I could install the gems:
Code: Select all
gem install rails
gem install node
gem install execjs
gem install sqlite3 -- --with-sqlite3-lib=/opt/lib


Furthermore there seem to be some incompatibilities and I had to use rack '1.3.3' instead of the latest version with my rails apps (added to Gemfile) to avoid problems.
So in the Gemfile of a new app I add:
Code: Select all
gem rack, '1.3.3'
gem execjs
gem node


That's it.
I have RoR 3.1.1 and ruby 1.9.2 running on my QNAP 219P+


I am pretty sure I didn't remember all the details and I made many errors in the process, so please comment on anything I might have forgotten or could have done better.
I know, the ruby thing is a bit sketchy in the end, but I kinda hacked it together myself to make it work as well.

Someone should be able to make a qpkg out of this whole thing now :P

Update:
I managed to get rvm working properly! :)
now I am stuck at passenger. More specifically with the apache installation and the corresponding files not being found by passenger.
Update 2:
I got passenger to compile and since the build directory from the apache install is not present I tried to build the standalone version with nginx.
This went well(actually not really... I had to modify a C-header to make it compile even, but eventually it worked) up until when I try to start my server where it dies with:
Code: Select all
*** ERROR ***
Could not start Passenger Nginx core:
nginx: [alert] could not open error log file: open()
"/tmp/passenger-standalone.6059/logs/error.log" failed (2: No such file or
directory)
2011/10/23 22:32:40 [emerg] 6071#0: getgrnam("nobody") failed (2: No such file
or directory)
Stopping web server... done
I couldn't find out how to fix those two problems and I am giving up...
tkrajacic
Starting out
 
Posts: 18
Joined: Sat May 14, 2011 3:25 pm
Model: TS-119P+

Re: [Tutorial] Ruby 1.9.2, Rails 3.1 on QNAP 219P+

Postby toufou54 » Sat Nov 05, 2011 11:08 am

HI,
for the nginx fail try to put this user :
user httpdusr everyone;
in the conf file !
toufou54
New here
 
Posts: 4
Joined: Sat Jun 27, 2009 9:12 pm
Model: TS-109/209 Pro II

Re: [Tutorial] Ruby 1.9.2, Rails 3.1 on QNAP 219P+

Postby tkrajacic » Sat Nov 05, 2011 3:20 pm

For nginx standalone this worked fine! Thx!
However I can't find the config file for passenger :(
Where is the default nginx.conf for it?
tkrajacic
Starting out
 
Posts: 18
Joined: Sat May 14, 2011 3:25 pm
Model: TS-119P+

Re: [Tutorial] Ruby 1.9.2, Rails 3.1 on QNAP 219P+

Postby ccb056 » Mon Jan 23, 2012 6:10 pm

I'm thinking about giving this a go on my TS-659. Will it work??

I have a pfsense router running snort as an IPS and would like to run snorby on the qnap. Will it be stable?
ccb056
Starting out
 
Posts: 12
Joined: Mon Sep 20, 2010 2:31 am
Model: TS-659 Pro

Re: [Tutorial] Ruby 1.9.2, Rails 3.1 on QNAP 219P+

Postby johan7210 » Wed Feb 01, 2012 9:07 pm

Can you please explain the steps needed to get rvm working ?
johan7210
First post
 
Posts: 1
Joined: Wed Feb 01, 2012 9:05 pm
Model: TS-259 Pro+

Re: [Tutorial] Ruby 1.9.2, Rails 3.1 on QNAP 219P+

Postby tkrajacic » Wed Feb 01, 2012 9:12 pm

Not sure myself anymore. Sry I am short on time at the moment.
Maybe try rbenv? Should be easier and I might switch to it too in the future.
tkrajacic
Starting out
 
Posts: 18
Joined: Sat May 14, 2011 3:25 pm
Model: TS-119P+

Re: [Tutorial] Ruby 1.9.2, Rails 3.1 on QNAP 219P+

Postby babalooi » Tue May 08, 2012 2:30 am

Trying to install on TS-412.
I'm getting error on installing ipkg configure.

Code: Select all
[~] # ipkg install configure                                                   
Nothing to be done
An error ocurred, return value: 4.
Collected errors:
Cannot find package configure.
Check the spelling or perhaps run 'ipkg update'


Did ipkg update and getting the same error.
babalooi
Starting out
 
Posts: 13
Joined: Sat May 05, 2012 12:09 am
Model: TS-212


Return to Web Server & Applications (Apache + PHP + MySQL / SQLite)

Who is online

Users browsing this forum: No registered users and 4 guests