OpenNMS doesn't start with systemd after installing on Ubuntu/Debian

Problem

You have installed OpenNMS Horizon on a Debian/Ubuntu system. Initializing the database was successful, OpenJDK 11 JDK is installed and was set with runjava -s. Starting OpenNMS with systemctl start opennms fails. This is a current issue documented in NMS-10693.

Diagnosis

Run journalctl -u opennms to get the error output of the service. You will see the following output:

root@ubuntu:~# journalctl -u opennms
-- Logs begin at Wed 2018-12-12 11:30:32 UTC, end at Fri 2019-05-10 09:52:52 UTC. --
May 10 09:15:03 ubuntu systemd[1]: Starting LSB: OpenNMS - Open Source Network Management System...
May 10 09:15:03 ubuntu opennms[14709]: $JAVA_HOME is not set.  Set it in /etc/default/opennms or run `/usr/share/opennms/bin/runjava -s` to autoconfigure.
May 10 09:15:03 ubuntu systemd[1]: opennms.service: Control process exited, code=exited status=1
May 10 09:15:03 ubuntu systemd[1]: opennms.service: Failed with result 'exit-code'.
May 10 09:15:03 ubuntu systemd[1]: Failed to start LSB: OpenNMS - Open Source Network Management System.

Rerunning /usr/share/opennms/bin/runjava -s doesn’t solve the problem.

Solution

The init script reads the JAVA_HOME variable from /etc/default/opennms and ignores the Java configuration from /usr/share/opennms/etc/java.conf. To get the service started, set the JAVA_HOME variable in /etc/default/opennms as the following:

# Get the Java configuration set by runjava -s
cat /usr/share/opennms/etc/java.conf
/usr/lib/jvm/java-11-openjdk-amd64/bin/java

Set the JAVA_HOME path in /etc/default/opennms as the following:

echo "JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64" >> /etc/default/opennms

Start the service with systemctl start opennms.