Latest Posts

Latest Tweets

    Posts Tagged ‘Ubuntu’

    Puppet on Ubuntu 10.04

    December 18, 2011 4:44 am    Posted by Viktor Petersson    Comments (2)

    Yesterday I decided that it’s about time to learn Puppet. I’ve had my eye on both Puppet and Chef for some time now. Yesterday after reading this Quora-thread and this blog-post, I decided to go with Puppet.

    After downloading their test-VM and going through the tutorial, I pretty quickly fell in love with the simplicity and structure. Puppet is straight forward and rather intuitive.

    One of the architectures that I wanted to deploy Puppet on was running Ubuntu 10.04 LTS. Unfortunately, the version from Ubuntu’s repository is really old (0.25.4), and not really compatible with much of the cool things you can do with Puppet.

    Fortunately, PuppetLabs do provide their own repository, but the instructions for adding this repo wasn’t really at par with the rest of their excellent documentations — hence this post.

    If you’re a die-hard Ubuntu/Debian-fan, this is probably pretty straight-forward, but if you’re not, here is what you need to do:

    sudo su - 
    echo -e "deb http://apt.puppetlabs.com/ubuntu lucid main\ndeb-src http://apt.puppetlabs.com/ubuntu lucid main" >> /etc/apt/sources.list
    apt-key adv --keyserver keyserver.ubuntu.com --recv 4BD6EC30
    apt-get update
    apt-get install puppet

    Ok, so that was pretty straight forward. The only tricky part was importing the keys, but now you know how to do that too.

    Rebuilding a Linux software RAID array

    June 18, 2011 9:49 am    Posted by Viktor Petersson    Comments (0)

    The process is pretty straight forward, and I’m writing this as a ‘Note-to-self’ for future references than anything else. If anyone else find it useful, that’s great.

    Identify the broken drive

    Start by identifying the device as the system know it (ie. /dev/sdX or /dev/hdX). The following commands should provide you with the information:

    cat /proc/mdstat
    mdadm --detail /dev/mdX
    cat /var/log/messages | grep -e "/dev/hd" -e "/dev/sd"

    Once you’ve identified the drive, you want to know something more about this drive, as /dev/sdX doesn’t really tell us how the drive looks like. In my case, I have three identical drives, so the following command didn’t help me much, but maybe it does for you.

    hdparm -i /dev/sdX

    That should give you both the model, brand and in some cases even the serial number. Hence this should be plenty to identify the drive physically.

    Replace the drive

    Not much to be said here. I assume you already know this, but you need a drive of equal size or larger.

    Partition the new drive

    If your system boot up in degraded mode, then just boot up your system. If not, boot it off of a Live CD (I used Ubuntu’s LiveCD in ‘Rescue mode’).

    Once you’ve made it to a console, the first thing we need to do is to partition the new hard drive. The easiest way to do this is to use sfdisk and use one of the existing disks as the template.

    sfdisk -d /dev/sdY | sfdisk /dev/sdX

    (where sdY is a working drive in the array, and sdX is your new drive)

    Rebuilding the array

    The final step is to add the new drive to the array. Doing this is surprisingly easy. Just type the following command:

    mdadm /dev/mdZ -a /dev/sdX1

    (assuming you want to add the partition sdX1 to the RAID array mdZ)

    Of that went fine, the system will now automatically rebuild the array. You can monitor the status by running the following command:

    cat /proc/mdstat

    This solution is so ugly that I felt that I had to post it =).

    I had a problem. Whenever I plugged in or rebooted, the a 3G modem into a Linux machine, it appeared on a different path (/dev/ttyUSBX). That creates some issues, as I’m using to connect to the internet, and Wvdial is using a hardcoded path to the modem. To fix this, I had to manually edit the file every time it changed. That’s very annoying. Now add in the fact that this is sitting on a remote machine that I have little physical access to, this is a real problem.

    My initial approach was to turn to udev and write a rule for the modem that creates an automatic symlink, such as /dev/modem. Unfortunately, when you add usb_modeswitch into the mix, it breaks. For some reason, usb_modeswitch simply wouldn’t detect the modem when doing this, and hence render it useless.

    Instead, I figured, if I write a Bash-script that automatically creates a symlink, that would take care of the issue. Of course, it is very ugly, but it does indeed work. Now I can simply run this script in Cron and that way know that I always have the correct path to the modem.

    So how did this script look you may ask. This is how:

    #!/bin/bash
    MODEM=$(cat /var/log/messages |grep "GSM modem (1-port) converter now attached to" | tail -n 3 | head -n 1 | perl -pe "s/.*GSM modem \(1-port\) converter now attached to (ttyUSB.*)$/\1/g;")
    CURRENT=$(ls -l /dev/modem | awk '{print $10}' | perl -pe "s/\/dev\/(ttyUSB.*)$/\1/g;")
     
    if [ $CURRENT != $MODEM ];
    then
    	rm /dev/modem
    	ln -s /dev/$MODEM /dev/modem
    fi

    I never said it was pretty, but it does indeed work. If you wonder what the ‘head’ and ‘tail’ part is all about, it is because the system creates three paths, but only the first one works.

    Update: Turns out it is a bad idea to run this in Cron, as the logs will rotate. Instead, launch it at boot in rc.local, but make sure you insert a ‘sleep 10′ or similar to allow the modem to settle.

    Update 2: Turns out there is a far more elegant solution to the problem. The system automatically generates a symlink for you. In my case, the modem is accessible via:
    /dev/serial/by-id/usb-HUA_WEI_Huawei_Mobile-if00-port0
    This means that you can hard-code that path instead of having to run a silly script to generate a symlink for you.

    Local management tools are critical for most Linux and Unix distributions. For instance, if you delete Python 2.6 from your Ubuntu installation, it becomes more or less unusable. This is because most local management tools are written in Python. I have no problem with this. On the contrary, I think it makes a whole lot of sense to write management tools in a high-level language, such as Python or Ruby.

    The problem is that there are many circumstances in where you’d would need to install a different version of these languages, as some other tool or application you’re using requires it. This is likely to cause problems. It is particularly true if you’re running an LTS-version of Ubuntu, or CentOS/RHEL (which is still using Python 2.5). Yes, you can run multiple versions of Python on the same machine, but it’s quite likely that applications will be confused on what version to use. Also, what version should you point the command ‘python’ to? Yes, you can call on Python with it’s full name (ie python26), but ‘python’ is still what many scripts call on.
    more>>

    Monitor Nginx and disk-usage with Monit

    July 12, 2010 2:19 am    Posted by Viktor Petersson    Comments (2)

    Yesterday I posted an article on how to monitor Apache and PostgreSQL with Monit. After setting that up I was amazed how simple and flexible Monit was, so I moved on with two more tasks: monitor Nginx and disk usage.
    more>>

    Monit is a great little utility that monitors your daemons. If a daemon fails, Monit will start the daemon it will automatically restart the process. It comes in very handy if for web-servers, such as Apache.

    For Red iGone we use Apache as the web-server, and PostgreSQL as the database. I wanted to configure Monit to keep an eye on these processes. As it turns out, setting up Monit was really straight-forward.

    I tried this on Ubuntu 9.10 and 10.04. If you try this on a different Ubuntu version (or other distribution), it is likely that you will need to make changes to apache.conf and postgresql.conf.
    more>>

    Last week I published a new version of my ZoneMinder Virtual Appliance. The virtual appliance is great if you want to easily deploy ZoneMinder without having to spend time setting it up. However, in some situations, you want to run ZoneMinder directly on the hardware. Perhaps you need better performance or simply need to capture video streams from V4L-devices.

    Since I already spent the time getting it running, I thought I’d share the instructions for getting it running. It’s pretty straight forward, but there are a few minor things that took me some time to get around.
    more>>

    Hello Grub, you suck!

    May 14, 2010 5:59 am    Posted by Viktor Petersson    Comments (0)

    In the last few weeks I had to set up a few new Linux servers. Since Ubuntu is my preferred Linux dist in recent years, 10.04 LTS was a natural choice.

    Ubuntu 10.04 LTS is a great Linux distribution, with one exception: Grub. I really mean it. Grub is probably the worst boot loader to date. Is so bad that it could equally well be replaced with the following shell script:

    echo ""
    sleep 10

    The better alternative to Grub is obviously Lilo. While it may be obsolete, poorly updated and 20 years old, it does one thing that Grub doesn’t: it works. Personally I couldn’t care less about fancy splash screens and all the bells and whistles that Grub can put on it’s repertoire. It’ doesn’t matter when it cannot boot the system. Please Ubuntu, just ditch Grub and make Lilo the default boot loader.