neo4j icon indicating copy to clipboard operation
neo4j copied to clipboard

APT Installation Issues: Could not find or load main class

Open coffeegist opened this issue 3 years ago • 2 comments

apt installation failing to load neo4j

My sincerest apologies if this is not the proper place to report this since it may be an issue with the package and not neo4j's core codebase. It seems as though launching the neo4j service (or the binary at /usr/bin/neo4j directly) doesn't work proeprly, and reports the error Could not find or load main class org.neo4j.server.CommunityEntryPoint

  • Neo4j version: 4.0.12
  • Operating system: Kali Rolling 2021.2
  • openjdk 11.0.11 2021-04-20
  • OpenJDK Runtime Environment (build 11.0.11+9-post-Debian-1)
  • OpenJDK 64-Bit Server VM (build 11.0.11+9-post-Debian-1, mixed mode, sharing)

Expected behavior

Installing neo4j via apt should install in a way that the neo4j service can properly start

Actual behavior:

/usr/bin/neo4j is unable to find it's entrypoint. However /usr/share/neo4j/bin/neo4j loads fine.

Steps to reproduce below

-kali2021.2-# wget -O - https://debian.neo4j.com/neotechnology.gpg.key | sudo apt-key add - 

-kali2021.2-# echo 'deb https://debian.neo4j.com stable 4.0' > /etc/apt/sources.list.d/neo4j.list

-kali2021.2-# sudo apt-get update

-kali2021.2-# apt install neo4j
<snip>

-kali2021.2-# neo4j console
DEBUG: SCRIPT_PATH is "/usr/share/neo4j/bin/neo4j"
Directories in use:
  home:         /var/lib/neo4j
  config:       /etc/neo4j
  logs:         /var/lib/neo4j/logs
  plugins:      /var/lib/neo4j/plugins
  import:       /var/lib/neo4j/import
  data:         /var/lib/neo4j/data
  certificates: /var/lib/neo4j/certificates
  run:          /var/lib/neo4j/run
Starting Neo4j.
WARNING: Max 1024 open files allowed, minimum of 40000 recommended. See the Neo4j manual.
Error: Could not find or load main class org.neo4j.server.CommunityEntryPoint
Caused by: java.lang.ClassNotFoundException: org.neo4j.server.CommunityEntryPoint

-kali2021.2-# which neo4j
/usr/bin/neo4j

-kali2021.2-# neo4j version
Error: Could not find or load main class org.neo4j.server.CommunityEntryPoint
Caused by: java.lang.ClassNotFoundException: org.neo4j.server.CommunityEntryPoint

-kali2021.2-# /usr/share/neo4j/bin/neo4j version
neo4j 4.0.12

-kali2021.2-# java --version
openjdk 11.0.11 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+9-post-Debian-1)
OpenJDK 64-Bit Server VM (build 11.0.11+9-post-Debian-1, mixed mode, sharing)

-kali2021.2-# cat /etc/os-release                                                                                                     1 ⨯
PRETTY_NAME="Kali GNU/Linux Rolling"
NAME="Kali GNU/Linux"
ID=kali
VERSION="2021.2"
VERSION_ID="2021.2"
VERSION_CODENAME="kali-rolling"
ID_LIKE=debian
ANSI_COLOR="1;31"
HOME_URL="https://www.kali.org/"
SUPPORT_URL="https://forums.kali.org/"
BUG_REPORT_URL="https://bugs.kali.org/"

-kali2021.2-# uname -a
Linux kali 5.10.0-kali7-amd64 #1 SMP Debian 5.10.28-1kali1 (2021-04-12) x86_64 GNU/Linux

-kali2021.2-# ls -alh /usr/lib/jvm                                                                                                 
total 16K
drwxr-xr-x   3 root root 4.0K Jun  1  2021 .
drwxr-xr-x 125 root root 4.0K Dec 18 15:47 ..
lrwxrwxrwx   1 root root   25 Jul 17  2019 default-java -> java-1.11.0-openjdk-amd64
lrwxrwxrwx   1 root root   21 Apr 20  2021 java-1.11.0-openjdk-amd64 -> java-11-openjdk-amd64
-rw-r--r--   1 root root 2.0K Apr 20  2021 .java-1.11.0-openjdk-amd64.jinfo
drwxr-xr-x   7 root root 4.0K Jun  1  2021 java-11-openjdk-amd64

coffeegist avatar Dec 18 '21 21:12 coffeegist

I BELIEVE the issue may be the following line in /usr/bin/neo4j

NEO4J_HOME="${NEO4J_HOME:-/var/lib/neo4j}" NEO4J_CONF="${NEO4J_CONF:-/etc/neo4j}" exec "${SCRIPT_PATH}" "$@"

This makes sense for the default to be /var/lib/neo4j, given that the neo4j user is added with a home directory of /var/lib/neo4j as seen in /etc/passwd

# /etc/passwd
<snip>
neo4j:x:998:998::/var/lib/neo4j:/bin/bash

But I believe my NEO4J_HOME should actually be /usr/share/neo4j. See the directory differences below:

Below is a directory comparison

-kali2021.2-# ls -al /var/lib/neo4j          
total 24
drwxr-xr-x  6 neo4j adm  4096 Dec 18 17:11 .
drwxr-xr-x 69 root  root 4096 Dec 18 17:11 ..
drwxr-xr-x  2 neo4j adm  4096 Jun 29 08:46 certificates
drwxr-xr-x  5 neo4j adm  4096 Dec 18 17:11 data
drwxr-xr-x  2 neo4j adm  4096 Jun 29 08:46 import
drwxr-xr-x  2 neo4j adm  4096 Dec 18 17:11 plugins
                                                                                                                                     
-kali2021.2-# ls -al /usr/share/neo4j 
total 44
drwxr-xr-x   7 neo4j adm   4096 Dec 18 17:11 .
drwxr-xr-x 347 root  root 12288 Dec 18 17:11 ..
drwxr-xr-x   3 neo4j adm   4096 Dec 18 17:31 bin
drwxr-xr-x   4 neo4j adm   4096 Dec 18 16:15 data
drwxr-xr-x   2 neo4j adm  12288 Dec 18 17:11 lib
drwxr-xr-x   2 neo4j adm   4096 Dec 18 16:15 logs
drwxr-xr-x   2 neo4j adm   4096 Jun 29 08:46 tools

And it seems that when I remove the NEO4J_HOME environment variable from /usr/bin/neo4j, things start up normally

-kali2021.2-# cat /usr/bin/neo4j 
#!/usr/bin/env bash

NEO4J_BIN=/usr/share/neo4j/bin
SCRIPT_NAME="$(basename "$0")"
SCRIPT_PATH=""${NEO4J_BIN}"/"${SCRIPT_NAME}""

[ -r /etc/default/neo4j ] && . /etc/default/neo4j

# NEO4J_HOME="${NEO4J_HOME:-/var/lib/neo4j}" NEO4J_CONF="${NEO4J_CONF:-/etc/neo4j}" exec "${SCRIPT_PATH}" "$@"
NEO4J_CONF="${NEO4J_CONF:-/etc/neo4j}" exec "${SCRIPT_PATH}" "$@"

-kali2021.2-# neo4j console          
Directories in use:
  home:         /usr/share/neo4j
  config:       /etc/neo4j
  logs:         /usr/share/neo4j/logs
  plugins:      /usr/share/neo4j/plugins
  import:       /usr/share/neo4j/import
  data:         /usr/share/neo4j/data
  certificates: /usr/share/neo4j/certificates
  run:          /usr/share/neo4j/run
Starting Neo4j.
WARNING: Max 1024 open files allowed, minimum of 40000 recommended. See the Neo4j manual.
2021-12-18 22:33:30.233+0000 INFO  ======== Neo4j 4.0.12 ========
2021-12-18 22:33:30.239+0000 INFO  Starting...
^C2021-12-18 22:33:30.472+0000 INFO  Neo4j Server shutdown initiated by request
2021-12-18 22:33:32.875+0000 INFO  Bolt enabled on localhost:7687.
2021-12-18 22:33:32.876+0000 INFO  Started.
2021-12-18 22:33:33.842+0000 INFO  Remote interface available at http://localhost:7474/

coffeegist avatar Dec 18 '21 22:12 coffeegist

As a temporary stop-gap, anyone else running into this issue should do the following to resolve:

  1. Change the neo4j user's home directory (not sure this is required) usermod -d /usr/share/neo4j neo4j

  2. Run systemctl edit neo4j and modify the NEO4J_HOME var. An example can be seen below:

### Editing /etc/systemd/system/neo4j.service.d/override.conf
### Anything between here and the comment below will become the new contents of the file

[Service]
Environment="NEO4J_CONF=/etc/neo4j" "NEO4J_HOME=/usr/share/neo4j"

### Lines below this comment will be discarded

### /lib/systemd/system/neo4j.service
# [Unit]
# Description=Neo4j Graph Database
# After=network-online.target
# Wants=network-online.target
# 
# [Service]
# ExecStart=/usr/share/neo4j/bin/neo4j console
# Restart=on-failure
# User=neo4j
# Group=neo4j
# Environment="NEO4J_CONF=/etc/neo4j" "NEO4J_HOME=/var/lib/neo4j"
# LimitNOFILE=60000
# TimeoutSec=120
# 
# [Install]
# WantedBy=multi-user.target 
  1. You may also need to run systemctl daemon-reload to force the new settings

Of course, I would welcome any feedback on the issue from the team (or if I have messed something up that may have caused this in the first place). I see this question in several places across the internet, and it's gone unanswered from what I've seen which is why I've provided as much detail as possible here. Thanks again for a great tool!

coffeegist avatar Dec 18 '21 23:12 coffeegist