Setup – Apache and Hudson


Overview

This is a quick and easy tutorial to get up and running quickly with a complete environment as set out below.  About my personal setup… 

What will be covered is how to easily get up and running in the quickest, easiest manner.  What I’ll be going through are as follows:

  1. Pre-requisites
  2. Downloading and installing Hudson
  3. Downloading & installing Apache and Configuring Apache to host Hudson

Note that I’m installing and running these environments on a VirtualBox VM running Ubuntu version 3.2.10.  If you would like to know how to set up the same environment you can refer to my other article called “Ruby-Environment”.

Pre-requisites

Before you go any further I would have to advise you to install the pre-requisites that I have on my “Setup – Requirements” article.  This will sort out most of the requirements you need to install Apache and Hudson.

Downloading and installing Hudson

When installing Hudson I like to set it up so it automatically pulls the latest versions as and when the stable releases gets released.  This is a very simple set up as follows.  You’ll want to get the key by opening up a Terminal Window and running the following command:

wget -O /tmp/key http://hudson-ci.org/debian/hudson-ci.org.key

This will download a “key” file to your “/tmp/” folder.  Once that has been done you’ll want to add the key to your system by running the following command:

sudo apt-key add /tmp/key

Now that the key has been added to your system you can go ahead and download Hudson by running the following command:

wget -O /tmp/hudson.deb http://hudson-ci.org/latest/debian/hudson.deb

This will download Hudson to the “/etc” folder as the file “hudson.deb”, which will then allow us to go and depackage and install it by running the following command:

sudo dpkg –install /tmp/hudson.deb

On completion of this simply run the following command again.  Once this is completed, you have Hudson up and running and you should be able to browse to your newly created Hudson site at:

http://localhost:8080/

That’s it for getting Hudson up and running.  If you were wondering where Hudson is installed, you should find it under “/etc/default/Hudson/” and the Hudson logs can be found under “/var/log/Hudson/”.  To start Hudson you can run:

sudo /etc/init.d/hudson start

And to stop it you can run:

sudo /etc/init.d/hudson stop

One last thing on this; in future you can simply run the following command if you would like to update Hudson:

apt-get update; apt-get install Hudson

In the next section it gets a bit trickier when we want to run Hudson under Apache 2 over port 80 so we can get the nicer URL of:

http://localhost/hudson

Downloading and installing Apache

To get the nice URL you saw in the previous section you’ll first have to edit the file “/etc/default/hudson” file by adding “–prefix=/hudson” to the “HUDSON_ARGS” section of the file.  Once that’s been done you should restart Hudson by running the following command:

sudo /etc/init.d/hudson force-reload

If you get the exception as follows:

“* Restarting Hudson Continuous Integration Server hudson

The selected http port (8080) seems to be in use by another program

Please select another port to use for Hudson”

Then you can run the above commands to stop and start Hudson.  This should resolve the issue and it seems to be a known bug inside Hudson.  Now we can move onto the Apache installation and configuration section.  First you have to download and install by running this command:

sudo apt-get install apache2

That’s fairly straightforward to do…  Once you have Apache installed you should also install the following package:

sudo apt-get install libapache2-mod-proxy-html

This will install the proxy libraries necessary to enable us to route all calls coming into our nice URL to the Hudson server still running on port 8080.  Once you have this package installed you should run the following two commands:

sudo a2enmod proxy

And you’ll also need to enable the http proxy by running this command:

sudo a2enmod proxy_http

Now that you have Apache installed and running and you’ve enabled it for proxy capabilities you should restart it by running the command as follows:

Once these are enabled I would suggest that you also disable the root domain by running the following command:

sudo a2dissite 000-default

The next step would be to change the Apache configuration to point to your new Hudson Build Server.  To do this you can run:

sudo nano /etc/apache2/apache2.conf

When the file opens you should add the following to the bottom of the file:

ServerName localhost:8080

Now you’ll need to create a new Virtual Host for Apache to serve.  You do this by making a “hudson” file by running the following command:

sudo touch /etc/apache2/sites-available/hudson

You should now edit the file by running:

sudo nano /etc/apache2/sites-available/hudson

When the file is open you should add the following to it:

<VirtualHost *:80>

  ProxyPass         /  http://localhost:8080/

  ProxyPassReverse  /  http://localhost:8080/

  ProxyRequests     Off

   # Local reverse proxy authorization override

  # Most unix distribution deny proxy by default

  # (ie /etc/apache2/mods-enabled/proxy.conf in Ubuntu)

  <Proxy http://localhost:8080/*&gt;

    Order deny,allow

    Allow from all

  </Proxy>

</VirtualHost>

The final step in this configuration is to enable Hudson and to restart Apache.  You can enable Hudson by running the following command:

sudo a2ensite hudson

Now that you have Apache installed and running and you’ve enabled it for proxy capabilities you should restart it by running the command as follows:

sudo /etc/init.d/apache2 restart

You can also restart Apache by running the stop and start commands separately by running the following two lines on Terminal:

Stopping Apache
sudo /etc/init.d/apache2 stop

Starting Apache
sudo /etc/init.d/apache2 start

That’s it… 🙂  Now you can test that your Apache setup worked by simply opening up a browser and going to http://localhost/ .  If you see a big “It works”, then I guess it’s working.  If not, well start over 🙂  Just kidding, but good luck 🙂

If you would like to see if the pretty URL we wanted works then you can just go to:  

http://127.0.0.1/hudson/

If it works, that’s great J  Pat yourself on the back, go outside, have a smoke and if you’re not at work have a beer 🙂

Conclusion

Now that you have the Apache and Hudson configuration up and running you’ll be able to do quite a few things, but in my case I’m trying to reach for the ultimate goal of having a CI environment, running at regular intervals pulling the new source from my Git repository, building it, running tests, deploying it to my Dev Integration servers after versioning my source and allowing our QA and Operations guys to pull whichever version they want when they want it while having full visibility to the stakeholders on the projects my team and I are working on… 

I hope you enjoy the Hudson environment and the capabilities it gives you as much as I’m going to enjoy it.  I’ll keep you posted on how I do the other things in future articles…!!!! 🙂

Leave a comment