NodeJS on the Drobo
Recently I have been loading data onto my
DroboFS. Much of it I would like to share with family and friends, but I also want others to be able to share files with me, too. I considered many options for file sharing, and settled on
WebDAV (
specification). However, the only software already compiled for the Drobo which supports WebDAV was
lighttpd. Its WebDAV implementation is
incomplete, so it has different problems depending on which client connects. I've been working with JavaScript very closely for some time, have been enjoying working with
NodeJS, and found a module called
jsDAV, so I thought to myself, "Why not install NodeJS on my Drobo?" The following is a HOWTO I've pieced together after a week of struggling with it.
WebDAV
Why did I choose WebDAV?
- File/folder based organization (not package based, search based, seed files, etc.)
- I have no expectation of keeping other metadata (executable flags, creation time, etc.)
- Native support for the protocol in Windows, Mac, and Linux (nothing to install)
- Supports SSL encryption (except on Windows XP)
- Supports authentication controls per-file or per-folder (it's "just a web page" when it comes to access control)
- Can be mounted as a "local" filesystem (transparent to programs accessing the files)
- Supports seek operations within large files without having to download the entire file (e.g. can have a 10GB file and load only the 7th GB if you so choose, an essential feature when playing large video files over the network)
The Quick Way
Download my precompiled package
here.
The Easy Way
Follow the "Prerequisites" steps below (remember to enable the 2009 tool-chain), then...
Download the
shell script I created, place it in ~/code, and run it.
The Hard Way
Prerequisites
Make sure you have set up a cross-compile environment as described
here.
Follow the instructions to get the latest cross-compile tool-chain as described
here.
Install the latest copy of nodejs for the HOST machine. This is needed later during the install process, as nodejs uses itself to execute the script for installing itself to the target directory (clever, but annoying when cross-compiling).
$ sudo apt-get install python-software-properties
$ sudo apt-add-repository ppa:chris-lea/node.js
$ sudo apt-get update
$ sudo apt-get install nodejs
Fetch Resources
Save this patch file:
~/code/nodejs-configuration-patch.txt
$ wget http://zlib.net/zlib-1.2.7.tar.gz
$ wget http://www.openssl.org/source/openssl-1.0.0d.tar.gz
$ wget http://nodejs.org/dist/v0.8.2/node-v0.8.2.tar.gz
Then extract each file into your ~/code directory.
Build zlib
Thankfully, zlib is very easy to build statically:
$ cd zlib-1.2.7
$ ./configure --prefix=/mnt/DroboFS/Shares/DroboApps/nodejs --static
$ make clean
$ make
$ make install
Build openssl
OpenSSL needs a bit more to compile. Many thanks to Ricardo for
making it easy.
$ cd openssl-1.0.0d
$ ./Configure linux-generic32 \
-DL_ENDIAN \
--prefix=/mnt/DroboFS/Shares/DroboApps/nodejs \
--openssldir=/mnt/DroboFS/Shares/DroboApps/nodejs no-shared no-zlib-dynamic \
--with-zlib-include=/mnt/DroboFS/Shares/DroboApps/nodejs/include \
--with-zlib-lib=/mnt/DroboFS/Shares/DroboApps/nodejs/lib
$ sed -i -e "s/CFLAG= /CFLAG=${CFLAGS} /g" Makefile
$ make clean
$ make # First make always dies on a non-error, strange, but...
$ make # Second one succeeds
$ make install
Build nodejs
A few notes about why things are done the way they are below:
- The configuration patch is needed for the ARMv5te processor, because we want the generic "dest-cpu=arm" for bookkeeping, but need to skip the flags intended for the ARMv7
- Without-snapshot says to not include a previously compiled snapshot of v8, which is absolutely necessary here because we're statically compiling everything.
- We explicily state the CC, CXX, CFLAGS, CXXFLAGS, and DESTDIR on the make line because something strange happens in the call from an outer make command to an inner one. Local environment variables get lost, but if make is directly told to use those, it passes them along correctly.
- The system copy of nodejs/npm are compiled with a static prefix of "/usr", which means our files end up in/usr instead of just the destination directory, so I used rsync to make sure they were moved out properly.
$ cd node-v0.8.2
$ make distclean clean
$ patch < ../nodejs-configuration-patch.txt
$ ./configure --dest-cpu=arm \
--prefix=/mnt/DroboFS/Shares/DroboApps/nodejs \
--without-snapshot \
--shared-openssl \
--shared-openssl-includes=/mnt/DroboFS/Shares/DroboApps/nodejs/include \
--shared-openssl-libpath=/mnt/DroboFS/Shares/DroboApps/nodejs/lib \
--shared-zlib \
--shared-zlib-includes=/mnt/DroboFS/Shares/DroboApps/nodejs/include \
--shared-zlib-libpath=/mnt/DroboFS/Shares/DroboApps/nodejs/lib
$ make CC="$CC" \
CXX="$CXX" \
CFLAGS+="$CFLAGS -O3 -mfloat-abi=soft" \
CXXFLAGS+="$CFLAGS -O3 -mfloat-abi=soft" \
DESTDIR=/mnt/DroboFS/Shares/DroboApps/nodejs \
install
$ rsync \
--recursive \
--remove-source-files \
--verbose \
/mnt/DroboFS/Shares/DroboApps/nodejs/usr/ \
/mnt/DroboFS/Shares/DroboApps/nodejs/
$ find /mnt/DroboFS/Shares/DroboApps/nodejs/usr/ -depth -type d -exec rmdir "{}" \;
Congratulations! You're ready to package it up and run nodejs on your DroboFS!