Tricking out your AppleTV running Linux

Upset that your old AppleTV is left in the dust following the release of the new $99 AppleTV? Get Linux installed on that thing, and make it useful again!

After getting Debian successfully installed on the AppleTV, I wondered exactly how many services can run on it without overloading it. So far, the following services are running:

  • Netatalk / avahi-daemon
  • Samba
  • GKrellMd
  • OpenVPN
  • Apache 2 + PHP5
  • Asterisk 1.6 + Cepstral TTS + Lobstertech VoiceChanger + PHPAGI
  • ircd-hybrid – IRC Server
  • Nagios 3 with ircd-hybrid integration

Netatalk / avahi-daemon

This allows the AppleTV to show up on the network as a Macintosh OS X shared drive. We could easily plug in a USB external drive and this extra drive would also be shared on the network. If you want more information on configuring Netatalk on Linux, check my earlier blog posts on the subject.

Samba

This allows the AppleTV to show up on the network as a Windows shared drive.

GKrellMd

My favorite little monitoring app for Gnome, GKrellM allows you to monitor the server in real time from a little desktop widget.

OpenVPN

A simple VPN server which allows you to tunnel home from work or coffee shops.

Apache 2 + PHP5

A standard Apache 2+PHP5 install is running on this machine. Here is a screenshot of the default page I created for it:

In order to conserve memory, decrease some Apache config values:

[code]
<IfModule mpm_prefork_module>
StartServers 1
MinSpareServers 1
MaxSpareServers 5
MaxClients 50
MaxRequestsPerChild 0
</IfModule>
[/code]

WebDAV is enabled so I am able to quickly and easily edit this site using Coda.

Asterisk 1.6 + Cepstral TTS + Lobstertech VoiceChanger + PHPAGI

This AppleTV runs my VoIP phone server. Phone service is through Flowroute. If you call my phone number, it speaks out text to the caller using Cepstral TTS. Anyone placing calls using this phone system can spoof any outgoing number or change their voice with the help of the Lobstertech VoiceChanger module. Incoming spoofed CallerID numbers are “unmasked” and the true number is revealed. The main phone script is written with PHP code using PHPAGI. Surprisingly, the AppleTV CPU handles the Text to Speech very well and I don’t notice any CPU strain. Very flexible and fun phone system.

Here is a sample of what the code looks like:
[php]
function doMainMenu() {

global $debug;
global $fh;
global $agi;

$count = 0;

while ($count < 5) {
// Say Main Menu Script
$result = $agi->swift_get_data(‘Press 1 to ring the house phones or press 0 to leave a voice message.’);

// Capture which keys were pressed
$keys = $result[‘result’];
$key = $keys[0];
if ($debug) fwrite($fh, "Key Press:[". $keys[‘data’] . "]\n");

// Do something, based on which keys they pressed
if ($key == "1") doRingHousePhones();
elseif ($key == "0") doGoToVoicemail();
elseif ($key == "*") doLoginToVoicemail();
else {
$agi->swift("You didnt pick any options.");
}
$count++;
}

$agi->swift("Goodbye.");
}
[/php]

ircd-hybrid

The IRC server is used for Nagios 3 logging at the moment

Nagios 3 with ircd-hybrid integration

This is the newest addition, and a very sweet setup at that. Nagios 3 is an open source monitoring software. It monitors all of my equipment and servers and the services which are running on them. If CPU gets a little hot, or hard drive starts filling up, or website stops responding, it sends email/SMS notifications, and also sends a color coded notification to #nagios on the IRC server. Nagios uses Apache for the web front end.

General AppleTV tweaks

It turned out that the swap partition that I created was only 25MB or was only showing up as 25MB. This is a problem since this AppleTV only has 256MB of internal RAM. I ended up setting up a loopback swap file which basically allows you to have a ‘file’ on your main partition which will behave as a partition. This 512MB file is mounted as the swap for the system and is working perfectly.

[bash]
dd if=/dev/zero of=swapfile bs=1k seek=512k count=1
mkswap swapfile
losetup -f
losetup /dev/loop0 swapfile
swapon /dev/loop0
[/bash]

You can verify that it worked with either of these:
[bash]
cat /proc/meminfo | grep -i swap
free
[/bash]

Here is a screenshot of ‘top’ running on the AppleTV with all of these services running:

Check out the load average! This machine is simply kickin’ back!

If anyone is interested in more detail how any of these services are configured or if you have any suggestions on what other services should be added to this project, drop me a comment.


Posted

in

by

Tags:

Comments

8 responses to “Tricking out your AppleTV running Linux”

  1. dito Avatar
    dito

    that’s great, I am wondering if this can work as a desktop, can I use firefox or chrome and browse silverlight sites, would that be slow or doable?

  2. emb3dd3d Avatar
    emb3dd3d

    I just used the above links and installed Centos6 desktop to an apple tv… I just wanted to see what it would look like. It appeared to work fine, I was able to log into the desktop. I was using the hdmi cable and never tried the rca jacks or optical connection. Now I am updating to Centos 6.2 and turning off gdm so i can just use it as a server with a dmz dropbox. It was a fun project that I will use in restricted production.

    Great instructions…

    Greets!

  3. Edemir Avatar
    Edemir

    How is the system going? Can you run apache well ? how many connections it will handle???

    Can you install ubuntu 12.04 server ?

    1. Chris Carey Avatar

      Edemir, It’s been a while since I ran this box so I cannot answer those questions at this time. It would not be too difficult to get ubuntu server running as opposed to Debian server. they are quite similar.

      1. Edemir Avatar
        Edemir

        Do you know if a linux distro is faster than the original OS X that is installed in the 1st gen Apple TV for running Mysql, Apache and PHP?

  4. watrix Avatar
    watrix

    Chris, I’m interested to implement nagios3 on my atv2 and I would appreciate our help. I’m able to install lighttpd (apache, mysql and php), but what about the nagios3 engine binaries. How can I build them? nagios3 apt package is not available and neither gcc (to build and compile the source)

    Thanks in advance, wtx

  5. Kim Avatar
    Kim

    Hi Chris, How can I get Netflix over ATV classic?

    1. Chris Carey Avatar

      That machine is not nearly powerful enough to run a Netflix UI.

Leave a Reply to watrix Cancel reply

Your email address will not be published. Required fields are marked *