2011/03/25

Scripting the mod_proxy_balancer Balancer Manager from Bash

Here's a little script I wrote for https://www.digitalpigeon.com that allows me to interact with the Balancer Manager via a Bash script. It basically allows you to enable/disable a worker from the shell.

e.g. ./balancer.sh enable http://web-01:8080

#!/bin/bash
set -e

print_usage() 
{
 echo "Usage: $0 enable|disable http://worker-url"
}

WORKER_URL=$2
ACTION=$1

if [ "${WORKER_URL}" == "" ]; then
 print_usage
 exit 1
fi
if [ "${ACTION}" == "" ]; then
 print_usage
 exit 1
fi

BALANCER_MANAGER_URL=http://load-balancer-host/balancer-manager
BALANCER_NAME=load-balancer
BALANCER_NONSE=`curl -s ${BALANCER_MANAGER_URL}  | sed -n "/href=/s/.*href=\([^>]*\).*/\1/p" | tail -1 | sed -n "s/.*nonce=\(.*\)\"/\1/p"`

if [ "${BALANCER_NONSE}" == "" ]; then
 echo "Could not extract nonce from ${BALANCER_MANAGER_URL}"
        exit 1
fi

curl -s -o /dev/null "${BALANCER_MANAGER_URL}?b=${BALANCER_NAME}&w=${WORKER_URL}&dw=${ACTION}&nonce=${BALANCER_NONSE}"

2011/02/28

Connecting to Cassandra JMX via SSH

This post is based on http://gabrielcain.com/blog/2010/11/02/using-ssh-proxying-to-connect-jconsole-to-remote-cassandra-instances/.
  1. Make sure you can ssh into the Cassandra node without typing a password
  2. On the server running Cassandra edit cassandra-env.sh and include the hostname of the machine in the 'java.rmi.server.hostname' property (JVM_OPTS="$JVM_OPTS -Djava.rmi.server.hostname=foo.bar.com"
  3. On the client machine add the 'jc' function to your bash (or whatever) profile:

    function jc {
        # set this to the host you'll proxy through.
        proxy_host="dan@foo.bar.com"
        host=$1
    
        jmxport=8080 # as specified by JMX_PORT in cassandra-env.sh
        proxy_port=${2:-8123}
    
        if [ "x$host" = "x" ]; then
            echo "Usage: jc  [proxy port]"
            return 1
        fi 
    
        # start up a background ssh tunnel on the desired port
        ssh -N -f -D$proxy_port $proxy_host 
    
        # if the tunnel failed to come up, fail gracefully.
        if [ $? -ne 0 ]; then
            echo "Ssh tunnel failed"
            return 1
        fi
    
        ssh_pid=`ps awwwx | grep "[s]sh -N -f -D$proxy_port" | awk '{print $1}'`
        echo "ssh pid = $ssh_pid"
    
        # Fire up jconsole to your remote host
        jconsole -J-DsocksProxyHost=localhost -J-DsocksProxyPort=$proxy_port \
            service:jmx:rmi:///jndi/rmi://${host}:${jmxport}/jmxrmi
    
        # tear down the tunnel
        kill $ssh_pid
    }
  4. Source the 'jc' function added to your bash profile (e.g. 'source ~/.bash_login')
  5. Open jconsole using: 'jc foo.bar.com'

2010/04/08

Sun's Java JDK on Ubuntu 10.04 beta1 (Lucid Lynx)

Sun's Java 6 JDK is now available through the partners repository.  To get it installed use the following steps...
  1. sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
  2. sudo aptitude update
  3. sudo aptitude install sun-java6-jdk

2010/02/21

IntelliJ Idea Menu Item on Ubuntu Desktop

Creating a Menu Item for IntelliJ Idea (and I'm guessing any other Java GUI app) is pretty annoying on Ubuntu Desktop. As it turns out the annoyance is caused because your environment variables defined in .bashrc are not available when executing commands defined in the Menu Editor. To fix this you need to explicitly define the JDK_HOME variable before calling the idea.sh script.

The steps are;
  1. Navigate to System > Preferences -> Main Menu
  2. Locate "Programming" under the "Menus" panel
  3. Click the "New Item" button
  4. Enter the appropriate details;
    Type
    Application
    Name
    IntelliJ Idea
    Command
    bash -c "export JDK_HOME=/usr/lib/jvm/java-6-sun; ~/Development/Tools/Idea/current/bin/idea.sh"
Obviously you'll have to substitute the paths you are using for both Java and Idea...

I rarely use the Menu but by adding Idea to the menu GnomeDo automatically picks it up.