Saturday, 25 August 2007

Jetty - lost in the web

Grails uses an embedded Jetty instance to serve the application during development. I'm trying to figure out how to configure it with Apache in front using mod_proxy - this means I need to do some Jetty configuration so that when running Jetty it knows it has a proxy in front of it.

It seems though that jetty.mortbay.org is not available on the web (for the last 24 hours I've been getting 'Can't find the server'). Google, however is turning up a lot of documentation that points there. So, its taken a long time to find information not on jetty.mortbay.org.

http://docs.codehaus.org/display/JETTY/Jetty+Wiki seems to be the best reference - it has working links to the binary distributions and source repositories.

Apache 2 mod_proxy - 403 error

I've been trying to put Apache2 in front of my Grails Jetty instance so that I can have common resources served by httpd and not included in my Grails web application. I enabled the proxy module, but always got 403 forbidden errors.

Searching around the web turned up this post, which lead me to check which modules were loaded.

Where I had simply done:
a2enmod proxy

I really need to also do:
a2enmod proxy_http
a2enmod proxy_connect

Of course, after enabling these modules, remember to force a reload:
/etc/init.d/apache2 force-reload

Wednesday, 22 August 2007

Nautilus - stop opening new windows

Nautilus on Fedora has an annoying habit of opening new windows every time you double click on a directory. This is enough to drive any one mad, but there is a solution.

Under the edit menu select preferences. On the behaviour tab click the 'Always open in browser windows'. Not particularly intuitive.

Thanks to Lars E. Pettersson for this tip! Now, Nautilus behaves sensibly and we have access to the directory tree.

Dovecot - Error: No protocols given in configuration file

I have been trying to get Dovecot running on my laptop for development purposes, but something went wrong somewhere. The service never started and running the /etc/init.d/dovecot start script never complained or produced any output.

Just trying to find out what the problem is can be difficult sometimes, never mind finding the solution to the problem. Luckily excellent documentation from the makers came to the rescue.

A wiki entry on logging showed how to find where the logs are:
root@laptop:~# grep "starting up" /var/log/*
/var/log/acpid:[Sun Aug 19 14:05:05 2007] starting up

But no mention of Dovecot in those logs.

The clue came from directly running dovecot:
root@laptop:~# dovecot
Error: No protocols given in configuration file

And sure enough, looking at /etc/dovecot/dovecot.conf showed:
...
# Protocols we want to be serving: imap imaps pop3 pop3s
# If you only want to use dovecot-auth, you can set this to "none".
#protocols = imap imaps
protocols =
...

Setting the protocols property did the trick:
protocols = pop3

Now, I can see it starting in the logs:
root@laptop:~# grep "starting up" /var/log/*
/var/log/acpid:[Sun Aug 19 14:05:05 2007] starting up
/var/log/mail.info:Aug 21 11:52:26 laptop dovecot: Dovecot v1.0.rc17 starting up

Tuesday, 21 August 2007

ProFTPd - Fatal: Socket operation on non-socket

I was trying to set up ProFTPd on Ubuntu recently and for some reason it wouldn't start. Somehow the configuration had been messed up (or something had been). I uninstalled and reinstalled it, but still it wouldn't start.

While trying to fix this problem, I came across this brilliant FAQ:  Chapter 4. Common Running problems. This described all the problems I was having:
3. Unable to bind to port/Address already in use
5. "Fatal: Socket operation on non-socket"

It's great to see such a useful FAQ.

Wordpress themes

Looking for Wordpress themes? Try WPThemesFree.com. This site catalogues tons of themes, and has them categorised appropriately (number of columns, colour scheme, topic). You can view the themes against the test database, and there are statistics available for downloads, views, and tests.

VMWare Server - Can ping but nothing else between host and guest

I've been using VMWare Server for testing some software and I've found it very easy to use and extremely valuable. This is a free product that lets you create virtual servers using multiple operating systems. Its great, because you can install an OS and then back it up in that state. Then you can make modifications (try out various configurations or software products) while being able to easily revert to a back up at any time.

I'd created a VM on one PC and after a while I transferred it to another host. I thought all was well, until I tried to SSH to it. No joy. I thought something was up with the networking, since I was also using it on another network and had changed from DHCP to static ip addresses.

After a while I figured that:

  1. the host could ping the guest

  2. the guest could ping the host

  3. the guest could see the internet

  4. no other networking (http, ssh etc) worked


Now that I knew what I was dealing with, I quickly found a bug report:
Bug #105697 in vmware-player (Ubuntu)

My host was Ubuntu 7.04 and the guest was Fedora Core 5. I seems there is a problem with TCP (ping is ICMP so that works) - to quote the bug report:
Host and Guest could talk to each other when using non-TCP based services, but when TCP based services(SSH) were used the connection failed:
I believe from looking at the vmware forums, that this can happen with any host operating system if the driver for your network card has some kind of TCP Offload Engine or something like that.

From lspci I can see my ethernet card is a Realtek:
02:01.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL-8139/8139C/8139C+ (rev 10)

I still haven't found a solution to this - the command for turning off TCP Offload Engine doesn't seem to work for the Realtek.

The PHP binary coming with ISPConfig does not work properly on your system!

Ahhh, this old chestnut. I was installing ISPConfig-2.2.5 when I came across this. I'd done a Fedora 5 install as per The Perfect Setup - Fedora Core 5 (at least I think I followed it exactly), but I still came up with this error.

I found this forum entry (see post 13) , and essentially I needed to install bison and flex. I issued this command to make sure I had everything:
yum install make bison flex gcc

I think it was 'bison' that made the difference, because I've actually seen a different error when flex is not installed.

I have to say, Till and Falko (and others?) at HowToForge are fantastic, and have created a great resource on the web. These guys really know their stuff and are very helpful.

Basic Apache2 setup

I just installed Apache 2.2.4 on Windows XP. I needed to set up virtual hosts, so I added the following to C:\WINDOWS\system32\drivers\etc\hosts:
127.0.0.1 server1.localhost server2.localhost
127.0.0.1 www.server1.localhost www.server2.localhost

Now to configure Apache, the virtual host configuration needs to be included in C:\Program Files\Apache Software Foundation\Apache2.2\conf\httpd.conf by uncommenting the line containing:
Include conf/extra/httpd-vhosts.conf

Edit C:\Program Files\Apache Software Foundation\Apache2.2\conf\extra\httpd-vhosts.conf to set up your virtual hosts – In my case I used the following:
NameVirtualHost *:80

<Directory />
Order deny,allow
Allow from all
</Directory>

<VirtualHost 192.168.0.102:80>
ServerAdmin webmaster@server1.localhost
DocumentRoot /www/docs/server1.localhost
ServerName server1.localhost
ServerAlias www.server1.localhost
ErrorLog logs/server1.localhost-error_log
CustomLog logs/server1.localhost-access_log common
</VirtualHost>


<VirtualHost 192.168.0.102:80>
ServerAdmin webmaster@server2.localhost
DocumentRoot /www/docs/server2.localhost
ServerName server2.localhost
ServerAlias www.server2.localhost
ErrorLog logs/server2.localhost-error_log
CustomLog logs/server2.localhost-access_log common
</VirtualHost>

Notice the <directory> directive. By default, everything is denied in httpd.conf, so you need this to allow the files in your docs directory. If you don’t, you’ll see 403 not authorized errors in your browser, and you’ll see something like the following in your error log (C:\Program Files\Apache Software Foundation\Apache2.2\logs\server1.localhost-error_log):
client denied by server configuration: C:/www/docs/server1.localhost/

I’ve put the content for my hosts in
C:\www\docs\server1.localhost
C:\www\docs\server2.localhost

Now I can access my content through
http://server1.localhost/
http://server2.localhost/

The next thing I want to do is redirect from www.server1.localhost to server1.localhost – the extra www is unnecessary.

So in httpd.conf uncomment the rewrite module:
LoadModule rewrite_module modules/mod_rewrite.so

Now add the following to the virtual host definition:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^server1\.localhost [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*) http://server1.localhost:%{SERVER_PORT}/$1 [L,R]
RewriteCond %{HTTP_HOST} !^server1\.localhost [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://server1.localhost/$1 [L,R]

Try accessing http://www.server1.localhost/ and see how the browser location changes to http://server1.localhost/

I have a few static resources that I use in several applications on different virtual hosts – things like libraries (Prototype, YUI etc). Rather than uploading them several times, I can put them in a common location and map an alias in each virtual host:
Alias /common /www/docs/common

Now I can access http://server1.localhost/common and http://server2.localhost/common and have them both serving from the same content.

If I put content in versioned directories, then my applications can pick and choose which version they need, and none are forced to upgrade. For example:
/www/docs/common/yui/2.2.0/
/www/docs/common/yui/2.2.2/

Serving this content from Apache in this manner is much more efficient than (for example) including it in my java web applications – when uploading new versions of the applications the WAR is much smaller without all of this static content!

Download Apache from http://httpd.apache.org/download.cgi and view the documentation at http://httpd.apache.org/docs/2.2/

The full vhosts file:
NameVirtualHost *:80

<Directory />
Order deny,allow
Allow from all
</Directory>

<VirtualHost 192.168.0.102:80>
ServerAdmin webmaster@server1.localhost
DocumentRoot /www/docs/server1.localhost
ServerName server1.localhost
ServerAlias www.server1.localhost
ErrorLog logs/server1.localhost-error_log
CustomLog logs/server1.localhost-access_log common

RewriteEngine on
RewriteCond %{HTTP_HOST} !^server1\.localhost [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*) http://server1.localhost:%{SERVER_PORT}/$1 [L,R]
RewriteCond %{HTTP_HOST} !^server1\.localhost [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://server1.localhost/$1 [L,R]

Alias /common /www/docs/common
</VirtualHost>

<VirtualHost 192.168.0.102:80>
ServerAdmin webmaster@server2.localhost
DocumentRoot /www/docs/server2.localhost
ServerName server2.localhost
ServerAlias www.server2.localhost
ErrorLog logs/server2.localhost-error_log
CustomLog logs/server2.localhost-access_log common

RewriteEngine on
RewriteCond %{HTTP_HOST} !^server2\.localhost [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{SERVER_PORT} !^80$
RewriteRule ^/(.*) http://server2.localhost:%{SERVER_PORT}/$1 [L,R]
RewriteCond %{HTTP_HOST} !^server2\.localhost [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://server2.localhost/$1 [L,R]

Alias /common /www/docs/common
</VirtualHost>

Wednesday, 8 August 2007

Constantly learning what not to do

I'm sitting here looking at a JSP file which is over 5000 lines long. It has a massive amount of Java code and JavaScript scattered through it, along with some custom tag libraries. It generates an HTML file over 1.5 meg in download size.

The workstation I am using is a Pentium D with 1 Gig of RAM, and the tools I'm using can't cope so I'm resorting to simple text editors to make changes.

Once again, I'm spending most of my time at work learning (once again) what not to do. I'm one of the (apparently) few people who know not to do this kind of thing. But this is where I spend most of my time - fixing other peoples mistakes - and unfortunately this is a direct impediment to me learning new, better things and improving myself.

I'm really looking forward to the day a manager says:
"Instead of getting 3 developers who don't know what they are doing to build the system, and then bring someone good in to fix it, why don't we get one good developer to build it and 3 inexperienced developers to maintain it."

This attitude would mean:

  1. The good developer gets to learn and improve, instead of working on problems that should never have existed

  2. The inexperienced developers get to work on well written systems where they might actually learn what should be done


Does anyone actually think we might get there one day?

Does anyone know any companies that employ this strategy?

Until that day, I'll just have to learn 'what to do' after hours at home (few), and try and unlearn 'how not to do it' which I learn during the hours at work (many).

It's a crazy world.

Distributing applications as zip files

I really like just being able to download a program as a zip file, unzip it, and run it. Sure, an installer has some advantages such as adding shortcuts to your menu etc, but I don't rate these as highly as the convenience and simplicity of a 'zip install'.

This is especially true for Java programs which can remain platform independent. I even use the same installation on my dual boot laptop - regardless of whether I'm in Windows or Linux, I can just have the one binary unzipped to a common location.

There is another reason why simplicity wins too - at work the corporate environment is necessarily complex. I just tried installing a program (WinMerge) through an installer and it claimed that 'You must be logged in as an administrator when installing this program'. I am supposed to have administrator rights on this machine. I've run other installers (FireFox) okay. So this installer tried to do something different and apparently it couldn't. Luckily there is a plain old binary zip download for it.