Christmas Projects 2014: Raspberry Pi PBX

Preamble

I was lucky enough to take two full weeks of holidays over Christmas and New Years this year. It was magnificent and completely rejuvenating, despite the fact that everyone in my house was sick with one or more ailments throughout. In fact being sick and stuck at home may have in fact been just the excuse I needed to indulge in a few geeky back-burner projects.

Project 2: Raspberry Pi PBX

I have been running Elastix for years. Elastix is a top-notch open source project that glues together many other open source telephony projects (i.e. Asterisk, FreePBX, HylaFAX, and many more) into a single distribution built on top of CentOS. This setup has worked flawlessly for years, but I had an idea I wanted to try out… build a basic PBX phone server on a $35 Raspberry Pi computer.

My project: use this amazing little Raspberry Pi to run my home phone system.

Raspberry Pi

Well as it turns out, this project was a resounding: SUCCESS

I had most of the equipment around the house already, here is my setup:

Raspberry Pi – 1st Generation.
Lexar Professional 16GB Class 10 SD Card – For Raspberry Pi storage.
RasPBX – A Raspbian based Linux distro with Asterisk, FreePBX, HylaFax, etc.
Aastra 480i CT – A decent IP phone with a cordless handset.
Polycom SoundPoint IP 335 (x2) – Really great sounding IP phones.
Cisco SPA122 ATA – Connected to a fax machine.
NetGear ProSafe PoE Switch – 24 port Power over Ethernet to power the phones.

Also useful may be the layout of the network:

phone-network-diagram
So the Raspberry Pi, the three IP phones, and the Analogue Telephone Adapter are connected through the NetGear switch. Additionally the three IP phones are powered by the switch (PoE), which is extremely nice because you don’t need a big ugly power adapter plugged into each of your telephones.

To configure Asterisk, RasPBX comes with a very slick web application called FreePBX that allows you to setup and maintain your trunks (linkages to your VoIP provider), telephone extensions, inbound call routes, outbound call routes, and much more. You can get really fancy with this stuff, and it’s pretty fun to think of potential uses. In terms of VoIP providers I have been using Unlimitel (owned by Primus Canada Inc.) for 7+ years now, and have nothing but great things to say about their service. They’re not fancy, but they certainly know what they’re doing.

When I started this project I went into it with the expectation I could make it “work”, but that it probably would not be something I could rely on as a phone server. Needless to say that after 3+ weeks of this being fully operational without any issues, this setup has exceeded all expectations and cost less than $50.

Also interested in Project 1: PowerMac G5 Linux Desktop? Read on…

Christmas Projects 2014: PowerMac G5 Linux Desktop

Preamble

I was lucky enough to take two full weeks of holidays over Christmas and New Years this year. It was magnificent and completely rejuvenating, despite the fact that everyone in my house was sick with one or more ailments throughout. In fact being sick and stuck at home may have in fact been just the excuse I needed to indulge in a few geeky back-burner projects.

Project 1: PowerMac G5 Linux Desktop

Apple PowerMac G5When I started working at Queen’s University 11 years ago I was graced with a new Apple PowerMac G5 desktop to work with. While it is long passed its’ prime in the Apple world, this machine with a dual 1.8Ghz G5 processor and 6GB’s of RAM will run Linux without breaking a sweat. It’s still decent hardware.

My project: turn this beautifully designed 11 year old relic into a completely usable Linux desktop computer for light usage.

As you can probably guess, projects like this can go South. 16 hours, several *buntu installations, and a Debian 7.7 installation later, project status: FAIL

This particular PowerMac G5 has an NVidia GeForce FX 5200 graphics card, which absolutely will not work reliably with PowerPC architecture. The reason I think I sunk so much time into trying different things is that it doesn’t fail outright, it just fails in different ways between different versions of different Linux distributions (i.e. screen flickers, text disappearing, white boxes covering certain dialogs, etc.).

All is not lost for 2 reasons:
1. I am apparently stubborn and have ordered an old ATI Radeon 9600 XT for this machine, which appears to have a functioning driver available. I will update later to confirm.

Update: No, the ATI Radeon 9600 XT does not work. Waste of money. Boo. I’m open to suggestions if someone reads this. Hum… Should I install Mac OS X 10.5, or use the thing as a coffee table? That’s pretty much where I’m at.

2. I have a new love and respect for Debian. What a great operating system.

Next – Coming Soon – Project 2: Raspberry Pi PBX

Cleaning Up Is Hard To Do

Linux TuxI have been administering Linux servers for a while now so coming across a new problem is both exciting and stressful, especially when that problem is on a high demand production server. I recently came across one of these scenarios, and was surprised how difficult it was to solve.

I had a single directory on a server that contained millions and millions of tiny 32Kb text files (which were actually non-sharded PHP session files that didn’t get caught in garbage collection, and went unnoticed for months on a busy server). The interim fix to that problem was easy:

mv /var/php/sessions /var/php/sessions.evil && mkdir /var/php/sessions

The real problem was that I was left with this sessions.evil directory that I couldn’t delete, ignore in snapshot backups, or even list of the contents of because there were just too many files and going anywhere near it would use too much disk I/O and cause the load on the server to spike.

After using / writing various Bash, Python, PHP, etc, scripts that caused too much load on the server I happened across this genius solution by Zhenyu Lee (and a comment by Paul Reiber)… to use rsync instead of rm, find, xargs, etc:

On a CentOS box and using my example directory of /var/php/sessions.evil, which was owned by root:apache do this:

cd /var/php
mkdir empty_dir
chown root:apache empty_dir
rsync -vvvv -a –delete empty_dir/ sessions.evil/

Depending on how many files are in your sessions.evil directory this could take a while (2 days in my case), but the 5 minute load average on the server stayed between a manageable 2.0 and 3.0. My twist to Zhenyu’s solution was to add some verbosity (-vvvv) in there so I could tell that rsync was actually doing something.

Paul’s next comments are important though, so once rsync is eventually done mirroring your sessions.evil directory with your empty_dir pay attention:

rmdir sessions.evil
mkdir sessions.evil
rmdir sessions.evil empty_dir

The first rmdir sessions.evil will cause a bit of a load average spike for a few minutes, but once it’s gone… whew.

Well there you go, happy rsyncing, and a huge thanks to Zhenyu Lee for posting that unique and brilliant solution.

Find All WordPress Installations

I was trying to figure out how many WordPress installations lived on one of my hosting servers recently, and I also wanted to see how good the site owners are at keeping them up-to-date, which means I also wanted to find out the WordPress version number of each installation.

I couldn’t find any quick way of doing this so I turned the linux find command and grep to give me a hand. Here is the command (which must be run as a privileged user):

find /var/www/vhosts -type d -name "wp-includes" -print -exec grep "wp_version" {}/version.php \;

Just replace /var/www/vhosts with the root directory of where all of your domains are stored. Hope this helps someone. Cheers.

Updated: I switched the above command to use “-type d” vs “-d” as per James’ comment below. Thanks James.