Tech Note: Repair Failed Unifi Video NVR on BYOD Linux Servers v2
If you have a Unifi Video Controller (NVR) running on Linux and it has crashed recently, the cause was the update to OpenJDK 8 v282. The previous compatible version was 265, but as soon as the server updated to v282 Unifi Video would fail to run (not just the GUI, the whole controller would fall over).
We were originally able to fix this by removing OpenJDK, installing the latest compabible version available in the repository (which was v162) and version locking the module so it won’t be updated. Unfortunately there’s no longer any version prior to v282 available in the repository, so this method no longer works.
Here’s how to fix it.
(This should go without saying, but just in case, it’s probably best to point this out – before you do anything, make sure you take a full backup of your Unifi Video server before you start messing about with it. That way if you make a mistake you can always roll back to the backup and start again. This should be standard practice for pretty much everything, but sometimes people like to dive in head first without considering all the ramifications. So backup everything first. If you lose someone’s video controller because you made a mistake somewhere and you didn’t bother taking a backup, that’s no one else’s fault. This guide is provided as is in good faith in the hope that it helps others out there, but all responsibility and liability for the health of any systems people attempt to repair as a result of this guide are expressly denied. Back everything up before you start, then you can’t get into trouble.)
First, check your java version by running:
Download the OpenJDK 8 v265 Headless package from a public mirror:
Then install it:
sudo dpkg -i openjdk-8-jre-headless_8u265-b01-0ubuntu2~16.04_amd64.deb
You’ll notice a message saying Java is beind rolled back to the version that we need.
If you check your java version again, you should see it’s now v265:
If you leave things here, the next time you auto-update from the public repository v282 will simply overwrite v265 all over again. So now you need to lock v265 down so it won’t be updated:
echo "openjdk-8-jre-headless:amd64 hold" | sudo dpkg --set-selections
You can then check this has been applied by running:
dpkg --get-selections openjdk-8-jre-headless:amd64It should list the package with the ‘hold’ tag:
All that’s left to do is restart the Unifi-Video service:
service unifi-video stop
service unifi-video start
If you check the service, it should now be running correctly:
service unifi-video status
If it’s still saying the Unifi Video service is failing, there’s something broken. The first thing to try would be to repair it. Glenn’s script can both install the Unifi Video controller from scratch, or repair a damaged installation or dependency in a lot of cases.
From an root session (‘sudo -s’ on Ubuntu) run:
apt-get install wget ca-certificates -y; wget https://get.glennr.nl/unifi-video/install/unifi-video-3.10.13.sh; bash unifi-video-3.10.13.shAfter running through that, check the Unifi-Video service again. If it’s running now, you can browse to the Unifi Video controller login page, and you should be greeted with the prompt again.
If you’re instead seeing this:
… and it seems like Unifi Video can’t move beyond this screen, something within the controller is broken. Usually this happens when the version of the original controller is different and it hasn’t handled the upgrade to the latest release properly. To fix it, you need to completely remove Unifi Video and then reinstall it from scratch. Be careful though – going through this process may delete your configuration, so back that up first.
What’s that? You don’t have a backup of the configuration? Not to worry – browse to /usr/lib/unifi-video/data/backups/ on the Unifi Video server and backup the config file(s) you need (they’re date-stamped, so you should be able to find the most recent one fairly easily).
Now you can remove Unifi Video and its dependencies:
sudo apt-get purge unifi-videoNow run the command provided above for Glenn’s script. Once that’s finished, the service should be running ok and the GUI login page should be accessible. If it appears to have been reset, the cameras aren’t connected and your config is missing, import the configuration backup you made earlier. Hopefully it’s all working now!
You can now update from the repository as normal to keep your server up-to-date without worrying it will break Java again.