Posts Tagged ‘Linux’

Since we started WireLoad, the number of websites we host have grown steadily. It’s a myriad of sites, ranging from product sites to websites belonging to friends and family. Many of them are WordPress-sites (just like this one), while others are more complicated. Some use databases, while others don’t. Since we’re often in a rush when we set up a site, documentation often suffers, and you have to spend time later on trying to decipher how things were set up.

This past week I finally had enough and decided to resolve this issue once and for all. What we really needed was a template-based system that could take care of everything and provide us with a user friendly interface. Puppet felt like the best tool for the job so I got busy writing a custom module for this.

The final result is a module I named Puppet-hosting. It allows you to manage all your websites using Puppet. To add a new site, all you need to do is to add a few lines to in your site.pp, and you’re all set.

Here’s an example of how it can look:

hosting::site { 'My Website':
  type        => 'wordpress',
  url         => 'mysite.net',
  url_aliases => ['mysite.*', 'www.mysite.net'],
  ip          => $ipaddress_eth0,
  contact     => 'Viktor Petersson [email protected]>',
}

Not only does this make it much easier to manage all the sites, it also speeds things up and avoids human errors, such as typos (and if you do have a typo, it’s easy to spot, since it’s only a few lines in sites.pp).

My latest project: Screenly

August 1, 2012 4:10 am    Posted by Viktor Petersson    Comments (2)

One of the most hyped pieces of hardware in recent time is the Raspberry Pi. It is hyped for a very good reason. For $35 you get a fully functioning Linux-computer which is about the size of a deck of cards. While there have been plenty of micro-computers around in the past, none at this extremely low price point. The Raspberry Pi is simply any DIY’ers wet dream.

After months of wait, I finally got mine a few weeks back. My first project was Screenly: A digital signage platform built for the Raspberry Pi.

While still in early beta, the Screenly is fully functional and available on Github for anyone to download and install.

The entire system is designed to be a ‘set and forget’-appliance. Once installed, you manage the content from your web browser on your local computer.

Here’s a video of an early version of Screenly in action:

There are also screenshots and photos available of Screenly here.

For more information about Screenly, please visit the Github-project.

Munin-plugin for Zendesk

June 23, 2012 7:53 am    Posted by Viktor Petersson    Comments (0)

In recent time, I’ve really started to appreciate Munin. I’ve deployed Munin in multiple architectures already, and I still get impressed every time by how easy it is to setup.

I also really like how easy it is to write plugins. For a crash-course in writing plugins for Munin, take a look at this page.

Since I first deployed Munin to monitor YippieMove‘s architecture, I’ve written a handful of custom plugins to visualize various datapoints. However, one thing I’ve been wanting for some time was to a tool to visualize the volume of support tickets. Since we use Zendesk for support and the fact that they already got an API, all data I needed was already accessible.

I started writing the plugin this morning, and few hours later I had written one plugin for plotting all tickets (with their state), and another one for customer satisfaction.

If you want to take it for a spin, I’ve published it on Github.

Rebuilding a Linux software RAID array

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

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

Do you have a few long commands that you keep typing in the terminal? Things like ‘cd /some/long/path/that/takes/forever/to/type’ or ‘mycommand -with -lots -of -variables’?

If so, here’s something you’ll enjoy.

Just open up ~/.profile in your favorite editor, and add the following lines:

alias foo="cd /some/long/path/that/takes/forever/to/type"
alias bar="mycommand -with -lots -of -variables"

Now you don’t need to type those long commands ever again. All you need to do is to typ ‘foo’ or ‘bar’. You can of course replace foo and bar with anything you want, as well as the command.

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.

How to create SSH ‘bookmarks’

December 5, 2010 7:01 am    Posted by Viktor Petersson    Comments (8)

If you’re like me, you spend a lot of time in the terminal window. It’s not rare that I SSH into 10+ different servers in a day. Having easy-to-remember FQDN’s makes it easier, but sometimes that’s not possible. Sometimes you only have an IP to a server, perhaps the server has a really long FQDN, or perhaps SSH is running on some arbitrary port. That makes your life harder. Luckily there’s an easy fix for it.

Many people do not know that SSH comes with a bookmarkish feature out-of-the-box. All you need to do is to open up ~/.ssh/config (create it if it doesn’t exist) and add something like this:

host foobar
 hostname aaa.bbb.ccc.ddd
 port 2224

(Please note that the second and third lines are indented with a space.)

Now you can SSH into ‘foobar’ by simply typing:

ssh foobar

And voila, you no longer need to remember all arbitrary ports, IPs and hostnames. All you need to remember is your bookmark.

For more information on what you can do with ~/.ssh/config, please see this page.

Please note that this works on pretty much any platform except for Windows. But then again, if you’re this savvy, you probably know better than to run Windows in the first place =).

Introduction to scaling a website

November 27, 2010 7:21 am    Posted by Viktor Petersson    Comments (0)

Scaling architecture and web sites is really something I find exciting. I’ve playing with scaling various software for many years, but it is just recent years I’ve come to use this in production (primarily through YippieMove).

If you’re curious about scaling your website, I can really recommend the following video lecture from Harvard. It goes though concept that you might have run across in various blog-posts before. It is not super-technical, so even if you’re new to programming etc., you should still be able to understand the entire lecture.

Watch it on Academic Earth

VMware Server is a great product. It’s free and works well with most guest operating systems. However, there is one major drawback – you cannot use the ‘console’ app on Mac OS X. For some strange reason, VMware decided to only make the required Firefox plug-in available for Linux and Windows. Given that Mac OS X is the OS of choice for most tech-savvy users I know, this decision makes no sense at all. While I rarely need the console for an existing virtual machine (other than if it fails to boot or something similar), it is obviously required to install the operating system onto the virtual machine.

Until recently, I had to either remotely log into a Windows or Linux machine (or even more ironically, open it in a local virtual machine). Luckily there is a workaround: the built in VNC-support. It is a bit annoying to have to do this, but it’s probably faster than having to log into a remote machine just to access the console.

VNC connection directly to a VMware virtual machine.

more>>

There are a ton of tools out there for modifying PDF-files. Most of them are crappy, overpriced sharewares from mediocre developers looking to make cash from non-technical users. What most Mac-users perhaps do not know is that Mac OS comes with a ton of handy tools for modifying PDF files. For instance, with a few clicks, you can create an app that merges different PDF files into one file with Automator (I will post that app in a separate post).

One thing that the Mac does not do well though is to split a PDF file. Sure, you can “Print to PDF” and simply select the pages you wish to print. This works great if you’re only looking to split one file. If you have, let’s say 100 documents you wish to split, it’s not a very desirable approach. That’s where the handy toolkit Ghostscript comes into play. Most Unix/Linux users have probably encountered it at one point or another (or at least seen the package being installed), as it is widely used in the the Unix/Linux world under the hood.
more>>