Home Media Server — pi armbian stuck due to missing removable drive

So, I setup few SBCs (Raspberry Pi, Orange Pi) as mini-servers for many kind of purpose at home. One of them is a media-server, it is plugged into multiple removable drives (few USB sticks and one 3TB self-powered seagate 3.5″ enclosure).

I setup the drive to auto-mount on boot using fstab.

One day, because I use one of the USB stick, it stopped working. It seems that the system check and wait for the missing drive (since it’s declared explicitly on fstab)

UUID=XXXX-XXXX / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1
tmpfs /tmp tmpfs defaults,nosuid 0 0
/var/swap none swap sw 0 0
UUID="XXXX-XXXX" /mnt/usb auto user,umask=000,utf80 0
UUID="XXXX-XXXX" /mnt/hdd exfat defaults,auto,umask=000,users,rw 0 0

The fix is to add nofail option to your fstab entry. Refer to man systemd.mount

With nofail, this mount will be only wanted, not required, by local-fs.target or remote-fs.target. This 
means that the boot will continue even if this mount point is not mounted successfully.

So my fstab entry modified into:

UUID=XXXX-XXXX / ext4 defaults,noatime,nodiratime,commit=600,errors=remount-ro 0 1
tmpfs /tmp tmpfs defaults,nosuid 0 0
/var/swap none swap sw 0 0
UUID="XXXX-XXXX" /mnt/usb auto user,umask=000,utf80,nofail 0
UUID="XXXX-XXXX" /mnt/hdd exfat defaults,auto,umask=000,users,rw,nofail 0 0

Now I can freely remove the removable drive without causing boot to stuck.

WordPress from PHP to HHVM

This blog was using nginx+php5.5+mysql and I’ve been reading about hhvm and it`s 100% compability with WordPress.

So it’s worth to test.

OK, what I was doing is basically installing hhvm using this guide

sudo apt-get install software-properties-common
sudo apt-key add --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0x5a16e7281be7a449
sudo add-apt-repository 'deb http://dl.hhvm.com/ubuntu trusty main'
sudo apt-get update
sudo apt-get install hhvm

Since hhvm is also fastcgi compatible, all I do is changing my nginx sites configuration to

location ~ \.(hh|php)$ {
    fastcgi_keep_conn on;
    fastcgi_index  index.php;
    fastcgi_param  $SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;

Restart hhvm and restart nginx to make sure the configuration got reloaded. And done!

Home Automation By Presence Detection

Some friends asking me about my Homebred setup for my home automation – It’s been a while since I promise to write about it – so here you go. (will open the code as soon as I can make it readable for public and clean it up from my custom setups)

The setup is simple, nothing fancy.

It’s using tricky simple presence detection – a.k.a detecting MAC address of my phone and trigger scripts based on that. The weakness of it that it will need DDWRT router use other router that list connected clients MAC address, but you will need to adjust the scrapper code to login and scrap your router interface)

Presence Detection

Install DDWRT on your router. Make sure the setting to expose info page


After this is enabled. It will expose Info.htm that you can use to scrap for information about your router. See the Wireless clients table on the bottom of the Info.htm page


Create daemon that check DDWRT status page on some interval and check for the existence of specific MACs. If some specific MACs is detected, go to a folder and run all scripts.

The Presence Script

The daemon itself is a Nodejs script that run on my Raspberry Pi. It run using cron on some certain interval.

I use Nodejs script for easy development effort :). For request Nodejs have Request and for scrapping it have Cheerio that makes all scrapping needs as easy as creating jQuery selector. For the DDWRT info page.

var request = require('request'); 
var cheerio = require('cheerio');
request('', function (error, response, body) { 
    if (!error && response.statusCode == 200) { 
        var $ = cheerio.load(body); 
        var clients = $('#wireless_table tr'); 
        // loop for clients - do the necessary MAC detection here. Don't forget to save it to external flag file so you can create event 
        // `onEnter`, `onExit` etc 
        // I save list of MACs that need to be checked in a simple JSON file 

When the above script detect an event, it will try to list all executable script in a folder – For example I have /opt/MYMACADDRESS/enter.d/ and /opt/MYMACADRESS/exit.d/ so when my MAC is detected as entering, it will executes all executable scripts in /opt/MYMACADRESS/enter.d/*

In Nodejs, it’s as easy as

//  loop for scripts and execute it using the code below
child = exec(scriptFileName, function (error, stdout, stderr) { 
    console.log('stdout: ' + stdout); 
    console.log('stderr: ' + stderr); 
    if (error !== null) { 
       console.log('exec error: ' + error); 

So I can create many scripts using shebang notation in the folder and those will be executed accordingly.


The scripts are fine tuned to my home setup. But it can be anything. Here’s some Ideas

  1. Set transmission torrent client to unlimited /usr/bin/transmission-remote -D && /usr/bin/transmission-remote -U (when I am at work)
  2. Set transmission to 0kb/sec /usr/bin/transmission-remote -d 0 && /usr/bin/transmission-remote -u 0 (when I am at home)
  3. Bash script that update Dynamic DNS provider with my new IP – It used to twit my public IP to a protected twitter account 🙂
  4. Twit to the protected twitter account if some specific MACs is entering my wifi network
  5. Turn on Air Conditioner by accessing IR arduino trough raspberry GPIO
  6. Wake On Lan my gaming PC by utility called powerwake powerwake

Non DDWRT Router

Well the idea can be applied to other router interface. Most router use basic authentication to access the internal web application. In Nodejs it’s as easy as (or use basic auth bearer Token)

request.get('').auth('username', 'password', false);

And then tweak your scrapper accordingly to harvest for MAC address or static IPs.