Sunday, June 3, 2018

Fix MongoDB incompatibility for Unifi 5.x in Ubuntu 18.04

UPDATE: Step 4 is not needed since UniFi SDN Controller version 5.10.17-11638-1

1. Replace Ubuntu’s MongoDB 3.6 with Community Edition MongoDB 3.4
$ sudo service unifi stop
$ sudo apt uninstall mongodb-server mongo-tools mongodb-clients mongodb-server-core
sudo apt-key adv --keyserver hkp:// --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
$ echo "deb [ arch=amd64 ] xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
$ sudo apt update
$ sudo apt install mongodb-org
2. Enable MongoDB migration option. NOTE: since MongoDB is started by Unifi, we need to start Unifi
$ sudo service unifi start
$ sudo mongo --port 27117
> db.adminCommand( { setFeatureCompatibilityVersion: "3.4" } )
> exit
$ sudo service unifi stop
3. Reinstall Ubuntu’s MongoDB 3.6
$ sudo rm /etc/apt/sources.list.d/mongodb-org-3.4.list
$ sudo apt update
$ sudo apt install mongodb-server
4. Fix Unifi’s MongoDB options incompatibility
$ sudo mv /usr/lib/unifi/bin/mongod /usr/lib/unifi/bin/mongod.bin
$ sudo cat <<'EOF'>>/usr/lib/unifi/bin/mongod
cleaned_args=$(echo $* | sed -e 's/--nohttpinterface//')
exec /usr/lib/unifi/bin/mongod.bin ${cleaned_args}

$ sudo chmod +x /usr/lib/unifi/bin/mongod
5. After the install unifi will break all the packages on the system because they specify a maximum version on mongo. In order to fix that - edit the state of dpkg in /var/lib/dpkg/status: advance to "Package: unifi" and remove the maximum on Mongo-db
6. References

No comments: