Without an existing cassandra service script, I decided to go ahead and create one, to make things a little easier to manage, and to make the whole experience a little more user friendly :) The script includes a few nodetool basics, such as repair, cleanup, info, netstats etc. And will log the start and end times in its own log for repair and cleanup, allowing you to see how long the process takes without having the trawl through all the cassandra logs to find a start and end time (very useful for us when it takes over 5 hours to complete a repair).

Here is the script, simply copy the content into /etc/init.d/cassandra and make it executable :)

#!/bin/bash
#
# Author: Brooke Bryan
#
#
# Description:	Cassandra Server.
# Processname: cassandra
# Config: /usr/local/share/cassandra/conf/cassandra.yaml

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

prog="Cassandra"
pidfile="/var/run/cassandra.pid"
progbin="/usr/local/share/cassandra/bin"
lock="/var/lock/subsys/cassandra"
logfile="/var/log/cassandra/service.log"

WriteLog()
{
    echo "`date`: $@" >> $logfile
}

LogInfo()
{
    echo "$@"
    WriteLog "INFO: $@"
}

LogWarning()
{
    echo "$@"
    WriteLog "WARNING: $@"
}

start()
{
    if [ -f $pidfile ] && checkpid `cat $pidfile`; then
        action "$prog is already running." /bin/false
        exit 0
    fi

    WriteLog "Starting $prog"

    daemon "$progbin/cassandra" -p $pidfile >> $logfile 2>&1
    usleep 500000
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
        touch "$lock"
        action "Starting $prog" /bin/true
    else
        action "Starting $prog" /bin/false
    fi

    WriteLog "Started $prog"

    return $RETVAL
}

stop()
{
    $progbin/nodetool -h localhost disablethrift
    $progbin/nodetool -h localhost disablegossip
    $progbin/nodetool -h localhost drain
    WriteLog "Stopping $prog"
    CASSIEPID=`cat "$pidfile"  2>/dev/null `
    if [ -n "$CASSIEPID" ]; then
        /bin/kill "$CASSIEPID" >/dev/null 2>&1
        ret=$?
        if [ $ret -eq 0 ]; then
            STOPTIMEOUT=60
            while [ $STOPTIMEOUT -gt 0 ]; do
                /bin/kill -0 "$CASSIEPID" >/dev/null 2>&1 || break
                sleep 1
                let STOPTIMEOUT=${STOPTIMEOUT}-1
            done
            if [ $STOPTIMEOUT -eq 0 ]; then
                echo "Timeout error occurred trying to stop $prog Daemon"
                ret=1
                action $"Stopping $prog: " /bin/false
                LogInfo "Timeout error occurred trying to stop $prog Daemon pid($CASSIEPID)"
            else
                rm -f "$lock"
                action $"Stopping $prog: " /bin/true
                WriteLog "INFO: $prog Daemon Stopped pid($CASSIEPID)"
            fi
        else
            action $"Stopping $prog: " /bin/false
            WriteLog "WARNING: $prog Daemon Stop Failed pid($CASSIEPID)"
        fi
    else
        ret=1
        action $"Stopping $prog: " /bin/false
    fi
    return $ret
}

restart()
{
    LogInfo "Restart Initiated"
    stop
    start
}

ring()
{
    $progbin/nodetool -h localhost ring
}

info()
{
    $progbin/nodetool -h localhost info
}

netstats()
{
    $progbin/nodetool -h localhost netstats
}

repair()
{
    LogInfo "Starting Repair"
    $progbin/nodetool -h localhost repair
    LogInfo "Completed Repair"
}

cleanup()
{
    LogInfo "Starting Cleanup"
    $progbin/nodetool -h localhost cleanup
    LogInfo "Completed Cleanup"
}

version()
{
    $progbin/nodetool -h localhost version
}

# See how we were called.
case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status cassandra
    ;;
  restart)
    restart
    ;;
  ring)
    ring
    ;;
  info)
    info
    ;;
  netstats)
    netstats
    ;;
  repair)
    repair
    ;;
  cleanup)
    cleanup
    ;;
  version)
    version
    ;;
  *)
    echo $"Usage: $0 {start|stop|status|restart|ring|info|netstats|repair|cleanup|version}"
    exit 1
esac

exit $?

Just a quick post on how-to install cassandra on Centos 5, and getting the required bits on to stop all the errors you will see, such as JNA and MX4J missing.

First you need to get all the required modules from yum, to prepare the server.

yum -y install gcc-c++ make cmake python-devel bzip2-devel zlib-devel
yum -y install log4cpp-devel git git-core cronolog google-perftools-devel
yum -y install readline-devel ncurses-devel libtool autoconf expat
yum -y install libevent-devel flex byacc expat-devel

# Perl Modules for Thrift Install
yum -y install perl-Bit-Vector perl-Class-Accessor

# Java Install
yum -y remove jpackage-utils
wget http://dev.centos.org/centos/5/testing/x86_64/RPMS/jpackage-utils-1.7.5-1jpp.1.el5.centos.noarch.rpm
rpm -ivh jpackage-utils-1.7.5-1jpp.1.el5.centos.noarch.rpm
yum -y install xml-commons-apis xml-commons-apis-javadoc ant
yum -y install java
yum -y install log4j jakarta-commons-logging jakarta-commons-lang
yum -y install java-1.4.2-gcj-compat java-1.4.2-gcj-compat-devel

Next you will want to download the latest version of cassandra available at http://cassandra.apache.org/download/

I have chosen to install cassandra in the following location: /usr/local/share/cassandra

wget http://mirror.ox.ac.uk/sites/rsync.apache.org//cassandra/0.8.4/apache-cassandra-0.8.4-bin.tar.gz
tar -xvf apache-cassandra-0.8.4-bin.tar.gz
mkdir /usr/local/share/cassandra/
cp ~/apache-cassandra-0.8.4/* /usr/local/share/cassandra -R -f;
cd /usr/local/share/cassandra

Installing JNA is done as follows:

wget “https://github.com/twall/jna/raw/3.3.0/jnalib/dist/jna.jar” –no-check-certificate -O /usr/local/share/cassandra/lib/jna.jar
chmod 755 /usr/local/share/cassandra/lib/jna.jar

MX4J is installed with:

wget “http://downloads.sourceforge.net/project/mx4j/MX4J%20Binary/3.0.2/mx4j-3.0.2.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmx4j%2Ffiles%2FMX4J%2520Binary%2F3.0.2%2F&ts=1314263784&use_mirror=freefr”
tar zxvf mx4j-3.0.2.tar.gz mx4j-3.0.2/lib/mx4j-tools.jar
cp mx4j-3.0.2/lib/mx4j-tools.jar /usr/local/share/cassandra/lib/
chmod 755 /usr/local/share/cassandra/lib/mx4j-tools.jar

Switching to Sun Java
You will need to download the latest JDK from SUN, and can switch from OpenJDK with the following

rpm /root/jdk-7-linux-x64.rpm -ivh
/usr/sbin/alternatives –install /usr/bin/java java /usr/java/jdk1.7.0/bin/java 2 && /usr/sbin/alternatives –config java

Just enter the number of the new JDK in the selection above, and hit enter (on a fresh install, its usually #3)

Finishing up.
After you have everything above done, you should just be able to edit the config file /usr/local/share/cassandra/conf/cassandra.yaml, and then run cassandra /usr/local/share/cassandra/bin/cassandra

If you are running a cluster setup with cassandra, you can use a token calculator such as http://blog.milford.io/cassandra-token-calculator/ which will evenly spread the data across your nodes.

Also be sure to set your commit log and data directory on different disks.

The best option I have found is having the commitlog and OS on an SSD drive, and the data stored on a Raid 0 disk array with SAS drives. You want to make sure you have at least double the space available on disk as what you will be consuming with your nodes.

Today, I had the problem of converting a timestamp to a readable time format inside excel.  Not quite as easy as I would have hoped for, but the solution is fairly painless.

In the excel column you wish to display the date, you need to place the following formula.

=(((COLUMN_ID_HERE/60)/60)/24)+DATE(1970,1,1)

You would then need to replace COLUMN_ID_HERE with the cell that holds the timestamp. e.g. A1

The above formula can be simplified, but I think the above explains a little more what is actually being done to the data :)

You would then need to format the cell to be dd/mm/yyyy hh:mm and you are done :)

Over the past few days I have been playing about with my Sky Boxes at home, and found a few hidden secrets around. This post is just to combine the bits I have found.

Forcing An Upgrade

After a few months of having a HD box still running on the old EPG (electronic program guide) , I decided to find a way to force the system to update to the latest version.

You can do this by:

Power off the box at mains
Hold down back up buttom on front of box
Power back on at mains
When download message appears on screen, let go of back up button.

This will usually take around 10 minutes, but once the box comes back, you should have the latest software for your box :)

Sky Installers Menu
The Sky installers menu allows you to change extra settings on your Sky box, but be careful, changing settings in here can cause your box to stop working.

On the original sky epg, you can access this menu by pressing the following keys on your sky remote in order.

SERVICES
4
0
1
SELECT

More information can be found about the options here: http://www.digitalsat.co.uk/skyinstallersmenu.html

To access the menu on a sky HD box, you need to press the following keys in order:

SERVICES
0
0
1
SELECT

So, I just downloaded the new Opera, and ran a JavaScript speed check, and was amazed how their new engines compare to the other browsers around.  It also supports Windows 7 taskbar highlights properly :)

The test I ran was on http://www2.webkit.org/perf/sunspider-0.9/sunspider-driver.html and here are the results

Opera 10.50
============================================
RESULTS (means and 95% confidence intervals)
——————————————–
Total: 388.6ms +/- 2.3%
——————————————–

Chrome 4.0.249
============================================
RESULTS (means and 95% confidence intervals)
——————————————–
Total: 556.2ms +/- 3.1%
——————————————–

Firefox 3.5.8
============================================
RESULTS (means and 95% confidence intervals)
——————————————–
Total: 1155.4ms +/- 1.6%
——————————————–

Internet Explorer 8
============================================
RESULTS (means and 95% confidence intervals)
——————————————–
Total: 5145.4ms +/- 0.6%
——————————————–

Update: (27th Jan 2011)  A fix for Chrome has now been uploaded.

Ever since the web moved into the 2.0 generation, websites are increasingly using ajax to build up content, and navigate around without reloading the entire page. There is one major problem with this, and that is the browser. Until now, browsers to not trigger events for when the user is flipping between pages using the navigation buttons. This has been a problem with flash sites for a much longer period of time, with the user clicking back in the browser expecting to see the previous page shown in flash, but instead, they are taken to the last site they were on.

When improving the functionality of our Automated Chat Software, Intellichat, we had many requests from customers asking for the chat window to not launch when the user clicked back in their browser. After a lot of research into the problem, and how to detect it, I found the solution to be based around iFrames (as much as I hate them). When the user clicks back on their browser, they will initially navigate back through the iframes on the page before main page can go back.

This solution works great in Firefox and IE, however Safari needs an alternative solution. This is based around location hash tags (I find this solution quite messy, and easy to spot from the users point of view). When the page first loads, you can set the window.location.hash to anything you want, and then simply check the window.location.hash variable every few milliseconds to see if it has changed. Once it changes back to an empty value, you can see the user clicked back.

The Solution
I have made a very reusable javascript class, that can be simply dropped into your web page, and when the user clicks back, it will call a function. The default function on this call is a javascript alert “Back Button Clicked”.

To replace this functionality, you simply need to override the OnBack function. This can be done by using the code below.

<script type="text/javascript">
bajb_backdetect.OnBack = function()
{
alert('You clicked it!');
}
</script>

This will now replace the “Back Button Clicked” alert with a “You clicked it!’” alert.

You can see the code in action at http://www.brookebryan.com/code/backbutton/
or you can download the source from: http://www.brookebryan.com/code/backbutton/BackDetect.zip

About 20 minutes ago I got my invite to google wave. I now have my account live (brooke@wavesandbox.com) as well as my secondary account (brooke-test@wavesandbox.com), so I can start testing out the wave. I haven’t had any time to get into it and play, but here is a screenshot of an empty preview account :)

Google Wave Home Preview

Update:
After about 20 minutes, everyone started using wave and this is what it looks like

Wave After 20 Minutes

Update 2:
When I tried to reply to a wave that was created after I first loaded the page.

Wave Requires Refresh

If you know me, you will know I hate Mac’s.  However, the day has finally arrived where I decided to take a risk and go to buy one for myself.  Not being a strong follower of the Apple movement, I purchased my MacBook Pro on sunday 7th June.  I got home, installed some apps (dragging an icon around the screen seemed to be how you install an app), and started to get used to the interface.  All was great until the afternoon on Monday.  I had James, the designer @ Just Develop It send me a text message telling me Apple dropped the price of the MacBook Range and also upgraded all of the hardware… Gutted.

I called the Apple Store straight away, and they said it would be fine to just bring it back and get a new one when it came in stock.  Yesterday it arrived at the store so I went down and exchanged my old MacBook Pro for a nice shiny new one.  They even gave me money back.  Money Back for an upgrade?  Are they mad.  I dont know how I have gone from hating apple, to loving them within the space of a week, and also now being the owner of my second apple.

MacBook Pro

I have to admit, Apple products are Very well designed, even the packaging is amazing.  I hope that my previous view on Mac Users was wrong, because I dont want to trade productivity for a good looking laptop. Setup was fairly painless with nearly everything being done for me, and I just had to go into the settings to tweak the system to act more like windows.  Working out all the short cut keys didnt take long (apart from Home & End, which I later found to just be cmd + the arrow keys) .  I have enabled the ‘right’ mouse button (bottom right of the trackpad) and am loving Expose and Spaces.  The only problem I have faced so far is the mouse guestures in Opera, but then what do you expect from a trackpad :)

Without having the full expierence of a Mac yet, im going to hold of saying any more unless it turns out to be a nightmare :)

It has now reached the stage where I am logging into 20 – 40 different servers a day, which itself is quite time consuming when you know the server logins stored in your head.  However, all our servers have different access passwords and finding each server password takes a little too long (there is no way I could remember all our server logins).

There is a great feature on UNIX  machines which will allow you to simply ssh into a server without the password as long as you have configured each machine.

The setup of this is pretty quick, there are only 3 main things you need to remember.

1. Generate the Key on the client box
2. Copy the Key into your clipboard from the client box
3. Enter the Key into  the server box from your clipboard

Stage 1: Generating the Key

ssh-keygen -t dsa

By running the above command, you will generate your client key. You will be faced with a few questions, you should just be able to press enter with no answer on each question.

Generating public/private dsa key pair.
Enter file in which to save the key (/root/.ssh/id_dsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Stage 2: Access the Key

You will need to access the key that was just generated to place on your server so you can quickly access it.   First things first, you need to get the key onto the screen or into your email.  I would recommend using the screen output to avoid any formatting errors by your mail client.

Outputting onto the screen:

cat ~/.ssh/id_dsa.pub

Sending the output to your email:

cat ~/.ssh/id_dsa.pub | mail email@domain.com

Stage 3: Storing the Key on the Server
Now you have the key, you just need to add it onto the server you are going to be SSH’ing into.

Open up the file ‘~/.ssh/authorized_keys’ using your preferred editor. I usually use nano, so:

nano ~/.ssh/authorized_keys

Then copy the key into the end of the file. You need to ensure that the key stays on one line and you have one key per line.

Once you have saved the authorized_keys file, you should be able to hop back onto the client box and just type

ssh root@hostname

and you will be logged straight into shell on the ‘hostname’ box.

And thats all you need to do :)

This has saved me soo much time on a day to day basis and probably given me an extra 30 mins > 1 hour a day to get some real work done.

So, its only a few hours away from the timestamp 1234567890 and we just went past 1234543210. As always, sad enough to take a photo (well, Jordan (www.oxcreative.com) took the photo) on a monitor in our office which is displaying www.coolepochcountdown.com. Its only 6 or so hours till all hell breaks out and the time starts going backwards (or we just see a nice timestamp come and go).

123453210