Category Archives: Linux

Using Nagios to monitor multiple VirtualHosts

On first sight, Nagios it doesn’t look like Nagios can be used to monitor websites hosted on the same server. All concepts in Nagios revolve around services and hosts. The whole “sub-part of service”, like a VirtualHosts in the HTTP service, doesn’t seem to fit. It is perfectly possible though.

Let’s start with a simple plugin to check whether a VirtualHost if functioning correctly (returning HTTP status 200, 301 or 302). This can’t be done with check_http, because it will only warn when a 404 is found.

#!/usr/bin/php
<?php
$headers = @get_headers($argv[1], 1);
if(!$header) { echo "Could not connect to $url"; exit(2); }

if(preg_match('/200/', $headers[0])) {
        print_r($headers[0]);
        exit(0);
} elseif(preg_match('/302/', $headers[0])) {
        print_r($headers[0]);
        exit(0);
} elseif(preg_match('/301/', $headers[0])) {
        print_r($headers[0]);
        exit(0);
} else {
        print_r($headers[0]);
        exit(2);
}
?>

Save this in /usr/lib/nagios/plugins/check_www and make the file executable.

Next, we have to create a command for Nagios to use. Paste the following in /etc/nagios-plugins/config/www.cfg

define command{
        command_name    check_www
        command_line    /usr/lib/nagios/plugins/check_www '$ARG1$'
}

Now finally, add service definitions like this to your Nagios configuration file.

define service {
        host_name               yourservername
        service_description     theurlyouwanttomonitor.com
        check_command           check_www!http://theurlyouwanttomonitor.com
        use                     generic-service
}

Good luck!

SparkleShare

Dropbox on Your Own Server

I’ve always liked Dropbox, except for one thing: I don’t trust them with my data. Also, it seems wrong to pay $ 10,00 for 50 GB of storage when you have your own server with much more storage and available on a fast network.

Well, finally there is a solution. It’s called SparkleShare and it’s completely open source and uses Git as a backend. Today they released a very early alpha version and I tried it out immediately. After having some trouble with the interface (you need to insert <username>/<reponame> in the folder input box if you use Github), everything worked great. However, I don’t advice anybody to use it in production. It’s still in development and can contain serious bugs. I can’t wait till it gets more mature and ready for production usage!

Howto: Live migrate to software RAID 1

Feel insecure about your data? Don’t trust your harddrive anymore? Use this howto to migrate your running Ubuntu Linux system to software RAID 1.

Before starting off, I assume you have your running system on /dev/sda and your new harddrive is called /dev/sdb.

Boot up your system and install the mdadm package. We now have to create partitions on sdb that are the same as sda. Because I have identical disks, I just copy the partition table from sda to sdb like so:
sfdisk -d /dev/sda | sfdisk /dev/sdb
After that, I use partprobe to let the Linux kernel know I have changed the partition table.

Next step is to create a degraded RAID array on sdb which we can copy the files to and than add sda to the array. For every partition you have to run:
mdadm --create /dev/md0 --level 1 --raid-devices=2 missing /dev/sdb1

Where you replace sdb1 with the partition you want. Now create filesystems on these new raid devices:
mkfs.ext3 /dev/md0
Again, run this for all your mds.
After copying all the files to your new array, we have to modify a few files.

  • /boot/grub/menu.lst
  • /etc/fstab
  • /etc/initramfs-tools/conf/resume

All these files contain references to UUIDs that are no longer correct. I simply replaced them with /dev/md0 for example. You can try to use UUIDs, but I believe that the (striped) partitions have the same UUIDs as the raid devices (the mds). If you’ve changed everything, run:
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
And don’t forget to update your initrd:
initramfs -u

That’s all! You can now enjoy the safety of RAID 1 without to much hassle. To check the status of your array, look in /proc/mdstat. Also make sure you setup a mail server or ssmtp, because the mdadm tools will try to send you an email if one of your RAID devices is degraded/corrupt.

pinnacle_dvb-t_stick_remote

Pinnacle DVB-T stick remote

Another post about that Pinnacle DVB-T stick? No, this one is about the remote! I wrote that the remote wasn’t completely working yet. Apparently, there is a driver for this remote or the stick that converts the buttons from the remote to “keyboard events”. Meaning I can type the number 0-9 with my remote for example. However, the “change channel” buttons appear to send a keycode that is above 255 and the X11 protocol only reserves one byte for keycodes. This means those keycodes can’t be send to the X11 server and will disappear. There’s a bug about this in the X.org bugzillay: http://bugs.freedesktop.org/show_bug.cgi?id=x11-keycode-limit and their solution: Change the X11 protocol (meaning: start development on the X12 protocol) or remap those keyevents somewhere between the kernel and X.org. I think the last solution is probably the simplest. I only have to figure out how to remap those keys with hal.

pinnacle_dvb-t_stick

Pinnacle DVB-T stick on Ubuntu Jaunty

Yesterday I decided to buy the Pinnacle DVB-T Stick (also known as Pinnacle TV Stick 72e) to watch some free-to-air channels. In the shop I searched on Google for Linux support, to make sure I didn’t have to return the product. The first few hits seemed positive (2 years ago), so I decided to take the plunge.

After arriving at home, I plugged the device in an empty USB port and saw this in my dmesg:


[11906.080060] usb 1-6: new high speed USB device using ehci_hcd and address 5
[11906.214249] usb 1-6: configuration #1 chosen from 1 choice
[11906.245886] dib0700: loaded with support for 8 different device-types
[11906.246212] dvb-usb: found a 'Pinnacle PCTV 72e' in cold state, will try to load a firmware
[11906.246222] usb 1-6: firmware: requesting dvb-usb-dib0700-1.20.fw
[11906.252816] dvb-usb: downloading firmware from file 'dvb-usb-dib0700-1.20.fw'
[11906.471526] dib0700: firmware started successfully.
[11906.972059] dvb-usb: found a 'Pinnacle PCTV 72e' in warm state.
[11906.972135] dvb-usb: will pass the complete MPEG2 transport stream to the software demuxer.
[11906.972367] DVB: registering new adapter (Pinnacle PCTV 72e)
[11907.186126] DVB: registering adapter 0 frontend 0 (DiBcom 7000PC)...
[11907.369975] DiB0070: successfully identified
[11907.370122] input: IR-receiver inside an USB DVB receiver as /devices/pci0000:00/0000:00:12.2/usb1/1-6/input/input12
[11907.396132] dvb-usb: schedule remote query interval to 50 msecs.
[11907.396140] dvb-usb: Pinnacle PCTV 72e successfully initialized and connected.
[11907.396744] usbcore: registered new interface driver dvb_usb_dib0700

Great! All drivers and firmware load automatically in Ubuntu 9.04 Jaunty.

Next step: actually getting video on my screen. After Googling I found out I first had to scan for channels using dvbscan. However, it gave me the non-informal message “Unable to query frontend status”. Apparently there is also another scanning program called scan. I ran it like this:
scan /usr/share/dvb/dvb-t/nl-All > ~/.mplayer/channels.conf
Now I could start mplayer dvb:// and enjoy watching DVB-T digital television! Note you can switch channels with h (next) and k (previous). Last thing I need to figure out is how to use the remote for this (I can change the volume already).

Fixing FreeNX on Fedora 11

Today I had some problems getting FreeNX to work on Fedora 11. FreeNX is a VNC-like system that has much better performance than VNC itself. It is therefore very usefull if you would like to access your computer via your Cable or ADSL connection.

After installing FreeNX in Fedora, whenever I connected, I got some strange error messages. The error message also told me to run some command via ssh to find out more. Apparently, FreeNX wanted to start on display port :0, which was already in use by X. To fix this, I copied /etc/nxserver/node.conf.sample to /etc/nxserver/node.conf and uncomment the line that says: DISPLAY_BASE=1000 and change it to DISPLAY_BASE=1001. This will start the NX server on port 1001 (display port :1).
However, this fix would still not allow me to connect. After searching around on the internet, I found out the package was missing a dependency on xorg-x11-fonts-misc. Installing it allowed me to open a session and enjoy the responsiveness of FreeNX!

In short: Make sure your DISPLAY_BASE port is not set to 1000 if you also have another X server running and don’t forget to install xorg-x11-fonts-misc.

Using GNU screen as virtmanager for KVM

After my last post about KVM, somebody emailed me, asking how I use KVM’s serial console in combination with screen. It’s a rather simple, but really usefull solution if you think tools like virtmanager are too much for you and you don’t like to use VNC. So this post will try to explain it to you.
For starters, you have to add the -nographic option to you KVM parameters. Next, make sure your virtual machine outputs it’s console to serial device 0. For example, start the Linux kernel with console=ttyS0 and make sure there is a getty process running on that same device. Now, whenever you start KVM in a GNU screen (with that -nographic parameter) you will see the dmesg scroll by and will end up with a login prompt. You can just keep this KVM running while detaching the GNU screen session (ctrl+a d) and you can re-attach by starting screen -x.
I use this on my server to start my two virtual machines. I made a screenrc like this:
# display a nice status bar on the bottom of the screen
hardstatus alwayslastline "%-Lw%50>%n%f* %t%{-}%+Lw%< %=[%c]"
vbell off
deflogin off
# use virtio for disks also!
screen -t production kvm -m 2048m -nographic -drive file=production.raw,if=virtio,boot=on -net nic,model=virtio -net tap,ifname=tap0,script=no,downscript=no -smp 2
screen -t development kvm -m 1024m -nographic -drive file=development.raw,if=virtio,boot=on -net nic,model=virtio -net tap,ifname=tap1,script=no,downscript=no

Whenever the server boots it runs the following command in my rc.local:

# start KVM
cd /srv/
su frank - -c 'screen -c screenrc -dm'

So the server starts the GNU screen and the GNU screen start my virtual machines. If I can’t login via ssh in one of my virtual machines, I just connect to the host and attach to the screen to debug the problem.