OpenGrok, Ubuntu and Linux source tree

After all, thanks to our very long New Year holidays, I had a chance to install OpenGrok search and cross reference engine. The main reason is to have a tool to be able to efficiently browse Linux kernel source code. I use OpenGrok quite frequently, especially when there is a need to dive into Solaris/OpenSolaris internals. Frankly speaking, I haven’t seen anything else that comes close to it. And you know what? It’s a trivial game to install and run OpenGrok on your favorite Linux distro, BSD, Mac OS X or Solaris. But since I use Ubuntu as my cloud server all further details will be provided having it in mind. I will refer to the default installation since in 99.9% cases that would be the choice (I guess).

  1. First things first. Lets download OpenGrok and install additional packages if they’re missing.
  2. wget http://hub.opensolaris.org/bin/download/Project+opengrok/files/opengrok-0.11.1.tar.gz
    sudo apt-get install tomcat6 git exuberant-ctags
    
  3. By default, OpenGrok would use /var/opengrok so I chose to clone Linux source tree into /var/opengrok/src/linux-stable/ but you’re absolutely free to pick what suffice you most:
  4. sudo mkdir -p /var/opengrok/bin
    sudo mkdir /var/opengrok/lib
    sudo mkdir /var/opengrok/src && cd /var/opengrok/src
    sudo git clone git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git linux-stable
    
  5. Now it’s time to untar the archive and deploy OpenGrok.
  6. tar -zxf ./opengrok-0.11.1.tar.gz
    sudo cp ./opengrok-0.11.1/lib/opengrok.jar /var/opengrok/lib/
    sudo cp ./opengrok-0.11.1/bin/OpenGrok /var/opengrok/bin/    
    sudo /var/opengrok/bin/OpenGrok deploy
    
  7. Now you should have source.war copied to your webapps directory (in my case that was /var/lib/tomcat6/webapps/source.war).
  8. Start Tomcat if it’s not and run the indexer.
  9. /etc/init.d/tomcat6 start
    sudo /var/opengrok/bin/OpenGrok index /opt/opengrok/src
    Loading the default instance configuration ...
    WARNING: OpenGrok generated data path /var/opengrok/data doesn't exist
      Attempting to create generated data directory ... 
    WARNING: OpenGrok generated etc path /var/opengrok/etc  doesn't exist
      Attempting to create generated etc directory ... 
      Creating default /var/opengrok/logging.properties ...
    

There is however a small catch. The indexer is started with -Xmx option set to 2048m and this is done on purpose. Since I only had 512MB of RAM I tried to reduce Xmx down to 128, 256 and 512 megabytes but all the time I got “java.lang.OutOfMemoryError: Java heap space” error. So in the end I temporarily increased the sizing of my cloud server to 4GB and only after that the indexer had finished successfully.
I’m happy with the overall result because even with 512MB OpenGrok works blazingly fast – come in and check. I’ll do my best to update it whenever there is a new Linux release. Since OpenGrok supports incremental updates that shouldn’t be a problem:

cd /var/opengrok/src/linux-stable && git pull
sudo /var/opengrok/bin/OpenGrok update