Saturday, February 28, 2015

A snappy adventure

Project

My long term objective is to play with networking apps, particularly node.js in the Pi environment.  In order to achieve that I need some sort of Linux OS installed on Pi.

Raspberry Pi comes with various OSs.

The ones caught my eye are Raspbian, and Snappy Ubuntu Core.

In this article I will demonstrate a "hello world" app built on an Ubuntu VM and deployed into a Snappy Ubuntu VM.


For this exercise we won't even need a Raspberry Pi board. We will be simulating app deployment to Snappy Ubuntu Core.

Setup

Note: this is my setup You don't need to match it 100%. Equivalents will do. 
  • A Mac Book Pro.
  • A virtualisation app, I use VMware Fusion. ($AU 61.)
  • Download Ubuntu (free) and create an Ubuntu VM using your virtualisation app.
  • Download an OVA image (free) and create a Snappy Ubuntu Core VM using your virtualisation app.
  • An account in Ask Ubuntu portal (free).

Ubuntu VM


Download

This is where you will develop the snappy app. Installing Ubuntu VM using VMware Fusion is straightforward.

I allocated 30 GB, physical space, and 4 Gb RAM, probably an over-allocation. I just want to make sure swift development performance.

I think defaults would just do fine too.

Take a record of the static IP address of the VM allocated by VMware:
ergun@ubuntu:~$ ip adr show


Snappy Ubuntu Core VM



The above disk image is provided in OVA format. To create the VM using VMware follow these instructions.

After creating the Snappy Ubuntu Core VM, it will boot up. The booting process is slow (ironic if you consider the OS is called 'snappy'). The first message it displays: is "Error: malformed file". Simply ignore it. Later on it will also look like stuck with a message "Started Journal Service". But it is not. Don't panic, just leave it running, wait until it finishes, this may take several minutes.

After the boot process finishes it will ask you user name and password, just type "ubuntu" and "ubuntu" respectively until you see you are on:

ubuntu@localhost:~$

The first thing we need to do is to change the default ssh port from 22 to 8022. For this we need to edit the file /etc/ssh/sshd_config:

This file is read-only. You need to make it writeable first:
ubuntu@localhost:~$ cd /etc/ssh
ubuntu@localhost:/etc/ssh$ sudo chmod 777 sshd_config
ubuntu@localhost:/etc/ssh$ vi sshd_config
Find the line "Port 22" and change it as:
Port 8022
Save and exit. Put back the file into read-only:
ubuntu@localhost:/etc/ssh$ sudo chmod 644 sshd_config
One last bit before we leave the Snappy. Current version of Snappy Ubuntu Core image was shipped with cloud ssh setup. This introduced nasty "connection refused" errors when I attempted to deploy my snappy app. I reported the issue on here at Ask Ubuntu portal.

To fix the ssh setup you need to run these commands:
cd
sudo mv /etc/ssh/sshd_not_to_be_run .
sudo service ssh start

Verify that the ssh service started with:
ubuntu@localhost:~$ sudo service --status-all | grep ssh
 [ + ] ssh

Power-off your snappy than restart afterwards:
ubuntu@localhost:~$ sudo poweroff

Remember, starting snappy will take minutes to complete, so be patient.

Take a record of the static IP address of the Snappy VM allocated by VMware
ubuntu@localhost:~$ ip adr show

Build snappy app, deploy and test


As the last step, we are going to build a "hello world" snappy app on the Ubuntu VM, and deploy it to Snappy VM.

Go to your Ubuntu VM.

Make sure you fixed the ssh setup issue on your Snappy Ubuntu Core VM (See the section above.)

Just follow the instructions given here at Building Snappy Apps for Ubuntu Core.

If all goes well this is what you would see:
ergun@ubuntu:~/snappy-examples/hello-world$ snappy-remote 
        --url=ssh://172.16.187.129:8022 install 
        ./hello-world_1.0.5_all.snap
=======================================================

Installing ./hello-world_1.0.5_all.snap from local environment
ubuntu@172.16.187.129's password: 

ubuntu@172.16.187.129's password: 
WARNING:root:Signature check failed, but installing anyway 
        as requested

Reboot to use the new ubuntu-core.

=======================================================

ubuntu@172.16.187.129's password: 
ergun@ubuntu:~/snappy-examples/hello-world$ 

Go back to your Snappy Ubuntu Core VM and test:
ubuntu@localhost:~$ hello-world.echo
Hello World!
Note that as soon as you run your app for the first time it is auto deployed and added to apps folder:
ubuntu@localhost:~$ ls
apps snappy-bin sshd_not_to_be_run


Raspy Tools

Why Raspberry Pi

It's a lot of fun.

What you need to know

What you need

  • A Raspberry Pi board
  • A computer. A laptop is recommended if you want to move things around. Operating System can be Windows, Mac OS X or flavour of Linux.
  • Raspberry Pi Accessories (*)
  • Patience

(*) Raspberry Pi Accessories


As a minimum you'd need:
  • A multi-comp case
  • A pre-loaded 8GB micro-SD card in an SD-adapter
  • A micro-SD card Reader
  • A power supply designed for your Raspberry Pi board
  • An ethernet network cable

Optionally you may need:
  • An HDMI cable
  • An external HDMI display
  • A USB keyboard
  • A USB mouse
  • A USB power hub

Welcome to Raspy Pi

Hi Stranger

I am a guy addicted to programming. I do programming in my daytime job, as well as during some nights and on most weekends.

This blog is about my latest pursuit, Raspberry Pi projects. I ordered my first Raspberry Pi board yesterday.

On this blog I'll share stuff that I don't want to forget and may be useful to you as well.

Enjoy the ride..

Learning something new could be challenging. You'll need time, patience, and endurance. Be prepared for long nights with no results. Try to see it as an adventure game. Not everything will go according to plan, but in the end persistence pays off. See failures opportunity to learn and have fun.