VirtualBox and USB devices, vboxusers.

By default when installing VirtualBox on Ubuntu, you won’t be able to access USB devices in the VM.

To get around that problem is very simple, below are listed the steps needed to get access to USB devices in the VM.

First, make sure you have the latest version of the software:
Download VirtualBox

You also need to install the extension pack:
Get Extension Pack

and the Guest Additions:

Guest Additions Manual

After installing all the extra dependencies, it is time to enable USB access to the VM.

First

Right click on the VM and select settings:

You will get this message:


Failed to access the USB subsystem

VirtualBox is not currently allowed to access USB devices. You can change this by adding your user to the ‘vboxusers’ group. Please see the user manual for a more detailed explanation.

It tells that you need to add your user to the vboxusers group.

Second

There are two ways to add users to groups in Ubuntu.
Via the GUI

If you want something faster, it is also possible to add a user to a group via the command line:

After adding the user to the vboxusers group you need to restart Ubuntu.

Third

Now after adding the user to the vboxusers group, it is time to select which USB device you want to mount in the VM

Forth

Access USB devices in the VM

More Info:
http://www.howtogeek.com/howto/31726/mount-usb-devices-in-virtualbox-with-ubuntu/

Advertisements

Running node.js on port 80 with apache

This weekend I was faced with the task of putting a nodejs application into production mode.
Most of the development happened offline with each developer running local instances of node and using git to synchronize the code, so we didn’t have the problem of configuring node in a centralized server. Now that the development stage is over, we needed to set the project into production mode.

We already use Linode to host some of our projects, so we decided to host the nodejs project there as well.

All of our current projects are being served via apache.

The problem is that we can’t set apache and node to listen on the same port (80) and we didn’t have the option of deactivating apache to run just node.

We decided to implement a quick solution to get both apache and node working together: Proxy mode

So apache can still listen on port 80, and whenever somebody requests the nodejs application we forward the request to the port node is listening, in our case 11342.

Below are the steps needed to get apache and node running on the same server:

Assuming you already have apache2 installed and the nodejs application set up.

Load proxy modules

Load the proxy modules that will forward the request to node:
Open the file apache2.conf
Usually the file is located in the dir /etc/apache2/
If you not sure where the file is:

cd /
sudo find -name "apache2.conf"

After opening, append the following lines at the bottom of the file:

LoadModule proxy_module /usr/lib/apache2/modules/mod_proxy.so
LoadModule proxy_http_module /usr/lib/apache2/modules/mod_proxy_http.so

Without adding those modules, if you try to start apache you will get this message:

Syntax error on line 6 of /etc/apache2/sites-enabled/mysite.com:
Invalid command ‘ProxyRequests’, perhaps misspelled or defined by a module not included in the server configuration
Action ‘configtest’ failed.
The Apache error log may have more information.
…fail!

Configure the vhost

Now that you have the required modules running, it is time to configure the vhost

To add a vhost to apache you need to create a file in /etc/apache2/sites-available

<VirtualHost *:80>
     ServerAdmin your@email.com
     ServerName mysite.com
     ServerAlias www.mysite.com

     ProxyRequests off

     <Proxy *>
          Order deny,allow
          Allow from all
     </Proxy>

     <Location />
           ProxyPass http://localhost:11342/
           ProxyPassReverse http://localhost:11342/
     </Location>
     DocumentRoot /srv/www/mysite/public_html/
     ErrorLog /srv/www/mysite/logs/error.log
     CustomLog /srv/www/mysite/logs/access.log combined
</VirtualHost>

First you specify that all requests on port 80, to the domain mysite.com should be forward to localhost at port 11342

Enable the vhost

Now you need to enable the new vhost:

a2ensite siteName

A link will be created in the sites-enabled dir

to disable the site:

a2dissite siteName

Restart apache

Last thing you need to do is restart apache:

service apache2 reload


You should get the message:
* Reloading web server config apache2 [ OK ]

References:

http://www.ehow.com/how_5458585_configure-modproxy.html
http://karrigell.sourceforge.net/en/proxy.html
http://davybrion.com/blog/2012/01/hosting-a-node-js-site-through-apache/


Installing Lua on Ubuntu

I’ve been hearing about Lua for a few years now, but I never took the time to sit down and read more about the language, the only thing I knew was that WoW used it, and that it was created by a group of teachers in Brazil

Speaking with my brother in law, that now works in the same university as the teachers that created Lua, recommended to me a podcast where the main creator of Lua talks about the language in general.

The podcast is VERY good, Roberto Ierusalimschy explains why he created Lua, all the architectural design behind it, his philosophy regarding the project, some good use cases for the language and the future for Lua(the podcast is in Portuguese)

After listening to the podcast, I was really surprised to hear that Lua’s only data structure is Tables, much like the object notation in javscript, and that a lot of features in the new JS engines today are somewhat derived from Lua.
I decided to give a try and play a bit with the language.

Bellow is a simple tutorial to get Lua up and running on Ubuntu

Installing Lua

There are a few different ways you can install Lua on your machine, I decided to get the source code and compile it.
Lua it self is not that big, ~20,000 lines of code.

You can download the code here:

I downloaded the latest stable version, 5.2.0

After downloading/extracting, you’ll ge this files:

/doc
Makefile
README
src

All it takes to compile Lua is a simple:

make linux test

linux species which platform you want to build.
The complete list of supported platforms:

  • aix
  • ansi
  • bsd
  • freebsd
  • generic
  • linux
  • macosx
  • mingw
  • posix
  • solaris

test just prints the version of Lua to stdout

After compiling, the Lua executable will be created in your /src dir

To open the Lua shell: ./lua

*If you want to add the lua executable to your path there are several different ways to do it. A simple way is to create a symbolic link to lua in your $HOME/bin dir. It will automatically add lua to your PATH next time you log in

**You might get this error if you don’t have the readline lib installed:

To install the readline lib:

sudo apt-get install libreadline5-dev

After installing the lib, you should get this output:

If you don’t want to install the readline lib, you can make a few modifications to their build system:
Changing src/Makefile

linux:
  $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lreadline -lncurses"

to

linux:
  $(MAKE) $(ALL) SYSCFLAGS="-DLUA_USE_LINUX" SYSLIBS="-Wl,-E -ldl -lncurses"

also removing the lib from src/luaconf.h

#if defined(Lua_USE_LINUX)
#define Lua_USE_POSIX
#define Lua_USE_DLOPEN    /* needs an extra library: -ldl */
#define Lua_USE_READLINE  /* needs some extra libraries */
#define Lua_USE_STRTODHEX /* assume 'strtod' handles hexa formats */
#define Lua_USE_AFORMAT   /* assume 'printf' handles 'aA' specifiers */
#define Lua_USE_LONGLONG  /* assume support for long long */
#endif

or just do a:

make ansi

More info here.

Running Some Programs:

To get started, lets run the famous Hello World program.
In Lua, all it takes is a simple:

print("Hello World!")

To run the program:

lua hello-world.lua

Another example using tables:

obj = {
  a = 1,
  b = {
    str = "b1",
    dec = 2.1
  },
  c = 3,
  f = function (x)
        return x*2
      end
}

for index,value in pairs(obj) do print(index,value) end

print(obj.f(2))
print(obj.b.str)
print(obj.b.dec)

Much like in javascript, you can create tables using the object notation: { }

You can think of tables as an associative array, a key value pair structure, just like a hash.

That’s very powerful and gives a lot of flexibility when writing programs.
You can create very complex data structures with a few lines of code.

Use Cases

The Lua project has more than 15 year of existence, being tested and used by several different companies

Adobe has more than 100 engineers working specifically with Lua.
The Adobe Light Room was mainly written in Lua.

Huawei, the second largest network and telecommunications equipment company in the world has more than 1 million lines of Lua written in their products

Some other well known projects that use Lua are:

The list of games is huge, close to a total of 160 different titles:

You can check the complete list here:

Lua and the Web

What got me really excited about Lua, was the fact that it can also be used as a web server.
Actually, some benchmarks show that Lua can be up to 3 times faster than node.js and the VM is also a lot smaller than node.

There are a few projects that started porting Lua to be much like a nodejs server. Using the Lua VM instead of the V8 engine, but keeping all the awesome architecture existing in node

One of the projects is Luvit.
The project is still on its early stages of dev, but looks very promising 🙂

Other cool projects involving Lua:
LuaLibEvent
lua-ev
LuaNode
JSON4Lua
lunit