Reply
New Member
Posts: 10
Registered: ‎05-20-2013
Kudos: 15
Accepted Solution

Java Home Directory Fail Issue on Ubuntu - RESOLVED

[ Edited ]

Java Home Directory Fail Issue on Ubuntu - RESOLVED

 

For those of you who're building your Ubuntu from scratch, you might or might not get this after installing UniFi Controller

*Setting Java Home....fail

 

If that do happen, this might be because since the new Ubuntu, the name of the Java homedir changed according to the CPU architecture used and UniFi is using a hard-coded variable for the Java path in its startup script for some reason. You should change the homedir by editing the init script. (We won't get into much detail about what is init)

 

1. Open the init script

sudo nano /etc/init.d/unifi

 

2. Scroll down with your arrow key, look for a variable called

JAVA_HOME=/usr/lib/jvm/java-6-openjdk

 

3. Add your instance architecture type after that string.

For example, I'm using amd64bit in my instance, the string should become

JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64

DO NOT touch anything else.

 

4. After the edit just enter Ctrl-X and it will ask you wheter it should save or discard the change. We of course want to save it. Press Y, and press ENTER to save it with the same file name. The nano editor will close

 

5. Do this string to restart our UniFi Controller.

sudo service unifi restart

 

6. You suceed when you see

 * Starting Ubiquiti UniFi Controller unifi                              [ OK ]

 

PS: UniFi Controller also install Java ver 7 by default so if you ought to use the newest jave, tou can change 6 to 7 in the init we are editing.

Example :

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

 

You might also want to check

Adopting your Existing APs to set-inform to L3 Controller Address (No Factory Reset - SSH)

UniFi Controller on Different Regions - Layer 3 Amazon AWS

Upgrading or Building Your Own UniFi Controller 3.1.1 in Layer 3 Amazon AWS

 

 

Regards,

JAP


Accepted Solutions
New Member
Posts: 21
Registered: ‎12-18-2011
Kudos: 7
Solutions: 1

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

This solution will give problems, if updating to latest version of Java.

 

As you mentioned, remove the "java-6" file, and replace it - but use this setup below.

 

#JAVA_HOME=/usr/lib/jvm/java-6-openjdk
JAVA_HOME="$( readlink -f "$( which java )" | sed "s:bin/.*$::" )"

 

Johnny

 

View solution in original post


All Replies
New Member
Posts: 1
Registered: ‎06-15-2013

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

You still have to do this on the latest beta.

 

In fact, it updating the beta will break a working installiation. 

New Member
Posts: 21
Registered: ‎12-18-2011
Kudos: 7
Solutions: 1

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

This solution will give problems, if updating to latest version of Java.

 

As you mentioned, remove the "java-6" file, and replace it - but use this setup below.

 

#JAVA_HOME=/usr/lib/jvm/java-6-openjdk
JAVA_HOME="$( readlink -f "$( which java )" | sed "s:bin/.*$::" )"

 

Johnny

 

New Member
Posts: 14
Registered: ‎10-09-2014

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

Thanks Johnny...

That resolved my issues!

Dan

New Member
Posts: 2
Registered: ‎05-28-2015

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

Hey Johnny,

 

I'm new to SSH and I know my problem lies in the Java settings of my Ubuntu instance. Can you "spell out" your setup below?

 

Here is my java version:

 

java -version

java version "1.7.0_79"

OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2)

OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)

 

Here is my unifi script:

 

#!/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="/usr/lib/unifi"

MAINCLASS="com.ubnt.ace.Launcher"

 

PIDFILE="/var/run/${NAME}/${NAME}.pid"

PATH=/bin:/usr/bin:/sbin:/usr/sbin

 

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64

# 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 -Xmx1024M"

 

[ -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

 

 

Member
Posts: 283
Registered: ‎12-28-2014
Kudos: 76
Solutions: 20

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

[ Edited ]

This OP saved my ass today, works like a charm, cheers!

Emerging Member
Posts: 48
Registered: ‎06-25-2015
Kudos: 10

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

Since the scrypt still has this path hard-coded it is simplest solution it make symbolic link

Code: ln -s /usr/lib/jvm/<your java folder>/ /usr/lib/jvm/java-6-openjdk

Example: ln -s /usr/lib/jvm/java-8-oracle/ /usr/lib/jvm/java-6-openjdk

And you don't have to worry about things resting after updates Man Wink

Emerging Member
Posts: 51
Registered: ‎06-17-2016
Kudos: 7

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

Clearly STILL BROKEN AFTER MORE THAN 3 YEARS!!!

 

Having to manually patch the location or modify the /etc/default/unifi is only a temporary workaround, the BUG was clearly not fixed.

 

When JAVA_HOME is not already defined or is not working the proper way to detect it is:

export JAVA_HOME=`type -p javac|xargs readlink -f|xargs dirname|xargs dirname`

 

Please patch the init script!

Member
Posts: 273
Registered: ‎02-10-2015
Kudos: 143
Solutions: 5

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

Patching the detection script to detect other Java versions - also oracle - shouldn't be a problem?

@UBNT-MikeD

Emerging Member
Posts: 51
Registered: ‎06-17-2016
Kudos: 7

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

If anyone is interested I am working on making the the old Ansible playbook for deployment of UniFi service compatible with Debina, Ubuntu too (maybe even others). Once it will work it will be also available on Ansible Galaxy.

 

Check https://github.com/ansiblers/ansiblers.unifi/issues/1 -- Any help would be greatly appreciated, especially if in form of pull requests Man Happy

Member
Posts: 132
Registered: ‎10-31-2016
Kudos: 11
Solutions: 1

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

I found upgrading from 5.2.9 to 5.4.9 that I still had to replace

JAVA_HOME=/usr/lib/jvm/java-7-openjdk-${arch}

with

JAVA_HOME="$( readlink -f "$( which java )" | sed "s:bin/.*$::" )"

 

Highlighted
New Member
Posts: 4
Registered: ‎06-28-2015
Kudos: 6

Re: Java Home Directory Fail Issue on Ubuntu - RESOLVED

Tested on Ubuntu 16.04:

Create /etc/default/unifi with:

JAVA_HOME="$( readlink -f "$( which java )" | sed "s:bin/.*$::" )"

As the contents.

 

Hopefully I won't have to deal with this again.

Reply