I realize that the subject by itself seems to limit the interested audience of this post significantly. It took some tweaks to get the UniFi Controller from Ubiquiti working on Arch Linux | ARM though and I wanted to get it out there, if only just for me.

I’m going to presume you already have Arch Linux running on ARM. I used a Raspberry Pi 2, so your packages/mileage may vary if you are following these instructions elsewhere. Your users should have sudo privileges, otherwise you should su and then ignore the sudo part of each command. First, lets install the packages we need:

sudo pacman -S mongodb jdk7-openjdk unzip

These are the only dependencies required for the controller. With that done, you can download and extract the unix zip file from the UniFi Download Page. It will be named something like UniFi vX.X.X Zip for DIY. Mine looked something like this:

wget http://dl.ubnt.com/unifi/4.7.6/UniFi.unix.zip
unzip UniFi.unix.zip
sudo mv UniFi /opt/UniFi

By default, UniFi has a symlink to mongod but we need to add a few options to get mongod to startup through the controller. The reason behind the two additional options is primarily due to the Raspberry Pi 2 being 32-bit and MongoDB having some limitations on it.

cd /opt/UniFi/bin/
cat >mongod
#!/bin/bash

/usr/bin/mongod --journal --storageEngine=mmapv1 "[email protected]"
^D
chmod a+x mongod

You can now create a service to start and stop it. Here is my service file:

cat /lib/systemd/system/unifi.service
[Unit]
Description=unifi
After=local-fs.target remote-fs.target network-online.target
Wants=network-online.target
Conflicts=shutdown.target

[Service]
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
RemainAfterExit=yes
ExecStart=/usr/bin/java -jar /opt/UniFi/lib/ace.jar start
ExecStop=/usr/bin/java -jar /opt/UniFi/lib/ace.jar stop

[Install]
WantedBy=multi-user.target
sudo systemctl daemon-reload
sudo systemctl enable unifi
sudo systemctl start unifi

It may take a few minutes to start up but the web app should eventually be available. I’ve had several restarts with my pi2 and it’s always come up fine. For more information on starting and stopping, you can see the readme.txt file that came with the zip.

There are a couple of things it mentions that the unix version isn’t able to do, namely upgrade and backup. Upgrading basically involves taking a backup, getting the new zip file and overlaying it, and then restoring the backup. I haven’t had to do this yet, but I was interested to know if/when a new version was available. I wrote a small cron job that will mail me from the server. If you want to use it as well, you need to install a few more packages:

sudo pacman -S postfix jq cronie mutt
sudo systemctl restart postfix

Then I created the following script:

#!/bin/bash

curl -s 'https://www.ubnt.com/download/?platform=unifi' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-US,en;q=0.8,nl;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.82 Safari/537.36' -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: https://www.ubnt.com/download/unifi/' -H 'X-Requested-With: XMLHttpRequest' -H 'Connection: keep-alive' -H 'If-Modified-Since: Thu, 28 Jan 2016 23:42:54 GMT' -H 'Cache-Control: max-age=0' --compressed | jq '.downloads[] | {name: .name}' | grep Linux | sort > ~/.unifi_new

touch ~/.unifi

DIFF=$(diff ~/.unifi ~/.unifi_new)
if [ "$DIFF" != "" ]; then
		echo "$DIFF" | mutt -s "UniFi Controller Updated" '[INSERT EMAIL HERE]'
		cp ~/.unifi_new ~/.unifi
fi

Simply replace ‘[INSERT EMAIL HERE]’ with your e-mail address. You can then add this to a cron job. My entry looked like:

0 5 * * * /home/jmarsh/bin/unifi.sh

The first run will send you an e-mail because there is no original. Otherwise, you shouldn’t get anything until a new version is out.

Finally, there is the question of making a backup. Because I don’t have a lot of room on my Raspberry Pi 2, I chose not to do a daily backup but instead opted to backup after any major changes to my network. This is how I do it:

sudo systemctl stop unifi
sudo tar -czf unifi-controller-backup-2015-01-29.tar.gz /opt/UniFi/data
sudo systemctl start unifi