Google App Engine – goapp: ‘C:\Program’ is not recognized as an internal or external command

Today (24/07/2014) I installed the Google Apps components from the Google SDK installer. However when I try to run my goapps application with the command: ‘goapp serve myapp/’

I am receiving an error: ‘C:\Program’ is not recognized as an internal or external command. The problem here is that the ‘goapp.bat’ file tries to access an executable file in the ‘C:\Program Files\Google\Cloud SDK\…’ folder. Because Windows is (still) super terrible at handling spaces in folder names in scripts, it fails.

The solution is to go to the ‘C:\Program Files\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine’ folder and edit the ‘goapp.bat’ file.
At the bottom of the file you will see:

:: Note that %* can not be used with shift.
%GOROOT%\bin\%EXENAME% %1 %2 %3 %4 %5 %6 %7 %8 %9

Now add some quotes to this last line and your problem should be fixed.

:: Note that %* can not be used with shift.
"%GOROOT%\bin\%EXENAME%" %1 %2 %3 %4 %5 %6 %7 %8 %9

Once these changes are saved, go to the ‘C:\Program Files\Google\Cloud SDK\google-cloud-sdk\bin\’ folder. There’s ‘goapp.cmd’ file that gets added to the Windows path. Rename this file to ‘goapp.bck’ and copy your ‘goapp.bat file’.
In this last file change the last line again to:

:: Note that %* can not be used with shift.
"%GOROOT%\..\..\platform\google_appengine\goapp" %1 %2 %3 %4 %5 %6 %7 %8 %9

That’s it. Ugly, but it works…

Original Github issue: windows 7 C:/Program Files/… #688

Read More

NAS – Part 6: Health checks mdadm

Introduction

This post builds on part 2: NAS – Part 2: Software and services. It’s a detection script to see if your RAID is failing. In the past I’ve had my fair share of failed RAID configurations.

I do know the package mdadm can send alerts, however this small script which can be extended to detect specific changes in RAID/system configuration without using the built in reporting.

Implementation

First let’s start by installing mailutils. This package is needed

sudo apt-get install mailutils

Next up is the ‘ssmtp’ package. This package will allow you to send a mail.

sudo apt-get install ssmtp

Create the ssmtp directory (if it doesn’t exists).

sudo mkdir /etc/ssmtp/

And create an ssmtp.conf file.

sudo nano /etc/ssmtp/ssmtp.conf

This ssmtp.conf requires a username(author) and password(authpass). Also a mail hub (smtp, example: mailhub=smtp.gmail.com:587)

AuthUser=<your-email-adres>
AuthPass=<password>
FromLineOverride=YES
mailhub=<smtp-mailserver>
UseSTARTTLS=YES

To test your configuration you can try to send a test mail. Just change ‘email@mail.com’ to your email adress.

echo "This is a test" | mail -s "Test" email@mail.com

If everything works you are ready to create your cron job script. (I will create this script in my user directory, however you can create this wherever you want.)

cd ~
nano health-mdstat.sh

The underscore of ‘cat /proc/mdstat’ is used by mdadm to notify you of any failing RAID disks. So I’ll be checking for this character.

#!/bin/bash
SUBJECT="---RAID IN DEGRADED STATE---"
EMAIL="<target email>"
FROM="<from email>"
EMAILMESSAGE="/tmp/cron-email"
 
cat /proc/mdstat > /tmp/cron-email
 
if grep -q "_" "$EMAILMESSAGE"; then
   mail -aFrom:$FROM -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
fi

Let’s assign execute rights to our script.

sudo chmod +x ./health-mdstat.sh

That’s it! Now assign this to a cron job. I assigned my cron job to run daily.
Also happy scripting (when extending this script).

Read More

NAS – Part 5: Afraid.org DNS

Introduction

The final step to my NAS is keeping my dynamic IP bound to a DNS host. I am using http://afraid.org/ to manage and handle the dynamic DNS.

This script is adapted and based on th script found at: http://adambuchanan.me/post/25473551700/dynamic-dns-with-bash-afraid-org.

Script

This following script will change all hosts assigned to your account to the current IP you are running this script from.

#!/bin/bash
 
#insert SHA-1 hash here (format): username|password
hash=""
 
info_url="http://freedns.afraid.org/api/?action=getdyndns&sha=$hash"
 
echo "Calling $info_url ..."
 
ip=$(dig @208.67.222.220 myip.opendns.com | grep "myip.opendns.com." | grep "0" | awk '{ print $5} ')
echo "Current IP is: $ip"
 
# get the current dns settings...
for each in `curl -s "$info_url"`
do
        domain=`echo "$each" | cut -d"|" -f1`
        dns_ip=`echo "$each" | cut -d"|" -f2`
 
        update_url=`echo "$each" | cut -d"|" -f3`
 
        echo "$domain ..."
        if [ "$ip" != "$dns_ip" ]
        then
                echo "Updating $dns_ip =>$ip ..."
                curl "$update_url" >> log
        fi
        echo "OK"
done

Now run this with a job in crontab to update your afraid.org DNS.

crontab -e

Read More

Windows 3.11 with qemu-kvm – Part 1: Xubuntu

Introduction

For my little Windows 3.11 PaaS system I fell on a dead track with VirtualBox. So I’ve been researching another way to virtualize Windows 3.11 and I found qemu. Below is my little take at emulating Windows 3.11.

Installing qemu-kvm

Installing is pretty easy, just grab all needed packages. I am using the package ‘virt-manager’ as a GUI frontend.

sudo apt-get install qemu qemu-kvm libvirt-bin bridge-utils virt-manager

Next up is to add your current user to the correct groups. This ensures that your virtual machines can be run with your current user.

sudo adduser `id -un` libvirtd
sudo adduser `id -un` kvm

Now to check if everything is ok run virsh. This should return an empty list of virtual machines.

virsh -c qemu:///system list

If you get following error, then you need to change the permissions of your ‘libvirt-sock’ file.

error: failed to connect to the hypervisor
error: Failed to connect socket to '/var/run/libvirt/libvirt-sock': Permission denied
sudo chown legacy:libvirtd /var/run/libvirt/libvirt-sock

Next up is create a virtual machine. For this part I will be using Windows 3.11. However you could use any operating system.

Before we can start creating the virtual machine, I like to create my virtual disks myself. In my template I am using a C:\ drive of 100MB for the system and a data disk of 200MB.

qemu-img create -f qcow2 ~/qemu/template/boot.img 100M
qemu-img create -f qcow2 ~/qemu/template/data.img 200M

Next up, go to your menu and select the ‘Virtual Machine Manager’. This piece of software is a GUI frontend.
qemu-1

In this frontend GUI press the upper left icon to start the wizard to create a new virtual machine.

Give the virtual machine a name, in my case: TEMPLATE. And select ‘Local install media’.
qemu-2

Both types I’ll leave as ‘Generic’. Also select the install image. My windows 3.11 source is an ISO file.
qemu-3

Select the amount of memory and CPU. In the virtual machine manager there is a little bug that won’t allow you to assign less than 50MB. But this shouldn’t be a problem, we’ll fix this later. As for CPU, use one.
et/wp-content/uploads/2014/05/qemu-4.png”>qemu-4

Press the ‘Select managed…’ option here and navigate to the disks you’ve made with the ‘qemu-img’ command. The type will be wrong (raw) but we will fix this later too.
qemu-5

Last step of the wizard. Here by default the hypervisor will be ‘kvm’. My recent findings have found this to cause some stability issues with Windows 3.11. Select qemu instead. As architecture select i686. This is your default 32-bit architecture.
qemu-6

So that’s it. Create the image and let’s continue. Once your virtual machine is created select the blue ‘i’ button to edit the machine a little bit further.

Press the ‘Memory’ tab and assign 32MB. 32 should be enough for Windows 3.11.
qemu-11

Next go to ‘Boot options’ and activate floppy and hard drive. The floppy should go first before we boot from hard drive.
qemu-12

Once this is done, fix your disk one. Select ‘qcow2′ as type and make sure the disk bus is ‘IDE’.
qemu-13

After this assign the second hard drive. Press the ‘Add hardware button’ below and select ‘Storage’. From this menu assign the existing image as disk two.
qemu-14

Last step is the floppy drive. Add a new storage drive and select floppy from the dropdown list and press Finish.
qemu-15

That’s it now your virtual machine is configured to run.

Installing Windows 3.11 / MS-DOS

Next step would be to install the operating system. From the settings page you can connect and disconnect floppies to install your operating system. Press the ‘Disconnect’ button to disconnect the floppy image and press ‘Connect’ to reconnect an image.
qemu-22

Here we go, one fresh MS-DOS 6.22 install.
qemu-21

I won’t explain the other details of installing Windows 3.11, as this post will only cover qemu-kvm. However a little hint: you will need the tools listed on http://www.scampers.org/steve/vmware/

Managing with virtsh

Managing a running virtual machine is very easy. The tool to use for this is called ‘virsh’.

To suspend a machine use ‘virsh suspend’ followed by your virtual machine name. (In my case ‘TEMPLATE’). A suspend will keep your machine in RAM. However it won’t be using any other system resources (except disk space).

virsh suspend TEMPLATE

To resume a suspended state, use ‘resume’.

virsh resume TEMPLATE

To fully dump your running virtual machine use save. This will create an image file of your running config and will unload any RAM assigned to this machine.

virsh save TEMPLATE ~/qemu/template/suspend

First time you will need to change the rights of your suspend image as by default it will be owned by ‘root’. If you try to resume a suspended machine owned by root you will get a permission denied error.

sudo chown `id -un` ~/qemu/template/suspend

To resume a saved virtual machine you can use the ‘restore’ command followed by your image file.

virsh restore ~/qemu/template/suspend

To view the stats of your virtual machine you can use following command:

virsh -c qemu:///system list

It will show the state of your machines. A machine which has been saved to disk won’t show up in this table though.

 Id    Name                           State
----------------------------------------------------
 23    TEMPLATE                       running

More information about managing your virtual machine with virsh can be found at: http://www.centos.org/docs/5/html/5.2/Virtualization/chap-Virtualization-Managing_guests_with_virsh.html

Changing media with virsh

To view all your media assigned to an image you can use the ‘domblklist’ command.

virsh domblklist TEMPLATE

This will output a table showing you the assigned disks.

Target     Source
------------------------------------------------
hda        /home/legacy/qemu/template/boot.img
hdb        /home/legacy/qemu/template/data.img
hdc        /home/legacy/qemu/resources/windows.iso
fda        /dev/sdb

Example: to change the floppy with the command line use ‘change-media’. First disconnect the floppy drive.

virsh change-media TEMPLATE fda --eject

Verify that it has been disconnected.

virsh domblklist TEMPLATE
Target     Source
------------------------------------------------
hda        /home/legacy/qemu/template/boot.img
hdb        /home/legacy/qemu/template/data.img
hdc        /home/legacy/qemu/resources/windows.iso
fda        -

Now insert a new floppy image.

virsh change-media TEMPLATE fda ~/qemu/resources/tools.img --insert

There we go, the floppy is now usable in the virtual machine.

virsh domblklist TEMPLATE
Target     Source
------------------------------------------------
hda        /home/legacy/qemu/template/boot.img
hdb        /home/legacy/qemu/template/data.img
hdc        /home/legacy/qemu/resources/windows.iso
fda        /home/legacy/qemu/resources/tools.img

This example used a floppy image, however it is also possible to swap out disk drives and CD-ROM drives too.

That’s about it for the Xubuntu part. Next topic will probably cover this in an AWS – Amazon EC2 instance.

Read More

NAS – unstable C2750D4I

When configuring my NAS I noticed that the ASrock C2750D4I behaves rather sloppy. Uptime never reached more than 24 hours.
Online I can find other people who are experiencing the same issues with this board: http://forums.tweaktown.com/asrock/56730-c2750d4i-stability-problems-2.html

This is how I made it stable (been running 7 days now without reboots)

NIC drivers

A quick glance at the Intel website shows an update for the NIC:
https://downloadcenter.intel.com/SearchResult.aspx?lang=eng&ProductFamily=Ethernet+Components&ProductLine=Ethernet+Controllers&ProductProduct=Intel%C2%AE+Ethernet+Controller+I210+Series
Let’s install it:

cd ~
wget http://downloadmirror.intel.com/13663/eng/igb-5.1.2.tar.gz
tar xvf igb-5.1.2.tar.gz
cd ~/igb-5.1.2/src
sudo make install

Edit the modules file and add ‘igb’.

sudo nano /etc/modules
igb

Let’s check if it loads.

sudo modprobe igb

Reboot the machine and verify if the new drivers are loaded.

sudo reboot
modinfo igb

Output:

filename:       /lib/modules/3.13.0-24-generic/kernel/drivers/net/igb/igb.ko
version:        5.1.2
license:        GPL
description:    Intel(R) Gigabit Ethernet Network Driver
author:         Intel Corporation, 

Last step cleanup the files.

sudo rm -rf ~/igb-5.1.2
sudo rm ~/igb-5.1.2.tar.gz

Disable Intel Speedstep

Disable your Intel Speedstep and C-Bit in the BIOS. The manual states that Intel Speedstep could ‘make your system unstable’. On this board, yes it does.

SATA cables + Boot disk to Intel controller

The manual recommended the use of the Intel RAID controller for OS disks. (Which I didn’t) So I swapped the SATA cable with a more expensive one (found some postings of people reporting e better stability using better SATA cables), and moved the boot disk to the Intel SATA controller.

These steps solved my instability with this board. Whilst on paper this board is the most awesome buy you could do (passive cooled, 12 SATA ports, quad core Atom, 20 Watt). In reality it’s as picky as a spoiled toddler. Definitely a not buy. At the price of ~€350 this is quite an expensive pain in the ass.

However, is there a comparable product?

Read More

AWS – Using Amazon as frontend for your home server

Introduction

Owncloud is pretty awesome, it provides me with my files everywhere I want on the world. However sometimes accessing my files is rather trivial. Think in terms of hotel lobbies, public access points. Sometimes there are some real restrictions on ports being used. By default my ISP blocks all server traffic below 1024, which is in my opinion a rather rude. I want my files! Luckily we can use the Amazon t1.micro (free tier) to provide a solution to this.

Preparing the Amazon image

So select a free tier Amazon t1.micro. This should be free the first year so no worries. As for configuration. Open the SSL and HTTPS port. Once this instance is running login to the instance as ‘ec2-user’ with your certificate file.

Installing HAProxy

Before we can compile we need to install the build tools.

sudo yum install -y make gcc openssl-devel pcre-devel pcre-static

Now download HAProxy and build it.

cd ~
wget http://haproxy.1wt.eu/download/1.5/src/devel/haproxy-1.5-dev24.tar.gz
tar -xzf haproxy-1.5-dev24.tar.gz
cd haproxy-1.5-dev24
 
make clean
make USE_OPENSSL=1 TARGET=linux26 USE_STATIC_PCRE=1
sudo make install

By default HAProxy is installed in the /usr/local folder, create a logical link or change the variable from the make.

sudo ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy

Because we installed from source, there is no service script. So let’s create one.

sudo nano /etc/init.d/haproxy
#!/bin/sh
#
# haproxy
#
# chkconfig:   - 85 15
# description:  HAProxy is a free, very fast and reliable solution \
#               offering high availability, load balancing, and \
#               proxying for TCP and  HTTP-based applications
# processname: haproxy
# config:      /etc/haproxy/haproxy.cfg
# pidfile:     /var/run/haproxy.pid
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
 
exec="/usr/sbin/haproxy"
prog=$(basename $exec)
 
[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
 
lockfile=/var/lock/subsys/haproxy
 
check() {
    $exec -c -V -f /etc/$prog/$prog.cfg
}
 
start() {
    $exec -c -q -f /etc/$prog/$prog.cfg
    if [ $? -ne 0 ]; then
        echo "Errors in configuration file, check with $prog check."
        return 1
    fi
 
    echo -n $"Starting $prog: "
    # start it up here, usually something like "daemon $exec"
    daemon $exec -D -f /etc/$prog/$prog.cfg -p /var/run/$prog.pid
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}
 
stop() {
    echo -n $"Stopping $prog: "
    # stop it here, often "killproc $prog"
    killproc $prog
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile
    return $retval
}
 
restart() {
    $exec -c -q -f /etc/$prog/$prog.cfg
    if [ $? -ne 0 ]; then
        echo "Errors in configuration file, check with $prog check."
        return 1
    fi
    stop
    start
}
 
reload() {
    $exec -c -q -f /etc/$prog/$prog.cfg
    if [ $? -ne 0 ]; then
        echo "Errors in configuration file, check with $prog check."
        return 1
    fi
    echo -n $"Reloading $prog: "
    $exec -D -f /etc/$prog/$prog.cfg -p /var/run/$prog.pid -sf $(cat /var/run/$prog.pid)
    retval=$?
    echo
    return $retval
}
 
force_reload() {
    restart
}
 
fdr_status() {
    status $prog
}
 
case "$1" in
    start|stop|restart|reload)
        $1
        ;;
    force-reload)
        force_reload
        ;;
    check)
        check
        ;;
    status)
        fdr_status
        ;;
    condrestart|try-restart)
        [ ! -f $lockfile ] || restart
        ;;
    *)
        echo $"Usage: $0 {start|stop|status|restart|try-restart|reload|force-reload}"
        exit 2
esac

And assign execute rights.

sudo chmod +x /etc/init.d/haproxy

Configuration of HAProxy

now to configure HAProxy create the config file.

sudo mkdir -p /etc/haproxy
sudo nano /etc/haproxy/haproxy.cfg

To forward an HTTPS port use the mode TCP. This example forwards from the IP 255.255.255.255 (example). It proxifies (or tunnels) port 22443 to 443 and 22222 to 2222.

global
       daemon
       maxconn 10000
 
defaults
       timeout connect 500s
       timeout client 5000s
       timeout server 1h
 
frontend https_proxy
        mode tcp
        bind *:443
        default_backend https_servers
 
frontend ssh_proxy
        bind *:2222
        mode tcp
        default_backend ssh_servers
 
backend ssh_servers
        mode tcp
        server ssh 255.255.255.255:22222
 
backend https_servers
        mode tcp
        server server1 255.255.255.255:22443

This should do it. Your SSH and HTTPS connection are routed trough Amazon.

As for Owncloud (version 6.x), you will need to add your domain (example: ec2-255-255-255-255.eu-west-1.compute.amazonaws.com) to the config/config.php file:

  'trusted_domains' =>
  array (
    0 => '...........',
  ),

Read More

NAS – Part 4: Owncloud

Introduction

Owncloud is simply amazing. It’s like a Dropbox at home.
For my NAS I will be running this program in an instance in a virtual machine. This is done because I’ll be opening this machine to the outside of the world. Also it’s much easier to backup and dispose.

The VMWare instance

Let’s start with configuring the VMWare instance. I’ll be using the Ubuntu LTS server edition for this instance, as it uses less system resources than a full desktop environment.

Configure the VMWare instance according to the following specifications:
- CPU: 2 virtual CPU’s (1 thread each)
- RAM: 512 MB
- Disk: 6GB
- Operating System: Ubuntu 14.04 LTS

Whilst installing I used ‘automatic updates’ so I don’t have to manage this VMWare instance and I also installed OpenSSH server during the install procedure.

Installing Owncloud

Start by installing all needed packages and dependencies for Owncloud. Also enable the Apache2 headers and rewrite module.

sudo apt-get install apache2 php5 php5-gd php-xml-parser php5-intl php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl php5-json php-apc
sudo a2enmod rewrite
sudo a2enmod headers
sudo service apache2 restart

Installing Owncloud is quite easy, just download the package, extract and fire up a web browser.

cd ~
wget http://download.owncloud.org/community/owncloud-6.0.0a.tar.bz2
tar -xjvf owncloud-6.0.0a.tar.bz2
sudo cp -r owncloud /var/www/
rm -rf ~/owncloud
rm -rf ~/owncloud-6.0.0a.tar.bz2

Fix all rights in the ‘/var/www’ folder:

sudo chown -R www-data:www-data /var/www/

That’s about it, now you can follow the http:///owncloud link and configure your Owncloud. You will need a MySQL database for this application.

Optional: Moving Owncloud to RAID1 share

I prefer to move my data and Owncloud to a network share which is backed by a RAID1 configuration. In case one of my automatic updates shits the server.

Create a mount point for your data. I’ll be using \\192.168.1.10\owncloud as share. The username will be ‘www-data’. As Apache2 uses this username to read and write.
Create the account on the host system and create the share directory.

sudo smbpasswd -a www-data
 
sudo mkdir -p /media/raid1/owncloud
sudo chown -R www-data:www-data /media/raid1/owncloud/

Add the share to samba.

sudo nano /etc/samba/smb.conf
[owncloud]
comment = Raid 1 secure backup storage
path = /media/raid1/owncloud
valid users = www-data
public = no
browseable = no
writable = yes

On the Owncloud instance install the ‘cifs-utils’ package.

sudo apt-get install cifs-utils

Create the folder to mount and mount the network share.

sudo mkdir -p /mnt/network/tmp
sudo mount -t cifs -o user=www-data,password=password //192.168.1.10/owncloud /mnt/network/tmp

Test your share and move all data.

sudo mv /var/www/owncloud/* /mnt/network/tmp/

Now for the fstab file, create a credentials file.

sudo nano /home/owncloud/.cloudcredentials

Add the username and password to the credentials file.

username=www-data
password=password

Restrict access to this credentials file.

sudo chmod 600 /home/owncloud/.cloudcredentials

Add the mount to the ‘/etc/fstab’ file.

sudo nano /etc/fstab
//192.168.1.10/owncloud /var/www/owncloud cifs credentials=/home/owncloud/.cloudcredentials,iocharset=utf8,sec=ntlm 0 0 

That’s it, happy file synchronizing.

Read More

LegacyNET – Introduction

Introduction

Just an introduction to one of my side projects.

One late evening I decided to get creative for a while. So I came up with the design for a semi-PaaS Windows 3.11 system.
Why?
- Because it’s fun. I’ve always loved legacy systems because of their simplicity. Simplicity which allows me to grasp the history of complex current generation systems. The main purpose would be to see if I can meld old technology together with new technology.
- It hasn’t been done before. At least not that I know of. And if I wanted to create an up-to-date system/design which would serve a business purpose, I would prefer to get paid for doing this. This is my spare time.
- Gaming. You have to admit it, old-school games are fun. Anyone can download and install a DosBox and play Warcraft 2 games offline. However netplay on a server would be awesome.

Design

This is the initial design I’ve had in mind, it lacks quite a lot of advanced features. The goal is to use as much out of the box components as possible. I don’t want to write my own servers or other components as this will take a huge amount of time and will likely not scale at all.

LegacyNET

Front-end (http://legacy.enira.net)

This front-end GUI utilizes a regular HTTP/Apache2 web server to serve a graphical interface for users to:
a) Manage their account and credentials
b) Manage ‘friendly nodes’ which allow inter access network
c) Manage system messages and messages between users
d) Manage their virtual instance (reset/start/stop)

RDP gateway

This gateway is an Amazon EC2 instance (t1.micro) configured with HAProxy to proxy RDP connections to each instance and shield the node server from other external traffic. Each instance will receive an RDP port 3500 + n to connect.

Node 0

The actual physical system. In my case this will be an old Dell XPS M1530 which should provide enough resources for the initial setup.
Each VirtualBox instance will be configured with (based on a template):
- 32 MB RAM
- 100 MB of system storage (drive C:)
- 200 MB of user storage (drive D:)
- 800 x 640 resolution RDP connection
- Private IP address 192.168.x.100 + n connected trough an internet gateway (192.168.x.1)
- Windows 3.11 with networking capacities

A reset of an instance wipes drive C: (and repairs it from the template) but should keep all data on the D: drive.

Node Manager

Installed on each node, this manager allows JSON calls between the front-end component and physical state of the system. It will allow the GUI to send messages concerning:
a) System utilization
b) Instance management

Communication between node and front-end should be done using HTTPS and will utilize Apache2 to server HTTPS traffic.

Feasibility study

Study 1: RDP connection

Goal: Complete an RDP connection trough the internet and see if the performance of the RDP connection is enough for a Windows 3.11 instance running at 800×640. This RDP connection should use the VirtualBox RDP capabilities (found in the extra bundle).
Level: Critical
Status: Completed
Results: All objectives have been met.

Study 2: Clone template with VirtualBox

Goal: This test should create and maintain a new instance created from a previous Windows 3.11 instance (called template).
Level: Critical
Status: Ongoing

Study 3: Separate hosts on virtual LAN segment

Goal: This feasibility study should test if there is no traffic possible between each host configured in an internal networking mode. Preferably by using iptables and/ or Coyote Linux for routing network traffic.
Level: High
Status: Ongoing

Final notes

This system is far from perfect, and a lot of work needs to be done. I still need to confirm two feasibility statuses. If study 2 fails, this project will be scrapped.
This a project which is done entirely in my spare time the release date will be when it’s done.

Read More

NAS – Part 3: Mediacenter setup

Indroduction

In part two I’ve discussed the basic services for my NAS. This post will discuss the building of a media center. At the time of writing there are two dominant media players: Plex and XBMC. For my NAS I’ll be using Plex. See: http://www.maximumpc.com/article/features/xbmc_vs_plex2013

Plex

First service up is Plex. Plex needs the component ‘avahi-daemon’. Normally this should be installed on your system. For those who don’t have it:

sudo apt-get install avahi-daemon

Next install Plex. Check for any updates on the Plex website: https://plex.tv/downloads and download the Plex Debian package.

cd ~/Downloads 
wget -c http://downloads.plexapp.com/plex-media-server/0.9.9.7.429-f80a8d6/plexmediaserver_0.9.9.7.429-f80a8d6_amd64.deb
sudo dpkg -i plexmediaserver_0.9.9.7.429-f80a8d6_amd64.deb

That’s it, now login to your plex environment with http://:32400/manage. You alse need to have a Plex account but once you do you can add libraries to your Plex server. I recommend the Ouya Plex client or RasPlex to connect.

Sickbeard

Almost finished now, for my series I like to use Sickbeard. It’s an awesome tool that manages to capture meta data for series. It shows the quality of your series on your home NAS and the completeness.

Before we can start with Sickbeard, you need the ‘python-cheetah’ module. This module is needed by Sickbeard.

sudo apt-get install python-cheetah

Let’s download the tarball (yet again, I don’t like Git for installations).

cd ~/Downloads
wget --no-check-certificate https://github.com/midgetspy/Sick-Beard/tarball/master
tar -xzvf master

Once everything is unpacked, create a directory to run Sickbeard and move your files to it. The number ‘f64b94f’ could be different in your installation. (Depends on Git check-ins)

mkdir ~/SickBeard
mv /home/nas/Downloads/midgetspy-Sick-Beard-f64b94f/* /home/nas/SickBeard/

Now test the install by running the Sickbeard python script.

cd /home/nas/SickBeard/
python SickBeard.py

If Sickbeard launches without a problem, then you can add it to the startup of your server.

Autostarting is fairly easy. Just copy the ‘init.ubuntu’ file form the Sickbeard directory.

sudo cp ~/SickBeard/init.ubuntu /etc/init.d/sickbeard
sudo chmod +x /etc/init.d/sickbeard
sudo update-rc.d sickbeard defaults

This startup script needs to know which user it can run as and also the directory. These variables need to be added to the ‘/etc/default/sickbeard’ file.

sudo nano /etc/default/sickbeard
SB_USER=nas
SB_HOME=/home/nas/SickBeard
SB_DATA=/home/nas/SickBeard/sickbeard_data
SB_PIDFILE=/home/nas/SickBeard/pid

Now we can start the Sickbeard service.

sudo service sickbeard start

Sickbeard runs at http://:8080, from there you can configure your Sickbeard installation.

Transmission

Last service up is Transmission. Any good home NAS must have this. It’s the most awesome remote tool to schedule torrents.

By default it should be installed. For those who don’t have it:

sudo apt-get install transmission

To start Transmission I created a startup script that allows me to run this service once. As with the RDP environment there is a chance that Transmission gets started twice due to the session creation in RDP. A simple hack is to create a script that avoids this.

sudo mkdir -p /home/nas/Scripts/start
sudo nano ~/Scripts/start/runonce.sh
#!/bin/sh
 
for var in "$@"
do
        SERVICE="$SERVICE $var"
done
 
RESULT=`ps -aux | grep -i ${SERVICE} | grep -v grep | grep -v /bin/sh`
 
echo Result: $RESULT
 
if [ "${RESULT:-null}" = null ]; then
        echo "not running... starting $SERVICE"
        $SERVICE
else
        echo "running"
fi

And add ‘transmission-gtk’ to the XFCE session:

/home/nas/Scripts/start/runonce.sh /usr/bin/transmission-gtk

So that’s about it for part two. Next parts will handle Owncloud and Subsonic.

Read More

NAS – Part 2: Software and services

Introduction

Requirements: for the backup data I will be using a partimage file.

The OS of my nas will be Xubuntu 14.04. This distro is fairly lightweight for a NAS system and gives me a sleek GUI interface. I could do without a GUI but this makes some of the services quite ‘Spartan’ to handle. A NAS is not a production environment. I want to handle sudden events, light, swift and simple. There’s no real point in debugging your NAS at 11:00 PM in a command line interface when you need to go to work at 5:00 AM in the morning.

For detailed instructions about how to install Xubuntu I’d like to refer you to Google:
The only thing that needs to be changed in the installation is login by default. This is a must, if you want to config services which will run at boot time with a GUI, you’ll need an active session to start these programs.

Let’s start with the basics (in case you didn’t download the latest updates while installing):

sudo apt-get update
sudo apt-get upgrade

Installing remote access (OpenSSH, XRDP)

Start by installing openssh, this will be the backbone of our communication with the NAS server.

sudo apt-get install ssh

By default the openSSH deamon times out, I don’t really like this so I’ll be adding a ServerAliveInterval.

sudo nano /etc/ssh/ssh_config

And add following line to it:

ServerAliveInterval 60

Next, I chose Xubuntu for a reason, I want to have XRDP installed. Scarygliders has a neat install tool which works for all *untu distro’s. I really recommend you use this file. It will take quite some time and is as slow as a snail but it works. It works flawless.
Note: It should work for all Ubuntu based distributions, however for Lubuntu and Bhodi it doesn’t seem to work very well. Xubuntu gave me a near perfect XRDP session.

I don’t like to have git installed on this system so I’ll just grab the master.zip and unzip it.

cd ~/Downloads
wget https://github.com/scarygliders/X11RDP-o-Matic/archive/master.zip
unzip master.zip

Once these files are unzipped run the rdp script with the command ‘–justdoit’. This will install, build and configure everything. Pretty neat, no?

cd ~/Downloads/X11RDP-o-Matic-master/
sudo ./X11rdp-o-matic.sh --justdoit

Once this is done configure your sessions. It’s fairly easy, run the following command and select your user.

sudo ./RDPsesconfig.sh

Optional: If you, like me, have another keyboard layout instead of the regular US_en then follow these steps:
(WARNING: these commands can only be runned in your X environment, and not trough ssh)

Login to your environment and set X keyboard settings:

setxkbmap be

Now dump this keymap to a local file and dump it to the km-409.ini file of XRDP. This file is the default for all sessions. It’s a sloppy solution but it works.

xrdp-genkeymap ~/keymap.ini
 
sudo mv /etc/xrdp/km-0409.ini /etc/xrdp/km-0409.ini.bak
sudo mv ~/keymap.ini /etc/xrdp/km-0409.ini

Restart and try.

sudo /etc/init.d/xrdp restart

Migrating data from old drive

This part assumes you took a backup from the old drive with partimage. If you don’t have any data to migrate, you can skip this test.

First install partimage to be able to restore the data.

sudo apt-get install partimage

Next grab the block size of the partition you wish to restore. You can find this one by using fdisk and dividing the resulting size by 1024. Add some extra blocks as this result isn’t 100% exact. In my case the old backup disk was /dev/sdh1.

sudo fdisk -l /dev/sdh1

Next create an empty image file with the disk size found in the previous step.

dd if=/dev/zero of=restore.img bs=1024 count=31719727

Associate this empty disk image with a loopback device (loop0).

sudo losetup /dev/loop0 restore.img

Now you can restore the image with partimage. In my case my backup image is called ‘image.000′ and resides on a disk mounted on: ‘/media/nas/05885c86-ae41-4839-b0dc-f1282c59dea4′

sudo partimage restore /dev/loop0 /media/nas/05885c86-ae41-4839-b0dc-f1282c59dea4/image.000

Once everything is restored you can create a mount point and mount the loop0 device. This will give you access to individual backup files.

sudo mkdir /media/nas/backup
sudo mount /dev/loop0 /media/nas/backup

When you are done don’t forget to disconnect the loopback device and delete your .img file.

losetup -d /dev/loop0

Installing LAMP stack (Apache2, PHP & MySQL)

sudo apt-get install php5 libapache2-mod-php5 php5-cgi php5-cli php5-common php5-curl php5-gd php5-mysql php5-pgsql mysql-server mysql-common mysql-client

Migrating MySQL data (optional)

Sometimes it’s not possible to have a MySQL dump available. Lucky all data can be migrated from an old installation. In this example the disk is mounted on ‘/media/nas/backup/’. If you don’t have any old MySQL data to migrate, skip this step.

During this install you will be asked for a root password for the MySQL server.

First stop thye running MySQL server. The installer starts the SQL server by default.

sudo /etc/init.d/mysql stop

Next remove all generated data from the MySQL installation. As we will be replacing all data from a previous installation.

sudo rm -rf /var/lib/mysql/*

You can verify your old database at:

cd /media/nas/backup/var/lib/mysql

If you verified that the backup contains all your old data you can copy the data from the backup to your MySQL installation and reassign the right permissions.

sudo chmod 777 /media/nas/backup/var/lib/mysql
sudo cp -r /media/nas/backup/var/lib/mysql/* /var/lib/mysql
sudo chown mysql:mysql -R /var/lib/mysql
sudo chmod 700 /var/lib/mysql/

Now you database is copied however you still need one file and your MySQL server config. The debian.cnf file was generated by your previous system and is needed by the MySQL deamon.

sudo cp /media/nas/backup/etc/mysql/debian.cnf /etc/mysql/debian.cnf
sudo cp /media/nas/backup/etc/mysql/my.cnf /etc/mysql/my.cnf

All should be done now, you can start the database again.

sudo /etc/init.d/mysql start

To test if everything works you can connect to the instance and check all databases:

mysql -h localhost -u root -p<previously used password>

Oh look my old database schema’s are still there.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| owncloud           |
| performance_schema |
| system_info        |
| test               |
+--------------------+
6 rows in set (0.03 sec)
 
mysql>exit

Migrating Apache2 data

My previous system contained an Apache2 server with some files. I wish to keep these files. If you don’t have anything to migrate you can skip this step.
On Ubuntu systems < 14.04 you can use:

sudo cp -r /media/nas/backup/var/www/* /var/www

As of Xubuntu 14.04 the new Apache2 directory is located at ‘/var/www/html’.

sudo cp -r /media/nas/backup/var/www/* /var/www/html

Repair any rights that might have gotten a little bit wacky.

sudo chown www-data:www-data -R /var/www/*

That’s it, all data should be migrated. (If you’ve kept all your data in the default folders)

Software RAID

This section handles the migration of old mdadm data. For more information about creating a software RAID system see: http://ubuntuforums.org/showthread.php?t=408461

Start by installing the mdadm package.

sudo apt-get install mdadm

Create your mount points for each RAID. I’m using ‘disk_raid1′ and ‘disk_raid5′.

sudo mkdir /media/disk_raid1
sudo mkdir /media/disk_raid5

Now let’s copy over the old mdadm file. This contains the layout of the old RAID.

sudo cp /media/nas/backup/etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf

And reassemble the disks.

sudo mdadm --assemble --scan

This is the result of my reassemble, note that the RAID5 didn’t succeed in recreating. However if your previous system died a clean death it shouldn’t be a real concern.

mdadm: /dev/md/1 has been started with 2 drives.
mdadm: /dev/md/5 assembled from 1 drive - not enough to start the array.
mdadm: /dev/md/5 is already in use.
nas@nas:~$ cat /proc/mdstat
Personalities : [raid1]
md5 : inactive sdd1[3](S) sdg1[1](S) sde1[0](S)
      8790402048 blocks super 1.2
 
md1 : active raid1 sda1[0] sdb1[1]
      976630336 blocks super 1.2 [2/2] [UU]

Before we continue repairing the RAID5 system, verify the drive mappings. This should show you that you are using the correct drives, because if you mess this up your data will be lost!

sudo lshw -short -C disk
H/W path          Device     Class      Description
===================================================
/0/1/0.0.0        /dev/sda   disk       1TB SAMSUNG HD103SI
/0/2/0.0.0        /dev/sdb   disk       1TB SAMSUNG HD103SI
/0/3/0.0.0        /dev/sdc   disk       3TB ST3000DM001-1CH1
/0/4/0.0.0        /dev/sdd   disk       3TB Hitachi HDS5C303
/0/5/0.0.0        /dev/sde   disk       3TB Hitachi HDS5C303
/0/6/0.0.0        /dev/sdf   disk       1500GB SAMSUNG HD154UI
/0/7/0.0.0        /dev/sdg   disk       3TB TOSHIBA DT01ACA3
/0/8/0.0.0        /dev/sdh   disk       60GB KINGSTON SVP200S

Tip: you can also verify the super block existence on each drive by using the following command:

sudo mdadm --examine /dev/sd* | grep -E "(^\/dev|UUID)"

Verify this with the contents of your ‘mdadm.conf’ file and your previous knowledge of your array.

If the data is correct, stop the incorrect RAID5.

sudo mdadm --stop /dev/md5

Force the RAID to recreate using the correct drives, in my case these are sdd1, sdg1 and sde1. (sd[dge]1)

sudo mdadm --assemble --force /dev/md5 /dev/sd[dge]1

The output will look like this:

mdadm: forcing event count in /dev/sde1(0) from 292 upto 302
mdadm: forcing event count in /dev/sdg1(1) from 292 upto 302
mdadm: /dev/md5 has been started with 3 drives.

As you can see aboven there are twe drives which have 10 events less, this shouldn’t be a real problem.

Now your RAID5 will be started, a ‘cat /proc/msdstat’ should show a fresh initialized RAID5.

Personalities : [raid1] [raid6] [raid5] [raid4]
md5 : active raid5 sde1[0] sdd1[3] sdg1[1]
      5860267008 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]
 
md1 : active raid1 sda1[0] sdb1[1]
      976630336 blocks super 1.2 [2/2] [UU]

Last configuration: grab your old mount points and add them again to the fstab file.

cat /media/nas/backup/etc/fstab | grep raid
sudo nano /etc/fstab

And remount.

sudo mount -a

Testing:

df -h
/dev/md1        917G  7,4G  863G   1% /media/disk_raid1
/dev/md5        5,5T  2,6T  2,7T  49% /media/disk_raid5

It works! ‘df -h’ shows the drives mounted.

Samba

Install Samba.

sudo apt-get install samba

If you wish to migrate old shares copy your ‘smb.conf’ file from the backup.

sudo cp /media/nas/backup/etc/samba/smb.conf /etc/samba/smb.conf

Readd any existing users that might have been there. You can verify your ‘smb.conf’ file to see which users have access to a share.

sudo smbpasswd -a foo
sudo /etc/init.d/samba restart

VMWare

For my virtualization needs I prefer VMWare, you could also use VirtualBox of VMWare player. Both serve as a decent solution. A NAS without some virtualization is just a dumb storage brick.

Let’s start by installing the VMWare workstation, following commands needs to run on the server (and not trough ssh).
This command will pop up the install wizard.

sudo sh /media/disk_raid1/varia/vmware-install/VMware-Workstation-Full-10.0.0-1295980.x86_64.bundle

The problem with VMWare 10.0.0 and a linux kernel 3.13 is that it just won’t work. As Xubuntu 14.04 uses this kernel, this system also suffers from this error. A patch can be found at:
Below is the content of the page (In case it vanishes):

nano ~/vmnet313.patch
205a206
> #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
206a208,210
> #else
> VNetFilterHookFn(const struct nf_hook_ops *ops,        // IN:
> #endif
255c259,263
<    transmit = (hooknum == VMW_NF_INET_POST_ROUTING);
---
>    #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 13, 0)
>       transmit = (hooknum == VMW_NF_INET_POST_ROUTING);
>    #else
>       transmit = (ops->hooknum == VMW_NF_INET_POST_ROUTING);
>    #endif
#Change directory into the vmware module source directory
cd /usr/lib/vmware/modules/source
# untar the vmnet modules
tar -xvf vmnet.tar
#run a the patch you should have just saved earlier
patch vmnet-only/filter.c < ~/vmnet313.patch
# re-tar the modules
tar -uvf vmnet.tar vmnet-only
#delete the previous working directory
rm -r vmnet-only
# run the vmware module build program. (alternatively just run the GUI app)
/usr/lib/vmware/bin/vmware-modconfig --console --install-all

Next install the WSX bundle. This will allow access to the VMWare machines trough a modern browser using HTML5.

sudo sh /media/disk_raid1/varia/vmware-install/VMware-WSX-1.0-754035.x86_64.bundle

This component uses Python 2.6, any other version won’t work. So we need to add python alongside the newer Python versions.

sudo add-apt-repository ppa:fkrull/deadsnakes
sudo apt-get update
sudo apt-get install python2.6 python2.6-dev

Now you can start the WSX server.

sudo /etc/init.d/vmware-wsx-server start

 

Tip: When running VMWare images on a CPU which allows you to scale the frequency then your clock might get a little bit off if you don’t install the VMWare tools.
A little workaround to this is to add this to your cron jobs. (My example BE, Brussels NTP server Telenet)

sudo crontab -e
00 1 * * * ntpdate ntp.telenet.be

There you go, one fresh NAS server ready to serve your content and configured to add more scalable services.

Read More