Wolfmans Howlings

A programmers Blog about Programming solutions and a few other issues

Running Erlang OTP applications as Daemons on Ubuntu Servers

Posted by Jim Morris on Sun Sep 19 17:26:42 -0700 2010

Recently I needed to deploy an Erlang OTP application to a production server, and was surprised at the lack of official documentation on how to do that. My requirements are to have the application run on system startup, and if the application crashes to have it automatically be restarted, some optional requirements are to have rotated logs and to get email notifications if the application does crash.

Erlang itself has several layers of supervision to keep its processes running, however on occasion the VM itself may crash, if it runs out of memory for instance. I would want the entire appliction to be restarted in that case.

... Show more ...

Posted in Erlang  |  Tags erlang,OTP,daemon  |  2 comments

Using Postgresql with Grails

Posted by Jim Morris on Wed Nov 11 13:59:07 -0800 2009

I started playing with Grails, and I am planning to rewrite the blog engine I use for this blog in Grails. As noted earlier I wrote it in Merb originally. Although Merb is nice and lite it seems to be having difficulty keeping up with the gems it is dependent on. A case in point is Cucumber which it says is its recommended way of doing integration tests. The current version of Cucumber is very difficult to get working with Merb. See the Git source to see how I finally did it.

While I was learning Grails, I hooked up Postgresql 8.2 to Grails using the Datasource.groovy file. I turned on SQL logging, and to my horror saw how it was handling the id's. I have been using Postgresql for quite a while now, and used to run into problems with the creation and retrieval of the automatically generated IDs. It seems a lot of people run into these hard to describe problems, as it appears to happen rarely and is probably a race condition. With version >= 8.2 Postgresql introduced a way of inserting a new record and returning the automatically generated id in one atomic statement. This solves all the problems and is more efficient as it does not require two queries for each insert.

... Show more ...

Posted in Grails  |  Tags grails,hibernate,postgresql  |  11 comments

Converting a Sidewinder 3D pro joystick to USB

Posted by Jim Morris on Sat Oct 24 14:50:02 -0700 2009

In playing with my new Rovio I decided that my Old MS Sidewinder 3D Pro Joystick would be an excellent way to control it, as it has the twist which can rotate the Rovio, and the joystick up/left/down/right can move the Rovio in those directions while still facing forward.

The problem is that the joystick has a game port connector, and my Linux workstation does not have a game-port. After doing the obligatory Googling I found this Exactly what I needed, except this was for Windows not Linux. Thinking I would have to modify the code I contacted Grendel who graciously sent me the source code for the project, however it turns out the code he wrote was so good it works as is on Linux, I just needed to modprobe sidewinder and it worked.

... Show more ...

Posted in Linux,Embedded,Robotics  |  Tags joystick,usb,soldering  |  1 comments

Fun with a PC104 board, embedded Linux and wifi

Posted by Jim Morris on Wed Oct 21 01:32:16 -0700 2009

Around 10 years ago I was playing with some home robotics, built a simple robot, with some sensors and an on-board Linux-based PC. The purpose was to experiment with Robot AI, a continuation of my PhD thesis I started on some 30 years ago, but did not complete.

The robot had a camera, a digital compass, a sonar scanner and a short range IR range detector, plus some bump detectors. I could control it over a wifi connection, that was a Orinoco PCMCIA board plugged into the PC104, 586 based Linux PC that was on-board. All powered by several batteries.

... Show more ...

Posted in Linux,Embedded  |  Tags linux,pc104,wpa_supplicant,microdrive  |  no comments

A TCP socket bridge for Javascript

Posted by Jim Morris on Sat Sep 12 16:07:22 -0700 2009

In the process of rewriting my voice server in Erlang, I decided a new web-based Javascript UI would also be welcome. One problem of course is my voice server requires a TCP connection and a UDP socket for sending voice, not to mention the whole voice capture, playback thing.

In order for this to work the voice and playback would need to be written in a Java Applet, so it made sense to put the whole TCP/UDP communications stuff in there too.

... Show more ...

Posted in Java,Javascript  |  Tags java,javascript,applet  |  no comments

Using Cucumber to test Erlang Servers

Posted by Jim Morris on Sat May 02 00:09:36 -0700 2009

Background

I've been using cucumber to do all my integration testing. Usually testing over the wire to a live system, regardless of what the target system is written in (Ruby Rails, Merb, Java etc).

... Show more ...

Posted in Erlang,Cucumber  |  Tags erlang,cucumber,bdd  |  8 comments

Dealing with a TCP packet with a little endian header in Erlang gen_tcp

Posted by Jim Morris on Mon Apr 13 01:11:57 -0700 2009

In Erlang they have a very neat way of reading TCP packets that have a header that specifies how big the following packet is. So long as you send that header as a big-endian integer, you can use the built-in mechanism. Then gen_tcp, takes care of making sure the entire packet is read before passing it onto you.

Here is an example of a simple server getting packets from a client using some simple binary protocol... For instance sending this binary packet,

... Show more ...

Posted in Erlang  |  Tags erlang,gen_tcp  |  3 comments

Using Erlang with JInterface

Posted by Jim Morris on Sun Apr 12 16:56:50 -0700 2009

Background

I recently undertook a project to rewrite a voice conference server I wrote over 10 years ago. This server was written in C++ running on a Windows Server (originally NT and then win2k). The reason it was written for win2k was to use I/O Completion Ports which were not (and still are not) available on Linux.

Solaris has an equivalent AIO feature but not quite the same. I/O Completion Ports make very efficient use of multiple CPU's, and the conference server had to be very fast and handle a large number of concurrent connections.

... Show more ...

Posted in Erlang  |  Tags erlang,jinterface  |  5 comments

Using java enum for command dispatching

Posted by Jim Morris on Sun Apr 12 01:26:06 -0700 2009

I haven't blogged much about Java even though it is my primary programming language. Since I have been doing a lot of Java recently I thought I'd post something about some of the Java idioms I've used over the years.

One I have been using a lot recently is a command dispatcher where the command is text.

... Show more ...

Posted in Java  |  Tags java,enum,dispatcher  |  2 comments

Fixtures VS Factories, or how I do fixtures

Posted by Jim Morris on Fri Feb 06 15:04:54 -0800 2009

There is a raging debate in many forums about how to do fixture-like things. Basically how do you populate a database with test data so you can run your Specs/Tests/Features.

There are several libraries out there to do this like FactoryGirl, FixtureReplacement, Machinist, Fixjour etc etc. If you use Rails and ActiveRecord pick the one you like and be happy ;)

... Show more ...

Posted in Rails,Merb,Sequel  |  Tags merb,sequel,fixtures  |  1 comments