30/01/2019

UniFi network controller failed to start

By snorlaxprime

I was helping a friend to fix his UniFi network controller that failed to start. I didn’t know much about it, and we think this is related to the database mongodb which is full with logs of the events which make the size bloated up.

Here are the steps that I did to fix it.

  1. Stop the Unifi Service using the following command
service unifi stop

2. Repair the database with the following command

mongod --dbpath /usr/lib/unifi/data/db --smallfiles --logpath /usr/lib/unifi/logs/server.log --repair

3. Download the pruning script using WGET

wget https://ubnt.zendesk.com/hc/article_attachments/115024095828/mongo_prune_js.js

4. Perform the test run using the following command

mongo --port 27117 < mongo_prune_js.js

5. If the mongo db is not running you might have to run the following command first

sudo mongod --dbpath /usr/lib/unifi/data/db

6. Once the test run is success you will need to edit mongo_prune_js.js to disable “dryrun”, change the line var dryrun=false;

nano mongo_prune_js.js

7. Prune the database by executing the following command, this will take a while to run depends on the size of events that you have. I had about 2 millions events.

mongo --port 27117 < mongo_prune_js.js

8. If all goes well you should see a couple of OK message like the following

{ "ok" : 1}

9. Change the db and log files permission using the following (NOTE : this is an important step)

chown -R unifi:unifi /usr/lib/unifi/data/db/
chown -R unifi:unifi /usr/lib/unifi/logs/server.log

10. Finally start the unifi service using the following

service unifi start

11. if all goes well you should be able to login to the unifi web interface now.