Tuesday, 5 March 2013

Java on a $5 per month server from Digital Ocean

I just recently came across Digital Ocean - "Simple Cloud Hosting". I was impressed by the pricing, much cheaper than my current VPS solution so I've set up an Ubuntu 12.10 server with 512MB, 20GB SSD, for $5 USD per month. Since I've moved almost everything to Google (from self hosted WordPress to Blogger and Google Docs) the only thing I really need a VPS for is to run my Java applications (there still is the option to use AppEngine with Play 1.2.x if it makes sense to use DataStore).

But for $5 a month, this means I can use Grails or Play with a relational database - if it performs well enough.


Setting up a server with Digital Ocean really is simple. Once you've signed up (check their Twitter posts for a coupon) and added a credit card, your server can be running in minutes. I chose Ubuntu 12.10, and then they have nice and clear instructions on what to do next to secure it:
Now, a couple of other things I did to get the server up to date and install Jetty8:
  • sudo apt-get update
  • sudo apt-get upgrade
  • sudo apt-get install openjdk-7-jre-headless
  • sudo apt-get install jetty8
To get jetty to start, you've got to edit /etc/default/jetty8 and change:
  • NO_START=0
  • JETTY_HOST=0.0.0.0
  • JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386/jre/
You can find the location of Java by using 
  • ls -al /etc/alternatives/java
which should show you the linked path such as
  • lrwxrwxrwx 1 root root 45 Mar  5 01:58 /etc/alternatives/java -> /usr/lib/jvm/java-7-openjdk-i386/jre/bin/java
Now start Jetty with
  • sudo service jetty8 start
and it should be running on port 8080. I still have to enable it on port 80, but first I'll see how well my applications run on it and how it goes with memory.

'top' is currently reporting 188MB free - not much, but to upgrade to 1G is only going to cost $10p/m - I'll just have to see how well the applications run...

top - 03:27:04 up  1:29,  3 users,  load average: 0.00, 0.01, 0.04
Tasks:  67 total,   1 running,  66 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.3 sy,  0.0 ni, 99.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem:    508396 total,   319948 used,   188448 free,    16688 buffers
KiB Swap:        0 total,        0 used,        0 free,   250652 cached

(In the past I've usually used Apache in front of Tomcat, but since I don't need all that flexibility any more, I'm trying to simplify my setup and make the best use of my memory)