Backup Server Slow Down

Recently I noticed that my backup server was slowing down. Doing system checks told me that it wasn’t running out of memory, nor was the CPU being highly utilised. It was only when I went into the server room and noticed that the hard drive activity light was persistently on that I realised what was causing the slow down.

I ran iotop and analysed what process was continually writing to the disk. I noticed this process was updatedb.mlocate. This is the Ubuntu indexing process, which goes through all the files indexing them to make searching much quicker. As this backup server uses backuppc and has years worth of backups, it has many thousands of files to be indexed and meant that updatedb.mlocate (which is run daily) was taking longer than 24 hours to index.

To solve this problem I edited the file /etc/updatedb.conf and added the backuppc directory to the line that tells updatedb.mlocate not to index files within a certain path. This is simply done by adding “/var/lib/backuppc” to the end of the line that starts off with “PRUNEPATHS=”.

So mine now reads: PRUNEPATHS=”/tmp /var/spool /media /var/lib/backuppc”

suPHP + Userdir on Ubuntu

Recently I’ve had the need to combine suPHP with the userdir mod for Apache on Ubuntu. By default they don’t play nice together. So here is a quick guide on how to get it working.

If you have installed a standard LAMP server (there are many guides on how to do this), you now need to install the suphp package for apache, this is called libapache2-mod-suphp:

$ sudo apt-get install libapache2-mod-suphp

Once that has been installed open the file /etc/suphp/suphp.conf in your favourite text editor. Find the line that has the docroot on, and change the docroot so that it is just “/”. This means that the suphp engine will parse anywhere in the file system, and not just in the standard html directory, thus allowing users to have their own.

docroot=/

You may also want to change the security options as appropriate, just change the “false” to “true” of the applicable ones the enable them. This is worth experimenting with. Further down you will want to set the “check_vhost_docroot” is set to false, this again is to do with the fact that userdirs are not in the vhost’s document root.

check_vhost_docroot=false

Finally you have the min_uid and min_gid properties. These are worth altering if you still want to be able to have a website running as www-data (such as the default website). If this is the case, change them both to the uid and gid of www-data (33 by default). It is not recommended to allow suphp to run as root, so do not set it to 0.

min_uid=33
min_gid=33

Finally, you need to enable the mods suphp and userdir, and disable the mod php5, this is done with two commands, and then restart apache2:

sudo a2dismod php5
sudo a2enmod userdir suphp
sudo /etc/init.d/apache2 restart

This should then allow you to run php scripts as the user who created them. To test this, create a new php file that contains:

<?php
system(id);

This will give you information of the user that the php process is running as. I recommend changing the ownership and retrying it, just make sure sure suphp is running as it should be.

Arithmetic in Bash

Bash is not exactly brilliant at performing numerical calculations. Recently I’ve required the need to see how many people are currently logged in on the terminal servers through NX. Now, if people are logged in via standard SSH, then it’s quite easy to count:

who | wc -l

However, if you want to perform a line count of the NX list, you have 6 lines at the top which are not part of the count. In order to perform this subtraction, we need to do a calculation. To do this in bash we use a $(()):

echo $((2 + 2))

So, if we were to use this when performing the command on nxserver, this is how it would look in the end:

echo $(($(/usr/NX/bin/nxserver --list | wc -l) - 6))

Or, if you’re not running this script as root (and using sudo):

echo $(($(sudo /usr/NX/bin/nxserver --list | wc -l) - 6))