Tuesday, 29 March 2011

Book Review: Version Control with Subversion

I just finished reading the online version of the Version Control with Subversion book, which is available for free at the link provided. The book was an incredible help in teaching me the ins and outs of subversion. The only thing I can say that was perhaps not as great as it should have been is that it sometimes went into too much detail, exploring too many of the options and fringe use cases.

While I have managed to set up a repository, make it available over WebDAV and have a Redmine install use it, all without having read this book, this was mostly done by following a recipe. This means that I didn't delve too much into the workings of the software or all of the different configurations that you could have. This area is where this book shines. It tells you how you could have done things differently and the possible reasons for doing so. I personally found several configuration options which I have tweaked on my own Subversion/Apache setup to make it more secure and efficient.

Overall, a good read and while I can't say for sure that everything in this book will be relevant to you, I can say for sure that nearly everyone using Subversion will find something in this book for them.

Monday, 21 March 2011

Eclipse IDE indentation shortcut

If you're editing some code in Eclipse and you want to indent it, you just select the block of code and hit the TAB key. But what about if you want go go back the other way? In this case, you just use Shift+TAB.

Simple really, not sure why they don't have the keyboard shortcut listed next to the menu option to do the same thing.

Saturday, 5 March 2011

Changing JRE's in Ubuntu

If you're working with Java on Ubuntu, you have two main choices as to which runtime to use. The open source OpenJDK and the official Sun runtime. Luckily, due to the alternatives system in Ubuntu (probably inherited from Debian) you can install both of these and switch between them as you see fit.

To see your currently installed JRE's run the command:

$ update-java-alternatives -l

and you should see some output like:

java-6-openjdk 1061 /usr/lib/jvm/java-6-openjdk
java-6-sun 63 /usr/lib/jvm/java-6-sun


This assumes that you've installed both of the runtimes. If you've only got one or the other installed, you will only see one line in the above output.

Now that we know which runtimes are installed, it would also be nice to be able to see which one we are using at the moment. Run the command:

$ java -version

If you see the ouput:

java version "1.6.0_20"
OpenJDK Runtime Environment (IcedTea6 1.9.7) (6b20-1.9.7-0ubuntu1~10.04.1)
OpenJDK 64-Bit Server VM (build 19.0-b09, mixed mode)


Your are running the OpenJDK runtime. If you see:

java version "1.6.0_24"
Java(TM) SE Runtime Environment (build 1.6.0_24-b07)
Java HotSpot(TM) 64-Bit Server VM (build 19.1-b02, mixed mode)


You are running the Sun runtime. As an aside, the OpenJDK version is generally always a few versions behind the official Sun version.

So now that we know which runtimes we have installed and which one we are using at the moment, we can finally switch between them, using the update-java-alternatives command.

To switch to Sun's JRE:

sudo update-java-alternatives --set java-6-sun

To switch to OpenJDK:

sudo update-java-alternatives --set java-6-openjdk

To learn about the OpenJDK project and how it differs from the Sun Java runtime, you can have a look at:

http://openjdk.java.net/
http://en.wikipedia.org/wiki/OpenJDK

The 'update-java-alternatives' command has a lot more options allowing you to choose to switch just the JRE (and keep the JDK the same), or only switch out the browser plugin. To see all of the alternative options, have a look at the man page 'man update-java-alternatives'.

Wednesday, 16 February 2011

Installing from URL on Citirx XenServer

Citirx XenServer has a nice feature which lets you install a Linux directly from the repository. The one catch is that you have to get the URL right and if you don't you only get the error when you try and start up the VM. I've only tried out CentOS and Debian, the URL's for these distros are:

http://ftp.ca.debian.org/debian/ (Debian)

http://mirror.csclub.uwaterloo.ca/centos/5.5/os/x86_64/ (CentOS)

Note that since our host server is in Canada, I have used the Canadian mirrors. If you're using a different mirror, you'll have to replace the hostname with the hostname of your mirror.

Tuesday, 15 February 2011

How to change timezone on RHEL/CentOS

Here’s how to change the timezone on CentOS/RHEL:

cp /usr/share/zoneinfo/Pacific/Auckland /etc/localtime

Tuesday, 8 February 2011

Installing Redmine + SVN on Ubuntu 10.04

I've got a new workstation pc. It's not much (no hardware supported virtualization, onboard graphics) but it does the job. I've decided to take it and basically turn it into the ultimate development machine. That is to say, start right from the beginning and do things properly. The last sentence probably means a lot of different things to a lot of different programmers, so what does it mean to me? Well basically:

* Ability to access the machine remotely (Dynamic DNS + SSH/Web access)
* A Version Control System (Subversion, thank you very much)
* Project management/issue tracking software
* Development web server + database (Tomcat & MySQL)

So, today I will be writing how to get Subversion + Redmine up and running on Ubuntu 10.04. Partly to help someone out there that might be having the same problem and partly because I'll probably be having to install it again in the future and having a written record might save some time :-)

I've installed both Subversion and Redmine from the repositories and generally used the sample configuration which came with the packages, with a little bit of tweaking of course.

Installing Subversion is as easy as running:

sudo apt-get install subversion libapache2-svn

Next, I mostly followed the subversion install instructions found on the ubuntu wiki page, setting up a private repository. The wiki writeup is excellent, telling you how to get up and running quickly, whether you use subversion over HTTP/HTTPS/SVN/SVN+SSH.

Redmine was a little more tricky to install, although still a lot easier than I remember it being before it was in the repositories. Start by running:

sudo apt-get install redmine redmine-mysql

If you don't use MySQL, use one of the alternates (redmine-sqlite, redmine-pgsql). The sample configuration for Apache can be found at /usr/share/doc/redmine/examples/. I used the 'apache2-alias.conf' file by pasting it into /etc/apache2/sites-available/redmine and running:

sudo a2ensite redmine
sudo /etc/init.d/apache2 restart

After this I got an error saying that one of the apache directives was in the wrong place:

... waiting Syntax error on line 14 of /etc/apache2/sites-enabled/redmine:
SocketPath cannot occur within section


I then tried moving the directive to the /etc/apache2/mods-available/fcgid.conf, however this ended up giving me a different set of errors in the apache error log:

[Sun Feb 13 16:23:33 2011] [error] (13)Permission denied: mod_fcgid: couldn't bind unix domain socket /var/run/redmine/sockets/default/6126.28
[Sun Feb 13 16:23:33 2011] [warn] (13)Permission denied: mod_fcgid: spawn process /usr/share/redmine/public/dispatch.fcgi error

Finally, I commented this line out from both sections and was able to get redmine going without fcgi (Later I realised that I had installed passenger and it was running and that this was probably the reason that fcgi kept throwing the errors.

So, then you can navigate to http://localhost/redmine/ and configure the admin user (default username/pass is admin:admin) and you should have a working Redmine install.

Tuesday, 3 August 2010

MySQL Stored Procedure tip

The other day I was writing a stored procedure, when after making a change it just wouldn't save and kept giving me an error, saying something useful like "There is an error in your SQL syntax...".

After pulling my hair out for a day trying to work it out, I realised that when dealing with MySQL stored procedures you must put all of your declare statements at the start of the sproc.