Between reality and cyberspace
Roll your own video-on-demand server with vlc and vodca

Preface: Why?

I like to watch videos when I am getting bored or when I am alone.

We have a bunch of DVDs and even some blurays staying in the shelf here.

But I mostly want to watch them when I am not home: When I am on a business trip, when I visit my relatives, etc.

In all these cases I have some spare time and an internet connection. But not all of the DVDs. Or only some of them. Or I have to carry a disk or usbstick or flash card with me. But usually I don’t want to carry them with me or simply forget them.

So why not put them on my server and stream them from there?


VLC as the streaming server


VLC is a very popular, open source media player - but it is more than just that: I is also capable of acting as a streaming server!

When you want to use it, you can use the HTTP web interface (using the VLM interface) or the telnet interface:

vlc -I telnet

You can log in using “telnet localhost 4212” - the default password is “admin”.

With the following command you can add a new on-demand stream:

new Test enabled input “/path/to/some/file.avi”

You can then access the stream via the url

rtsp://your-server.org:554/Test


The problem

The vlc server is pretty good but there are two downsides:

  1. The HTTP interface is very basic
  2. The streams need to be reconfigured, when the server is stopped (or crashed)


The solution: Vodca

I decided to write a little interface myself: vodca

Vodca is a little interface that allows to add, remove, watch (if you have the vlc-plugin installed you can watch videos directly in your browser) and search your streams. It also allows you to recreate streams after a server restart with one click.

Painless development environments with VirtualBox, vagrant and puppet

Contents

  • The problem - Dev/Prod Parity, multiple development environments and troubles
  • Enter Virtualization - How to solve the problem
  • The solution - Vagrant and Puppet
  • An example scenario - Complete example
  • Sharing your VM - Distributing VMs between developers and deployment to the production environment


The problem

As a developer you may need to work on multiple customer projects over time.

This introduces the problem of having to set up a multitude of different development environments: You need different tools, libraries, servers, configurations - sometimes this can get really nasty for instance when it comes down to running a specific version of a library or tool, which conflicts with other tools running on your system.

Aside of that, there is the aspect of disc space: You can’t always throw away such a local development environment when the first version of the project is launched. What if the customer wants changes? What if there are bugs that have to be fixed? What if we need that environment to demonstrate or evaluate something with it?

Thus, these environments start to pile up and clutter your system.



Enter: Virtualization

Nowadays system virtualization is easy. You can choose between Vmware, Xen, KVM, VirtualBox, HyperVisor et. al. to find the easiest and most suitable solution for your virtualization needs. But still: These machines have to be kept somewhere - and you have to copy around large files, including the box-configuratons, the virtual disk images - or large ova-packages.

This is where Vagrant and Puppet jump in - and they’re free!



The solution

Imagine this: Someone creates a virtual machine with everything on board, the project needs. This way you can start testing by just starting the VM - and he can package this in a few small and structured config files and send these around in seconds. Some smart tools then recreate the VM to be just the same as the original. Additionally you can tear down VMs with a single command and build them up to be completely the same with another command.


That sounds cool, right? No more sending around large VM-images



An example scenario: LAMP stack with a web project

Imagine you have a git repository with a project leveraging PHP and MySQL in your company and you are now asked to fix a few issues on that project.

The Vagrant box for this should include everything that is necessary to run PHPUnit and the LAMP-Stack, hosting the web project.

After having installed Vagrant you need to add the first basebox like that:

vagrant box add base http://files.vagrantup.com/lucid32.box

Baseboxes are the basis for creating new Boxes. The box mentioned above will set up a Ubuntu Lucid 32-bit VM to start with. You can find different base boxes at vagrantbox.es 

Let’s create our VM!

Vagrant

You start by creating an new directory and initialize Vagrant. We will make the two directories called “manifests” and “configs” to house config files and puppet manifests:

mkdir lamp-project && mkdir lamp-project/configs && mkdir lamp-project/manifests

cd lamp-project

vagrant init

That was simple. Okay - now we want to setup some portforwarding to access the website from the host plus we make the first step towards Puppet. Put the following to the Vagrantfile:

config.vm.box = “lucid32”

config.vm.provision :puppet do |puppet|

    puppet.manifests_path = File.expand_path(“../manifests”, __FILE__)

end 

config.vm.forward_port 80, 8080

config.vm.share_folder “configs”, “/configs”, File.expand_path(“../configs”, __FILE__)

This way, the port 80 from the VM is forwarded to Port 8080 on the host.

On the last line (config.vm.share_folder) we make our configs/ folder be mounted as /configs in the guest VM.

The “config.vm.provision” line sets up Puppet for provisioning.

Nice and fine - but how do we use Puppet and for what?

Puppet

Puppet is a provisioning system, that allows you to automatically setup and configure a system to fit your needs. To tell Puppet how to set up the system it uses Manifests.


Lets create our first basic manifest by creating a manifests/default.pp with the following contents:

$config_path = “/configs”

$vagrant_base_path = “/vagrant”

Exec { path => “/bin:/usr/bin:/usr/local/bin” }

group { “puppet”: ensure => present }

exec { “apt-get update”: command => “apt-get update” }

class apache {

    file { “/etc/apache2/sites-enabled/000-default”:

        ensure => file,

        source => “${config_path}/000-default”,

        before => Service[“apache2”],

    }

    exec { “enable-mod_rewrite”:

        require => Package[“apache2”],

        before => Service[“apache2”],

        command => “/usr/sbin/a2enmod rewrite”

    }

    package { “apache2”:

        ensure => present,

        before => File[“/etc/apache2/sites-enabled/000-default”],

    }


    service { “apache2”:

        ensure => running,

        require => Package[“apache2”]

    }

}

class php {

    package { “libapache2-mod-php5”: ensure => present }

    package { “php5”: ensure => present }

    package { “php5-cli”: ensure => present }

    package { “php5-dev”: ensure => present }

    package { “php5-mysql”: ensure => present }

    package { “php-pear”: ensure => present }

    exec { “pear upgrade”:

        command => “/usr/bin/pear upgrade”,

require => Package[“php-pear”],

    }

}

class mysql {

  package { “mysql-server”:

    require => Exec[“apt-get update”],

    ensure => present,

  }

  service { “mysql”:

    enable => true,

    ensure => running,

    require => Package[“mysql-server”],

  }

  exec { “Set MySQL server root password”:

        require => Package[“mysql-server”],

        unless => “/usr/bin/mysqladmin -uroot -proot status”,

        command => “/usr/bin/mysqladmin -uroot password root”,

  }

}

include apache

include php

include mysql

This manifest is used by Vagrant to run puppet on the first start of the VM.

To learn more about Puppet, see the learning guide.

Enjoy the ride

Now it is time to start our VM. Run the command

vagrant up

and watch it happen. When it is finished, visit http://localhost:8080 and enjoy :)

When you need to do something on the VM, you can do “vagrant ssh” to connect to the VM and when you’re finished testing your work, you can do “vagrant halt” to stop it.

One of the big benefits: Whenever you decide to leave the project for a longer period of time, you can do “vagrant destroy” to kill the VM and whenever you need to get back to it, you just run “vagrant up” again and you’re ready to go.



Sharing your VM

The last step of this journey is about sharing your work. If you work in a team, it would be great to be abled to push the VM around without having to handle large binary files.

The great news: Sharing your VM is dead-simple: Share the Vagrantfile along with manifests and referenced config files you use and you’re done!

You could also make your VM a base box to be used by others to start from a common ground.

Let’s pretend you’re working in a web development agency and you have some projects requiring Ruby on Rails with RSpec, Sass, Capistrano and some other nifty gems, together with Passenger and Apache. On the other hand you still have to maintain PHP-Projects with a classical LAMP-Stack - these configurations are the same for all the projects - why not create two base boxes for that?

To do this, you just create the two VMs as usual and then export them.

First, you copy your Vagrantfile to Vagrantfile.pkg, then run

vagrant package —vagrantfile Vagrantfile.pkg —include configs,manifests

If you have looked at the tutorial on vagrantup.com you may have noticed the little differences between my Vagrantfile and the Vagrantfile in their example. I made them so that the configs and manifests can be included and properly used and referenced in the packaged box. This way, you do not have to ship around multiple files. Just the box.

I would be glad to hear your thoughts on this topic.

Beanstalkd with CakePHP 2.x

Beanstalkd? What? Why?

When you need to carry out background tasks (e.g. processing a video file, fetching RSS feeds or sending a huge amount of emails) with PHP, it’s usually a good idea to use an independent daemon to do the work.

This way, the user does not have to wait until the task is done and there is no risk of aborting the task because the user leaves or something goes wrong between server and client.

The use of a separate process handling the task brings up the problem of communicating the task between the handling script run by the webserver (taking the request from the user) and the processing script, performing the task with given parameters. For this purpose, there are many different message queue systems: Memcache, AMQ and Beanstalkd.

Setup Beanstalk and the CakePHP Plugin

When you are on a Debian system, you have it simple: 

apt-get install beanstalkd

Then edit /etc/defaults/beanstalkd and run

/etc/init.d/beanstalkd start

And you’re ready.

There are client libraries for a lot of different programming languages and with CakePHP you can take advantage of a plugin, which makes it really simple.

The plugin was originally written for CakePHP 1.x, but there is a fork for 2.x.

To use it, just go to your app/Plugin directory and run

git clone https://github.com/carlipa/cakephp-queue Queue

and edit your bootstrap.php to have the line

 CakePlugin::loadAll(); // Loads all plugins at once

and finally include in your database.php

    public $queue = array(‘datasource’ => ‘Queue.BeanstalkdSource’);

This is not well-documented in the plugin’s README.

The Producer: Beanstalkd in the Controller

The script that should trigger the daemon to do something (i.e. an action in a controller, called by the user visiting a URL) is called the “Producer” from Beanstalkd’s perspective.

To create a job in the Beanstalkd “default” tube have this in your controller:

    public $uses = array(‘SomeModel’, ‘Queue.Job’);

    public $tube = ‘default’;

That allows you to use Beanstalkd on the “default” tube from the controller.

To finally put a Job to the Queue do this:

public function someAction() {

    $this->Job->put(array(

        ‘body’ => array(…)

    ));

… 

This puts the values of “body” into the job in the “default” tube.

The Daemon - A worker

To process the jobs and perform the actual tasks (with the data passed in throught the job’s body) you could for example write your own CakePHP shell. The Shell itself should contain:

public $uses = array(‘Queue.Job’, ‘Repository’, ‘Testdrive’);

public $tubes = array(‘default’);

And to fetch (and delete) the job from the tube:
$job = $this->Job->reserve(array(‘tube’ => $this->tubes));
$this->Job->delete();
All the parameters you passed through “body” in the producing action is now in $job[‘body’] and can be used to do whatever you need.

dstat & sar

iostat, vmstat, ifstat and much more in one.

dstat screenshot

slurm

Visualizes network interface traffic over time.

slurm screenshot

vim & emacs

The real programmers’ editors.

vim screenshot

screen, dtach, tmux, byobu

Keep your terminal sessions alive.

gnu screen screenshot

multitail

See your log files…

NASA Space Apps Challenge Lausanne - C&C CubeSat Project

Abstract

CubeSats are small sats for educational purposes

This weekend the “NASA Space Apps Challenge” took place and I participated at the EPFL, Lausanne to work on a challenge about communicating with multiple CubeSats in space

Our amazing team decided to go all the way from “Satellites throw some bytes on us” to “You can tap a button on your iPad and see temperature curve of Satellite #1 for the last 10 days”. Our Code is on GitHub.


What a weekend!

This weekend, the NASA Space Apps Challenge took place and a few cool guys and I decided to tackle the “New command & control system for CubeSat”-Challenge.

We were participating at the EPFL, Lausanne - a very nice location with a lot of cool people there! We had a lot of fun on Saturday & Sunday and I’ll definitely try to attend next time, too.

Thanks a lot

The organization team surely did a great job and I want to thank all of them! (I can only name a few of you, but you all did a great job, so count this as a big THANK YOU! to every one of you!)

For our project, I would like to give a big thank you to the guys from the Swiss Space Center and Dr. Anton Ivanov for his patience and knowledge. Without him we wouldn’t have had a clue where to find the right specs to talk with CubeSats.

And last but not least: My teammates. You’re awesome guys! Let’s keep up the good work!


The Challenge: Command & Control CubeSats

So our challenge was to create a command & control system for CubeSat satellites.

As Dr. Anton Ivanov from the Swiss Space Center pointed out to us, there is already a solution going from the packetization layer up to the end-user.

That solution is currently capable of talking to a single satellite (currently “Swisscube 1” - call-sign “HB9EG”).

Our task now is to go down one layer and take encapsulated TC-Transfer-Frames (resp. Segments) and assemble them together to TC-Command-Packets again.

Our architecture is built upon 4 components:

  1. A packet-generator generating sample packets and puts them into frames and a library to reassemble packets from some given frames.
  2. An interface to put packets enriched by information about the sending spacecraft and the status of the packet (valid or invalid) into a database
  3. An API-layer to access data from the database as JSON
  4. A client-application for the end-user (for demo purposes)
For the sake of simplicity, the first to steps are both done in the packet generator, but can be easily deferred by using the packet generation functions and the packet reassembling functions separately.

Our result

We put our code on GitHub - more detailed documentation is in the wiki there.

We’ve been chosen as one of the two projects nominated for the global NASA challenge. (This is the other one, if I remember correctly)

The current status is:

  • We have a basic version of the packet generator and the library (currently it only validates frames, but I am currently implementing the other functions [i.e. packet assembling and enrichment for the database).
  • The API-Layer generates dummy data for testing purposes already (see the wiki).
  • The client application exists in static mockups (more and more)


And the T-Shirt goes to…

Thanks to the sponsors (NASA, Swiss Space Center and evolucix - tell me if I missed someone) the two teams nominated for the global challenge got T-Shirts! Yay!

 Perspective

I am not really sure how exactly this will go on - the team stays in touch and we’ll be giving some presentation at the Swiss Space Lab - and are participating at the global challenge. But how exactly this will all will happen is unknown to me now. Stay tuned!

A co-worker (@igama) pointed me at this (it’s a post on his blog) after I had some problems with MacPorts today. It is pretty straight-forward when you follow this article!

Debian Squeeze and Asus eeepc 1001p

Last year I got myself an Asus EEE pc 1001p and wanted to set it up with Debian.

After reading the Debian eee Wiki, I was convinced that it would be an easy task.

Turns out: It wasn’t.

The setup itself was nice and smooth. Setting up WiFi, X11 and fluxbox without any hassle. Then the first reboot.

After a few lines (up to udev, as it turns out) the screen went black.

This made me wonder, if something was wrong with my X11 config. I removed X11. Still: The screen went black.

I tried using “nomodeset” and several vga-modes in the boot command in Grub.

No effect, screen went black.

I also tried the “acpi_os=Linux” hint from the Debian eee Wiki.

Does not work.

The real solution:

Today, by pure incident, I came across the working solution:

acpi_osi=Linux

To have this working, just hit “e” in the Grub menu, go to the “linux …. quiet” line and append the option mentioned above and hit CTRL+X to boot.

You’ll be just fine.

meteor.js chat example

A few days ago, I discovered meteor.js and decided to give it a try.

After reading the Quick start, the “docs” and modifying the Leaderboard example, to get a short dive-in, I found it pretty nice to work with it.

Thats why I decided to write an example on my own - I decided to make a chat example. You can find it on GitHub or try it here.

The only problem I see with meteor.js at the moment is, that the documentation seems to be incomplete and too short in some points. I recommend following the discussions around meteor.js in their IRC channel (#meteor on freenode) to get the best insights.

I guess I’ll give ember.js / knockout.js a try in the next days. 

Montagsmaler - HTML5 / node.js “Draw something” clone

Abstract

I wasn’t happy with the flash-based “Draw my thing” and built my own version with node.js, HTML5 an socket.io and deployed it on nodester. Its open source. You can play it here or on Facebook.

It works on modern browsers and I tested it with Android Opera Mini and the Android browser, too.

Here is the whole story:

First, I got pissed off…

Some weeks ago I came across “Draw my thing” (via the app version “Draw something”). I like it and my girlfriend and I wanted to play it together. When I was on my phone and she was on her laptop, we wanted to start. “Its the same game vendor (OMGPop) and its the same thing. Should work, I guess” way my initial thought. It didn’t. “Draw something” and “Draw my thing” - while being named similarily and utilizing the same game principle, it was not possible to play together using both versions.

“Meh, okay - I just get my laptop and use that.”, I continued. Nevertheless, being flash-based it was pretty slow on my laptop (which is now 4 years old…) and even when trying to play together it was a bad user experience (“Okay, now I’ll send you this game’s link via google talk and then you open it in your browser” “But I am already on OMGpop in the “Draw my thing” screen. Can’t I just get a notification or something?”… and it never really worked to play this game together.

So I rebuild it with HTML5, node.js and socket.io

“Come on, that can’t be THAT hard!” went through my head. And so I started.

I used an HTML5 canvas element, socket.io and node.js for the whole thing.

When the first player connects, she sees “Waiting for other player” until a second player connects. The two then get in the game, they can save and share their drawings and the game ends, when one of the players disconnect.

My experience

It was all so easy and works like a charm. It even works on my Android phone - I just had to write a little wrapper for touch-events.

The server code is 119 lines Javascript (node.js / socket.io), the client-logic is 195 lines javascript and a bit HTML / CSS.

I made this open-source, you can find it on GitHub.

The deployment with nodester was simple, easy and awesome.

Tools and things to make web development much more fun

Web developers nowadays have a lot of possibilities to increase the pace of development and make the process from developing to deploying the app much more fun.

There is a bunch of good IDEs (even web-based ones), there are a lot of cool tools for testing your work and build/deploy management (Selenium, capistrano / capifony / mink / behat / cucumber).

There are countless frameworks for a bunch of different programming languages - some of them well-known, like Ruby on Rails, Sinatra, Groovy, Django, web.py, Plone, Grok,Zend_Framework, Symfony2, CakePHP, Yii, CodeIgniter, Lithium, Spring, JSF, GWT, ASP MVC, DotNetNuke or Wt for C++.

But there are some not widely-known ones, using JavaScript, like SproutCore, ember.js, express.js or - and I will cover it later on in more detail: meteor.js

The essence of this is: Take some time to look around what is out there. It will give you useful insights and inspiration and last, but not least, it gives you some more tools for your toolbox to encounter new problems with new solutions.