Turning a Raspberry Pi into a UniFi controller appliance en

By ERIKvanPAASSEN on Friday 7 March 2014 00:08 - Comments (68)
Category: UniFi, Views: 109.818





Last updated: 25 september 2014

A few months ago, a hard-float version of the Oracle Java 7 JDK for Raspbian has been released, opening up lots of new opportunities for the Raspberry Pi platform. This blog post will show you how to turn the Pi into a wifi controller appliance for the - almost equally affordable - UniFi access points from Ubquiti, which are becoming increasingly popular.

I'll be using a Raspberry Pi, model B, revision 2.0 which has 512 megabytes of RAM available. Keep in mind that this is just a proof of concept. I have not tested the setup very thoroughly and running the UniFi controller software on Linux is not officially supported, as far as I know. That being said, I haven't ran into any problems yet.

Update 25 september 2014: I'm using the Raspberry Pi to control three UniFi access points for over half a year now and it seems to be rock-solid.

http://tweakers.net/ext/f/qs7hNCPb2zKBY1DHi0Izedxk/full.jpg
Screenshot of the UniFi controller web interface.

Raspbian setup

The first step in the process will be getting your Pi up and running with Raspbian. You can download an image on the Raspberry Pi downloads page. If you don't know how to write the image to your SD card, I'd recommend you to take a look at the wiki page on this topic. After you've flashed Raspbian to the card, it's time to boot up your Pi and log in with username pi and password raspberry.

Raspbian configuration

Now we still need to expand the filesystem to the size of the SD card, so we'll be able to use all the space provided by the card. To do so, run:

sudo raspi-config

Choose Expand Filesystem to adjust the filesystem size. While we're in this neat little configuration tool, you might also want to adjust the amount of RAM assigned to the graphics adapter. You can do so by choosing Advanced Options > Memory split As we're running headless, 4MB would be more than enough. Reboot the device for the changes to take effect.

sudo reboot

Installing the UniFi software and its dependencies

The UniFi software package has two dependencies: Oracle Java, as stated earlier, and MongoDB. The Oracle Java 7 JDK is provided by the 'oracle-java7-jdk' package, which is installed by default on new versions of Raspbian. If you are not sure Java is installed on your device, just tell your package manager to deal with it.

sudo apt-get update && sudo apt-get install oracle-java7-jdk

Now it's time to fulfill the second requirement, MongoDB. Normally, this would be quite a pain since the ARM platform is not supported by it. Fortunately, Per Ola Ingvarsson created a non-x86 version and put it online. Using this guide, you could compile it and move on. But it will take hours and hours on your Raspberry, so I'll be using the lazy approach and just fetch some precompiled binaries from GitHub, thanks to Brice Morin. If you're not experienced with compiling software, I'd recommend you to the same. Create the directory '/opt/mongodb', download the binaries (found in 'mongo/bin' in the GitHub repository) to it and make them executable.

sudo mkdir /opt/mongodb
cd /opt/mongodb
sudo wget https://github.com/brice-morin/ArduPi/blob/master/mongodb-rpi/mongo/bin/bsondump?raw=true -O bsondump
sudo wget https://github.com/brice-morin/ArduPi/blob/master/mongodb-rpi/mongo/bin/mongo?raw=true -O mongo
sudo wget https://github.com/brice-morin/ArduPi/blob/master/mongodb-rpi/mongo/bin/mongod?raw=true -O mongod
sudo wget https://github.com/brice-morin/ArduPi/blob/master/mongodb-rpi/mongo/bin/mongodump?raw=true -O mongodump
sudo chmod +x *

Finally, it's time to download the UniFi software. I'll be using version 2.4.6, which is available from this UniFi update announcement. You'll need to accept a license agreement, so I can't provide you with a direct download link. I downloaded the package on my desktop machine and transferred it to the home directory of the pi user using SFTP. Unzip the package and move the extracted directory into /opt.

unzip UniFi.unix.zip
sudo mv UniFi /opt/UniFi

Next, we'll need to tell the controller software where it can find MongoDB. This is an easy one, as we'll only need to replace a symlink.

cd /opt/UniFi/bin
sudo ln -fs /opt/mongodb/mongod mongod

At last, we're ready to fire up the controller!

sudo java -jar /opt/UniFi/lib/ace.jar start

Or start it in the background by running:

sudo java -jar /opt/UniFi/lib/ace.jar start &

If all went well, you should now be able admire the web interface of your super-awesome UniFi controller appliance through HTTPS on port 8443. To observe the log while the controller is running in the background, use:

sudo tail -f /opt/UniFi/logs/server.log

To stop the controller again:

sudo java -jar /opt/UniFi/lib/ace.jar stop


P.S. You're running server as 'root'. This won't be a good idea for production use, but using a Raspberry Pi for production will probably never be a good idea anyway. However, if you'd set permissions on the 'data' and 'log' subdirs of the UniFi directory, nothing would stop you from running the server as a different user.

Update March 15th, 2014: Running the controller on startup

To run the UniFi controller when the Raspberry boots, we'll need a startup script. Fortunately, there's a Debian package mentioned in the release announcement and this package contains such a script.

By default, the script would assign a memory limit of 1024M to the controller, which I adjusted to 384M. I don't know yet if this would suffice, but it'll be easy to change anyway. I also changed the base dir path and the Java home.

So, create the file /etc/init.d/unifi with the following contents:

code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
#
# /etc/init.d/UniFi -- startup script for Ubiquiti UniFi
#
#
### BEGIN INIT INFO
# Provides:          unifi
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Ubiquiti UniFi
# Description:       Ubiquiti UniFi Controller
### END INIT INFO

NAME="unifi"
DESC="Ubiquiti UniFi Controller"

BASEDIR="/opt/UniFi"
MAINCLASS="com.ubnt.ace.Launcher"

PIDFILE="/var/run/${NAME}/${NAME}.pid"
PATH=/bin:/usr/bin:/sbin:/usr/sbin

JAVA_HOME=/usr/lib/jvm/jdk-7-oracle-armhf
# JSVC - for running java apps as services
JSVC=`which jsvc`
#JSVC_OPTS="-debug"
JSVC_OPTS="${JSVC_OPTS}\
 -home ${JAVA_HOME} \
 -cp /usr/share/java/commons-daemon.jar:${BASEDIR}/lib/ace.jar \
 -pidfile ${PIDFILE} \
 -procname ${NAME} \
 -outfile SYSLOG \
 -errfile SYSLOG \
 -Djava.awt.headless=true -Xmx384M"

[ -f /etc/default/rcS ] && . /etc/default/rcS
. /lib/lsb/init-functions

[ -d /var/run/${NAME} ] || mkdir -p /var/run/${NAME}
cd ${BASEDIR}

is_not_running() {
        start-stop-daemon --test --start --pidfile "${PIDFILE}" \
                --startas "${JAVA_HOME}/bin/java" >/dev/null
        RC=$?
        return ${RC}
}

case "$1" in
        start)
                log_daemon_msg "Starting ${DESC}" "${NAME}"
                if is_not_running; then
                        ${JSVC} ${JSVC_OPTS} ${MAINCLASS} start
                        sleep 1
                        if is_not_running; then
                                log_end_msg 1
                        else
                                log_end_msg 0
                        fi
                else
                        log_progress_msg "(already running)"
                        log_end_msg 1
                fi
        ;;
        stop)
                log_daemon_msg "Stopping ${DESC}" "${NAME}"
                if is_not_running; then
                        log_progress_msg "(not running)"
                else
                        ${JSVC} ${JSVC_OPTS} -stop ${MAINCLASS} stop
                fi
                log_end_msg 0
        ;;
        status)
                status_of_proc -p ${PIDFILE} unifi unifi && exit 0 || exit $?
        ;;
        restart|reload|force-reload)
                if ! is_not_running ; then
                        if which invoke-rc.d >/dev/null 2>&1; then
                                invoke-rc.d ${NAME} stop
                        else
                                /etc/init.d/${NAME} stop
                        fi
                fi
                if which invoke-rc.d >/dev/null 2>&1; then
                        invoke-rc.d ${NAME} start
                else
                        /etc/init.d/${NAME} start
                fi
        ;;
        *)
                log_success_msg "Usage: $0 {start|stop|restart|reload|force-reload}"
                exit 1
        ;;
esac

exit 0


This script uses jsvc, which we'll need to install. Run:
sudo apt-get update && sudo apt-get install jsvc

Enable execution of the script and make it run at boot time:
sudo chmod +x /etc/init.d/unifi
sudo update-rc.d unifi defaults

You can now start your controller using your new script, or just reboot your Pi.
sudo /etc/init.d/unifi start

Follow-up

Jimmy Selgen Nielsen wrote an excellent follow-up tutorial about running the controller under it's own user. It's really worth reading. You can find it here. (Update 28 april 2015: Link has been restored.)

Setting up log rotation should not be necessary, as the UniFi controller has log rotation built in.

You might also want to hang onto this topic in the Ubiquiti forums.

Volgende: Turning a Raspberry Pi into a UniFi controller appliance (UniFi 4, Raspbian Jessie, Oracle Java 8) 12-'15 Turning a Raspberry Pi into a UniFi controller appliance (UniFi 4, Raspbian Jessie, Oracle Java 8)
Volgende: T7 Tweaks Chrome-extensie v1.1 10-'12 T7 Tweaks Chrome-extensie v1.1

Comments


By Tweakers user prein2, Friday 7 March 2014 09:12

interesting, I am looking into buying the Inifiy access points.
what is the benefit of running the controller appliance in your network? I thought the APs would manage everything themselves?

and how about the pi's performance? will it still be able to do other simple tasks, or should one have a dedicated pi for this one?

By Tweakers user ERIKvanPAASSEN, Friday 7 March 2014 20:22

prein2 wrote on Friday 07 March 2014 @ 09:12:
interesting, I am looking into buying the Inifiy access points.
what is the benefit of running the controller appliance in your network? I thought the APs would manage everything themselves?
You'll need the controller software at least once to setup your network and to provision the access points. After it has been set up, you could shut down the controller again while the access points keep working. But you could also keep the controller online to monitor your access points and gather usage statistics. A permanent controller would also be required for some advanced features like captive portals, if I remember correctly.
prein2 wrote on Friday 07 March 2014 @ 09:12:
and how about the pi's performance? will it still be able to do other simple tasks, or should one have a dedicated pi for this one?
I have not tested the setup very well, but the load on the Pi seems rather high while requests to the web service are being made. I'll have to do some additional testing on load and memory usage with multiple access points (I'll be able to test with up to three access points).

By Jimmy Selgen Nielsen, Sunday 9 March 2014 20:01

Excellent tutorial.

I followed, and modified by creating a unifi user, and a rc.d script.
Works well.

I'm not sure that setting the memory split below 16 has any effect, IIRC you _can_ set it lower, but it splits at 16mb anyway.

By Jeff Scott, Saturday 15 March 2014 16:40

Awesome blog post buddy. So good.
But can you explain how to set this to run on startup as a service?

By Tweakers user ERIKvanPAASSEN, Saturday 15 March 2014 20:23

Jimmy Selgen Nielsen wrote on Sunday 09 March 2014 @ 20:01:
Excellent tutorial.

I followed, and modified by creating a unifi user, and a rc.d script.
Works well.

I'm not sure that setting the memory split below 16 has any effect, IIRC you _can_ set it lower, but it splits at 16mb anyway.
Thanks! I didn't know about the minimum amount of RAM used by the GPU, but it would be easy to verify. By default it consumes 64M, which is quite a lot for a headless device. Could you perhaps have a look at the new section about the startup script and see if it needs improvement in some way, please?
Jeff Scott wrote on Saturday 15 March 2014 @ 16:40:
Awesome blog post buddy. So good.
But can you explain how to set this to run on startup as a service?
There already were some requests on the UBNT forums about this too, so I decided to add I a section which explains how to make it run on startup. Good luck with it! :)

By Jimmy Selgen Nielsen, Saturday 15 March 2014 21:32

It looks a lot like what I did - I blogged about it here http://vile.devlix.dk/blo...erry-pi-unifi-controller/

I'll run over my own startup script and perhaps convert it to the one used here.

By Tweakers user ERIKvanPAASSEN, Saturday 15 March 2014 21:49

Jimmy Selgen Nielsen wrote on Saturday 15 March 2014 @ 21:32:
It looks a lot like what I did - I blogged about it here http://vile.devlix.dk/blo...erry-pi-unifi-controller/

I'll run over my own startup script and perhaps convert it to the one used here.
Nice follow-up! I added a link to your blog. :)

By Martin roeting, Sunday 6 April 2014 20:45

Everything is running but can not connect to port 8443 using midori.

Nothings happens no web interface.

Netstat shows ports are listening.

At the end of ace.jar info it shows "db""not connected". and als no logfiles.

By Michael Jensen, Wednesday 9 April 2014 12:09

Thanks for an excellent tutorial

I get an error from the log stating: WARN - discover - DiscoverHandler not initialized yet.

I can't connect to my pi from a browser using https://<pi ip>:8443. I get a timeout when I try.

Any suggestions?

By Jonathan Bjorgen, Thursday 1 May 2014 22:35

Thanks! Great tutorial. Worked perfectly for me. It's up and running and controlling a network plus guest network for a church campus.

Only hiccup I had was that when I restarted the pi, I got a timeout when trying to connect to https://<pi ip>:8443 as mentioned above.

I logged in via ssh and ran
code:
1
sudo service unifi restart

and within a minute or two I could connect just fine. Will have to see if I can figure out why.

By Johan A, Sunday 11 May 2014 17:00

Hi Thanks for this guide

i havve one show stopper so far, i cant fire up the controller, when trying to start, just nothing happens, i just have to restart my ssh connection.

i cant see that the unifi have started at all, but no clear error msg.

what is the problem?

By Tweakers user ERIKvanPAASSEN, Sunday 11 May 2014 17:41

Johan A wrote on Sunday 11 May 2014 @ 17:00:
Hi Thanks for this guide

i havve one show stopper so far, i cant fire up the controller, when trying to start, just nothing happens, i just have to restart my ssh connection.

i cant see that the unifi have started at all, but no clear error msg.

what is the problem?
Could you provide a little more information about? Are you using the start script? What do the log files in /opt/UniFi/logs/ say?

[Comment edited on Sunday 11 May 2014 17:41]



By riccardo capra, Wednesday 21 May 2014 12:01

Hello, and thank you for your grat tuttorial. Everything works fine, but I have a problem when I try to start unifi at startup.

This is the output:

:/# update-rc.d /etc/init.d/unifi defaults
update-rc.d: using dependency based boot sequencing
update-rc.d: error: unable to read /etc/init.d//etc/init.d/unifi

any suggestion?

thanks in advance.

By Tweakers user ERIKvanPAASSEN, Wednesday 21 May 2014 12:42

riccardo capra wrote on Wednesday 21 May 2014 @ 12:01:
Hello, and thank you for your grat tuttorial. Everything works fine, but I have a problem when I try to start unifi at startup.

This is the output:

:/# update-rc.d /etc/init.d/unifi defaults
update-rc.d: using dependency based boot sequencing
update-rc.d: error: unable to read /etc/init.d//etc/init.d/unifi

any suggestion?

thanks in advance.
Hmmm, I guess the command should be:
update-rc.d unifi defaults

I'll update the blog post. Thank you for your remark.

By riccardo capra, Wednesday 21 May 2014 14:15

Nothing to do.

root@raspberrypi:/# update-rc.d unifi defaults
update-rc.d: using dependency based boot sequencing
insserv: warning: script 'mathkernel' missing LSB tags and overrides

By Unflux, Thursday 22 May 2014 09:48

Riccardo,

You should try the following command:
sudo apt-get remove wolfram-engine

Else you could try the following to fix the insserv issue http://www.forum-raspberr...ng-lsb-tags-and-overrides

By Dan, Saturday 28 June 2014 20:22

Great job on this document. The one mistake I made was to make a text file on windows for the init.d config then try and move it over. Once I recreated the file through Vi, worked like a charm.

Thanks for putting this together and how thorough, added a lot of value to my network installation.

By Patrick, Sunday 29 June 2014 20:52

Bravo! Confirmed that all steps work like a charm using Raspian 06-20-2014 and Unifi Controller 2.4.6. Thank you very much for this walkthrough.

Cheers!

By Kowen, Tuesday 9 September 2014 04:51

Hey,

Thanks for the tutorial, I ended up making the controller fine with a few extra tweaks. Check out my blog for my out-of-the box solution:

http://kowenhouston.wordp...14/09/08/unifipi-rev-0-2/


Kowen

By Jeremy, Friday 19 September 2014 20:53

Has anyone tried this with the 'A' 256MB model to see if it will run? I imagine it will just use more swap space and be dog slow; but that's just a guess.

I have an 'A' model laying on the shelf and thought I could put it to use if it would work.

-J

By Tweakers user ERIKvanPAASSEN, Saturday 20 September 2014 16:31

Jeremy wrote on Friday 19 September 2014 @ 20:53:
Has anyone tried this with the 'A' 256MB model to see if it will run? I imagine it will just use more swap space and be dog slow; but that's just a guess.

I have an 'A' model laying on the shelf and thought I could put it to use if it would work.

-J
The model A lacks an ethernet port, so that would be a problem. If you're confusing it with a model B rev. 1.0 with 256MB of RAM, you might give it a shot, though. I think the memory consumption also depends on the number of connected access points.

By Gavin, Monday 22 September 2014 14:00

For those people having trouble getting things to start on port 8443, I noticed there was no keystore on my installation, thus Tomcat not being able to start with SSL. The below fixed this for me.

sudo keytool -genkey -keyalg RSA -alias selfsigned -keystore /opt/UniFi/data/keystore -storepass aircontrolenterprise -validity 365 -keysize 2048 -destalias unifi

You'll need to restart unifi for it to take effect.

By Jeremy, Wednesday 24 September 2014 03:34

ERIKvanPAASSEN wrote on Saturday 20 September 2014 @ 16:31:
[...]

The model A lacks an ethernet port, so that would be a problem. If you're confusing it with a model B rev. 1.0 with 256MB of RAM, you might give it a shot, though. I think the memory consumption also depends on the number of connected access points.
You're right, it is a 'B' after looking it over again. Giving it a try now and installing tonight. Thanks again for the blog here...very,very helpful.

-J

By Jeremy, Wednesday 24 September 2014 05:05

Got it working. Thanks Gavin for the tip on the keygen.

sudo keytool -genkey -keyalg RSA -alias selfsigned -keystore /opt/UniFi/data/keystore -storepass aircontrolenterprise -validity 365 -keysize 2048 -destalias unifi

That was the last piece needed.


It seems to be working ok. Performance isn't that bad with just a couple of APs. Will see how it goes with around 4 APs total.

-J

By Jeremy G, Thursday 16 October 2014 18:44

So I notice that my free memory slowly shrinks away about 6Megs a day.


Started at:
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 122608 28016 208164 0 0 13 14 457 333 6 1 92 0


Several days later
vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 56796 138516 131216 0 0 0 14 3 112 6 1 92 0

Overnight
vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 50472 139796 133724 0 0 0 14 68 43 6 1 93 0


I've had to reboot so I've never let it run down, but I assume I'll eventually eat away at swap space?

I'm wondering if I should have a cronjob to reboot once a week so I don't start eating into my swap space.

thoughts?


-Jeremy

By Tweakers user lostdogs, Sunday 2 November 2014 09:39

I got it to work with 2.4.6. Is it possible to run a newer version? 3.2.1?

By Nelesss, Sunday 2 November 2014 15:38

lostdogs wrote on Sunday 02 November 2014 @ 09:39:
I got it to work with 2.4.6. Is it possible to run a newer version? 3.2.1?
Yes this is possible, I have installed with the latest version 3.2.5. Just go to the website of UniFi and choice the unifi.unix.zip package. https://community.ubnt.co...-is-released/ba-p/1044423

By jorrit, Monday 10 November 2014 21:52

UniFi 3.2.7 up and running. Thnx for the great tutorial!

By Nate, Sunday 23 November 2014 01:25

No such luck getting this to work on 4.2.0 or 4.5.2... It will install and run just fine, until you try to adopt the USG, then it crashes with a memory error (creates a hs_error dump in /opt/UniFi)... and won't run until you turn off the USG, restart the service, then go in and "forget" the USG... then it will run again.

I tried messing with different settings in the -Xmx384M line (500, 450, 400, 256), and couldn't get anything to work... think the 512MB memory cap on the RPi might have reached its limit with the 4.x versions (at least with the initial versions)...

If anyone else was able to get it working, I'd really like to know and can try other suggestions anyone else might have.

4.2.0:
http://community.ubnt.com...-is-released/ba-p/1052757

4.5.2:
http://community.ubnt.com...ease/m-p/1090185#U1090185

By lostdogs, Sunday 23 November 2014 13:20

I have this up and running. Maybe my next question is off topic, but I want to customize the portal. https://community.ubnt.co...customization/ta-p/474293

But I can't find the <unifi_base> mentioned in the article: /usr/lib/unifi

Is that in a different location for this setup?

By lostdogs, Sunday 23 November 2014 13:25

lostdogs wrote on Sunday 23 November 2014 @ 13:20:
I have this up and running. Maybe my next question is off topic, but I want to customize the portal. https://community.ubnt.co...customization/ta-p/474293

But I can't find the <unifi_base> mentioned in the article: /usr/lib/unifi

Is that in a different location for this setup?
Nevermind... /opt/UniFi/

By Tweakers user ERIKvanPAASSEN, Sunday 23 November 2014 13:28

Nate wrote on Sunday 23 November 2014 @ 01:25:
No such luck getting this to work on 4.2.0 or 4.5.2... It will install and run just fine, until you try to adopt the USG, then it crashes with a memory error (creates a hs_error dump in /opt/UniFi)... and won't run until you turn off the USG, restart the service, then go in and "forget" the USG... then it will run again.
That's a shame. I don't have any experience with the 4.x version myself, since I don't use the USG.
lostdogs wrote on Sunday 23 November 2014 @ 13:20:
But I can't find the <unifi_base> mentioned in the article: /usr/lib/unifi
That's where you unzipped UniFi.unix.zip. So if you followed this guide, that would be /opt/UniFi.

By Martin, Tuesday 9 December 2014 14:19

Hi
I did your tutorial step by step, but the controller won't start in the background. All I get when I start the controller in the background i
[1] 2164

There is also no server.log

When I start "normal" I can access the controllers website.

What can I still do to ran the controller in the background?

By Martin, Thursday 11 December 2014 15:37

Martin wrote on Tuesday 09 December 2014 @ 14:19:
Hi
I did your tutorial step by step, but the controller won't start in the background. All I get when I start the controller in the background i
[1] 2164

There is also no server.log

When I start "normal" I can access the controllers website.

What can I still do to ran the controller in the background?
Now it's working. Well, I can access the controllers website, but the controller won't find my AP. Hmm .....

By gary roberts, Sunday 21 December 2014 17:01

Jeremy G wrote on Thursday 16 October 2014 @ 18:44:
So I notice that my free memory slowly shrinks away about 6Megs a day.


Started at:
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 122608 28016 208164 0 0 13 14 457 333 6 1 92 0


Several days later
vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 56796 138516 131216 0 0 0 14 3 112 6 1 92 0

Overnight
vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 50472 139796 133724 0 0 0 14 68 43 6 1 93 0


I've had to reboot so I've never let it run down, but I assume I'll eventually eat away at swap space?

I'm wondering if I should have a cronjob to reboot once a week so I don't start eating into my swap space.

thoughts?


-Jeremy
I notice the same leak on my side, im running 3.2.7

Can anyone comment if this leak is there on 3.2.6 or if they have a working solution to isolate/resolve the leak?

By Jason, Tuesday 30 December 2014 18:06

After typing:
sudo java -jar /opt/UniFi/lib.jar start
it replies
Port 8080 is not available. How do I fix this?

By Tweakers user ERIKvanPAASSEN, Tuesday 30 December 2014 18:31

Jason wrote on Tuesday 30 December 2014 @ 18:06:
After typing:
sudo java -jar /opt/UniFi/lib.jar start
it replies
Port 8080 is not available. How do I fix this?
Two things can be happening here: 1. another application is already using port 8080, or 2. the UniFi controller is already running. I think you should check which process is listening on this port using the 'netstat' command.

However, if you need to change the ports used by the UniFi controller, please refer to the documentation: https://community.ubnt.co...ller-and-UAPs/ta-p/412673

By Tweakers user Ma®tin, Tuesday 30 December 2014 18:33

Nice, works beautifully! :)
Thanks for the howto!

By Jason, Wednesday 31 December 2014 02:14

ERIKvanPAASSEN wrote on Tuesday 30 December 2014 @ 18:31:
[...]

Two things can be happening here: 1. another application is already using port 8080, or 2. the UniFi controller is already running. I think you should check which process is listening on this port using the 'netstat' command.

However, if you need to change the ports used by the UniFi controller, please refer to the documentation: https://community.ubnt.co...ller-and-UAPs/ta-p/412673
The state for the local address 192.168.0.25:8443 is FIN_WAITZ

By Tweakers user Downloader_NL, Friday 2 January 2015 18:39

Hé Erik,

Ik draai de software op mijn PI maar in de browser kom ik niet verder dan het:
Er is een probleem met het beveiligingscertificaat van deze website Na het klikken op de knop om door te gaan blijft de browser maar draaien !

By Tweakers user ERIKvanPAASSEN, Saturday 3 January 2015 16:30

Downloader_NL wrote on Friday 02 January 2015 @ 18:39:
Ik draai de software op mijn PI maar in de browser kom ik niet verder dan het:
Er is een probleem met het beveiligingscertificaat van deze website Na het klikken op de knop om door te gaan blijft de browser maar draaien !
This problem has already been solved through direct communication. Just to be clear: the warning shown by the browser about an untrusted or incorrect SSL certificate is expected behaviour. As long as you don't install a valid and trusted certificate, there's no other option than to ignore this warning.

By Jeffrey, Saturday 3 January 2015 17:51

Hey,

The latest wheezy img has java 8 on board so you have to change rule 25 in script from:

JAVA_HOME=/usr/lib/jvm/jdk-7-oracle-armhf

TO

JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt

It worked for me.

Greetings,

Jeffrey

By Tweakers user ERIKvanPAASSEN, Saturday 3 January 2015 19:21

Jeffrey wrote on Saturday 03 January 2015 @ 17:51:
The latest wheezy img has java 8 on board so you have to change rule 25 in script from:

JAVA_HOME=/usr/lib/jvm/jdk-7-oracle-armhf

TO

JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm-vfp-hflt
Thanks for this valuable feedback, Jeffrey.

By Wilson, Saturday 10 January 2015 17:45

When I press enter after for the line "sudo java -jar /opt/UniFi/lib/ace.jar start", it appears to be loading but nothing happens (almost like it is frozen). When I try to run it in the background it will give me a 1[xxxx] where the x's are random digits. I cannot access the controller either way. Thoughts would be appreciated!

By Tweakers user ERIKvanPAASSEN, Sunday 11 January 2015 15:12

Wilson wrote on Saturday 10 January 2015 @ 17:45:
When I press enter after for the line "sudo java -jar /opt/UniFi/lib/ace.jar start", it appears to be loading but nothing happens (almost like it is frozen). When I try to run it in the background it will give me a 1[xxxx] where the x's are random digits. I cannot access the controller either way. Thoughts would be appreciated!
Is there something in the log file?

[Comment edited on Sunday 11 January 2015 15:12]


By Fernando, Monday 19 January 2015 21:11

Hi Erik,
First thanks for the tutorial. It's great and solve my problem.
I'm managing from home two AP located in a little comunity of hollidays houses in the south os Spain and its running very well.
The only problem I got is that after 4 days since I started the Raspberry with the service (last saturday), I began to receive daily a mail with this error:

/etc/cron.daily/logrotate:
error: error creating output file /opt/UniFi/logs/server.log.1: File exists
run-parts: /etc/cron.daily/logrotate exited with return code 1[/i][/i][/i]

I look for all the information in the logrotate conf file and seems be rigth.

Any sugestion?

Thanks for the help

By Tweakers user ERIKvanPAASSEN, Tuesday 20 January 2015 17:16

Fernando wrote on Monday 19 January 2015 @ 21:11:
The only problem I got is that after 4 days since I started the Raspberry with the service (last saturday), I began to receive daily a mail with this error:

/etc/cron.daily/logrotate:
error: error creating output file /opt/UniFi/logs/server.log.1: File exists
run-parts: /etc/cron.daily/logrotate exited with return code 1[/i][/i][/i]
I don't think you should use logrotate with the UniFi controller software. The software has log rotation functionality built-in. I guess I should update the blog post with this info.

By Matt Brotherson, Monday 2 February 2015 00:44

Thanks for the write-up. I had an initial issue with the symlink to mongod, which the UniFi server log made aware. Perhaps I fat-fingered the creation of it, but removed and redid and working now, running 3.2.7.

Based on the 3.2.7 zip readme, it said that restore wasn't functional, so I scp'd the data directory over from my install on my laptop and everything jives.

Cheers.

By tspinoso, Wednesday 11 February 2015 06:33

Thanks for the write up - I got this up and running on a Pi2. I will throw a couple of UAPs on it and run it for a week or so.

The information from Jeffrey about Java 8 directory is very important and should probably be incorporated or at least called out.

Question - what are the instructions to add this and run as a user other than root?

If there is anything on my PI2 you want me to try to help the cause let me know.

Thanks !

By Jimmy Selgen Nielsen, Tuesday 28 April 2015 17:30

I hit a few bumps in the road with my server (a raspberry pi), meaning that the SD Card died and the hosting provider (PCExtreme) offered to replace it for free, and restore the server.

While i was setting everything up from scratch again, i also switched to another blogging platform.
The UniFi article i wrote is available here https://vile.thoughtcrime...pi-as-a-unifi-controller/

By Tweakers user ERIKvanPAASSEN, Tuesday 28 April 2015 17:51

Jimmy Selgen Nielsen wrote on Tuesday 28 April 2015 @ 17:30:
While i was setting everything up from scratch again, i also switched to another blogging platform.
The UniFi article i wrote is available here https://vile.thoughtcrime...pi-as-a-unifi-controller/
Thanks, I've updated the link in the article.

By Tim Oppenheim, Thursday 30 April 2015 02:46

Hi Erik,
Thanks for this. I have a small problem with space. I have an 8g card and looks like Mongo is taking a third of it. I look through some other threads with this topic, but did not find anything that worked. I have, as far as I can tell, the rotate logs script running, Any ideas?

By Tweakers user ERIKvanPAASSEN, Thursday 30 April 2015 21:21

Tim Oppenheim wrote on Thursday 30 April 2015 @ 02:46:
I have an 8g card and looks like Mongo is taking a third of it. I look through some other threads with this topic, but did not find anything that worked. I have, as far as I can tell, the rotate logs script running, Any ideas?
There's some info in the UBNT knowledge base. Did you try that already?

I don't know exactly how much space the DB supposed is to use, but it may depend on the number of devices. Iirc, I'm using a 16GB sd card myself.

By Tweakers user marineII7, Wednesday 3 June 2015 14:27

ERIKvanPAASSEN wrote on Sunday 11 January 2015 @ 15:12:
[...]

Is there something in the log file?
I have the same issue here. My log directory is empty so i guessing the link with mongodb isnt working. Do i need to start MongoDB somehow? I followed all your steps Erik. Thanks for the tutorial btw :)

(Im trying this with unifi controller 4.6.2)

[Comment edited on Wednesday 3 June 2015 14:29]


By Tweakers user marineII7, Wednesday 3 June 2015 15:37

Martin wrote on Thursday 11 December 2014 @ 15:37:
[...]

Now it's working. Well, I can access the controllers website, but the controller won't find my AP. Hmm .....
what solved your issue? Or was it just a matter of time and patience?

By Tweakers user ERIKvanPAASSEN, Wednesday 3 June 2015 20:33

marineII7 wrote on Wednesday 03 June 2015 @ 14:27:
[...]

I have the same issue here. My log directory is empty so i guessing the link with mongodb isnt working. Do i need to start MongoDB somehow? I followed all your steps Erik. Thanks for the tutorial btw :)

(Im trying this with unifi controller 4.6.2)
I have no experience running version 4.x on a Raspberry Pi. According to some sources on the UBNT forum, it won't run on a RPi v1. To be honest, I'm not sure it's not possible, but currently I don't have the time to sort this out. v4.x should, however, run easily on a RPi v2.

I'm still running v2.4.6, but v3.x should work just as well.

There's no need to start mongod yourself. The UniFi controller will handle this. You only need the binary. Perhaps you could double check the permissions on the mongod binary (make sure it's executable). I'd suggest you start with version v3.x and if that works, try to get v4.6.2 working. You could also try using tools like netstat to figure out what is happening.

By Tweakers user marineII7, Wednesday 3 June 2015 21:15

ERIKvanPAASSEN wrote on Wednesday 03 June 2015 @ 20:33:
[...]

* lots of information *

I'm still running v2.4.6, but v3.x should work just as well.
I'd suggest you start with version v3.x and if that works, try to get v4.6.2 working. You could also try using tools like netstat to figure out what is happening.
Thanks fors the tips Erik! I'll try version 3.x.x tomorrow! if it works i will definitely post it!

Its working! i've installed 3.2.10 with no issue other then i wont run in the background. No issue for me however its dedicated to that job. I even updated it to 4.6.3 and it works flawlessly

[Comment edited on Thursday 4 June 2015 14:59]


By Steven Grimm, Tuesday 30 June 2015 19:20

For what it's worth, the latest Raspbian distro (jessie) has MongoDB. So there's no longer any need to download custom binaries; "apt-get install mongodb" works fine.

By Cas, Sunday 2 August 2015 11:37

This setup worked for me, running 4.6.6 on Wheezy

Downloaded Unifi from:
https://www.ubnt.com/downloads/unifi/4.6.6/UniFi.unix.zip

By Adrian Zaugg, Tuesday 18 August 2015 14:48

The installation can be improved by running the unifi controller process under its own user. For this to work, the start-up script has to be altered and the ownershp of the directories should be changed. I installed in /usr/local/lib/UniFi (and /var/local/lib/UniFi symlinking changeable directories), you do not need that for running the controller under its own user, but I feel this to be more appropriate. Anyway, I rewrite below for /opt/UniFi on the fly, so please forgive me any mistakes...

How to achieve an UniFi Controller installation under a non-priviledged user:
0) prepare: Login as root, install as described above, but do not start the controller (or stop it, if it's running).

1) add a system user unifi:
adduser --system --disabled-login --home /opt/UniFi --shell /bin/false --group unifi

2) change ownership of the unifi directories:
chown -R unifi:unifi /opt/UniFi

3) prepare run directory
cd /opt/UniFi
rm run
ln -s /var/run/unifi run

4) (otional) prepare log directory to be under /var/log
cd /opt/UniFi
if [ -d logs ]; then mv logs /var/local/log/unifi ; else mkdir -p /var/local/log/unifi ; fi
ln -s /var/local/log/unifi logs
cd /var/log
ln -s ../local/log/unifi
chown unifi:unifi /var/local/log/unifi
cd

5) Use the following start script and replace the existing one. Check that the "find java magic" (line after JAVA_HOME) really works, or set it by hand. Use the line "#!/bin/bash" as the first line in the script! This script contains some -XX... java optimization options which are optional to include.

# ---------------------------- snip ----------------------------

#!/bin/bash
#
# /etc/init.d/UniFi -- startup script for Ubiquiti UniFi
#
#
### BEGIN INIT INFO
# Provides: unifi
# Required-Start: $local_fs $remote_fs $network
# Required-Stop: $local_fs $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Ubiquiti UniFi
# Description: Ubiquiti UniFi Controller
### END INIT INFO

NAME="unifi"
DESC="Ubiquiti UniFi Controller"

BASEDIR="/opt/UniFi"
MAINCLASS="com.ubnt.ace.Launcher"

PIDFILE="${BASEDIR}/run/${NAME}.pid"
PATH=/bin:/usr/bin:/sbin:/usr/sbin

JAVA_HOME="$(readlink -m $(dirname $(readlink -mn $(which java))/../../..))"

USER="unifi"

# JSVC - for running java apps as services
JSVC=$(which jsvc)
if [ -z "$JSVC" ]; then
echo "Java Service Controller jsvc not found. Can't load $NAME." >&2
exit 1
fi

#JSVC_OPTS="-debug"
JSVC_OPTS="${JSVC_OPTS}\
-home ${JAVA_HOME} \
-cp "/usr/share/java/commons-daemon.jar:${BASEDIR}/lib/ace.jar" \
-pidfile "${PIDFILE}" \
-procname ${NAME} \
-outfile SYSLOG \
-errfile SYSLOG \
-Djava.awt.headless=true \
-user ${USER} \
-server \
-XX:MaxPermSize=256m \
-XX:+UseCompressedOops \
-XX:+UseFastAccessorMethods \
-XX:+UseFastEmptyMethods \
-XX:+UseConcMarkSweepGC \
-Xmx384M"

[ -f /etc/default/rcS ] && . /etc/default/rcS
. /lib/lsb/init-functions

if [ ! -d "$(readlink -mn "${BASEDIR}/run")" ]; then
mkdir -p "$(readlink -mn "${BASEDIR}/run")"
chown "$USER":"$USER" "$(readlink -mn "${BASEDIR}/run")"
chmod u+rwXs "$(readlink -mn "${BASEDIR}/run")"
fi

cd "${BASEDIR}"

is_not_running() {
start-stop-daemon --test --start --pidfile "${PIDFILE}" \
--startas "${JAVA_HOME}/bin/java" >/dev/null
RC=$?
return ${RC}
}

case "$1" in
start)
log_daemon_msg "Starting ${DESC}" "${NAME}"
if is_not_running; then
${JSVC} ${JSVC_OPTS} ${MAINCLASS} start
sleep 2
if is_not_running; then
log_end_msg 1
else
log_end_msg 0
fi
else
log_progress_msg "(already running)"
log_end_msg 1
fi
;;
stop)
log_daemon_msg "Stopping ${DESC}" "${NAME}"
if is_not_running; then
log_progress_msg "(not running)"
else
${JSVC} ${JSVC_OPTS} -stop ${MAINCLASS} stop
fi
log_end_msg 0
;;
status)
status_of_proc -p ${PIDFILE} unifi unifi && exit 0 || exit $?
;;
restart|reload|force-reload)
if ! is_not_running ; then
if which invoke-rc.d >/dev/null 2>&1; then
invoke-rc.d ${NAME} stop
else
/etc/init.d/${NAME} stop
fi
fi
if which invoke-rc.d >/dev/null 2>&1; then
invoke-rc.d ${NAME} start
else
/etc/init.d/${NAME} start
fi
;;
*)
log_success_msg "Usage: $0 {start|stop|restart|reload|force-reload}"
exit 1
;;
esac

exit 0


# ---------------------------- snip ----------------------------

6) make the startup script executable:
chmod u+x /etc/init.d/unifi

7) start the controller:
service unifi start

8) check and test:
ps -efwww | grep unifi
...should reveal your controller runs as user unifi. Test by connecting to your controller with your web browser.

Best regards, Adrian.

By Unifispot, Thursday 22 October 2015 16:16

Really informative!

How about performance? Any info regarding memory/CPU usage?

By Tweakers user ERIKvanPAASSEN, Friday 23 October 2015 10:58

Unifispot wrote on Thursday 22 October 2015 @ 16:16:
Really informative!

How about performance? Any info regarding memory/CPU usage?
I'm using it with five access points and have no issues at all with performance. Starting the controller takes a bit longer than on a normal server, but no more than 1-2 minutes. After that, no issues at all. CPU usage is 100% while processing requests but almost idle otherways.

By Gerald, Monday 2 November 2015 22:04

Dear all, thx a lot, excellent work!

@Adrian: You specially saved my day! Tried a lot of manuals for running with its own user before - nothing worked so far. Your script ist perfect. Installed and worked with my configuration:
unifi/4.7.6-sp783omb, mongodb v2.1.1-pre-, java version "1.8.0", Raspbian GNU/Linux 7 (wheezy)

By Greg, Sunday 6 December 2015 12:36

Thanks, super helpful guide. Worked like a charm for my RPI v1

By Adrian Zaugg, Friday 18 December 2015 12:52

Because I do not have plenty of space left on my raspi I set up logrotate. Just use the following code and save it as /etc/logrotate.d/unifi

# ---------------------------- snip ----------------------------

# UniFi logs common rotation options

nomissingok
compress
delaycompress
create 640 unifi unifi


# Unifi log
/var/log/unifi/server.log {
daily
notifempty
rotate 8
}

# MongoDB log
/var/log/unifi/mongod.log {
daily
notifempty
rotate 8
}

# ---------------------------- snap ----------------------------

Check the file permissions to be 640. If you haven't set up unifi to save the log files in the right place, you need to adapt the log file path above. See my previous comment on how to save the logs to the right place.

You may check logrotate would work by executing

logrotate -df /etc/logrotate.d/unifi


Regards, Adrian.

By Tweakers user ERIKvanPAASSEN, Tuesday 29 December 2015 22:15

I created an updated version of this tutorial. It's available here.


Comment form
(required)
(required, but will not be displayed)
(optional)

Please enter the code from the image below: