Neo4j Couldn’t get file lock

May 8, 2013

Problem

A non-root user is running Neo4j and you are seeing locking errors in the log file

Symptom

May 8, 2013 6:20:31 PM java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode
WARNING: Could not lock User prefs.  Unix error code 2.
May 8, 2013 6:20:31 PM java.util.prefs.FileSystemPreferences syncWorld
WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
May 8, 2013 6:21:01 PM java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode
WARNING: Could not lock User prefs.  Unix error code 2.
May 8, 2013 6:21:01 PM java.util.prefs.FileSystemPreferences syncWorld
WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock.
May 8, 2013 6:21:31 PM java.util.prefs.FileSystemPreferences checkLockFile0ErrorCode
WARNING: Could not lock User prefs.  Unix error code 2.
May 8, 2013 6:21:31 PM java.util.prefs.FileSystemPreferences syncWorld
WARNING: Couldn't flush user prefs: java.util.prefs.BackingStoreException: Couldn't get file lock."

Cause

The non-root ID that is being used to start the Neo4j instance does not have a user_home directory. Therefore this non-root ID is unable to access the root user’s “/etc/.java/.systemPrefs”. This produces the aforementioned warning messages every 30 seconds in the neo4j log file.

Diagnosing the problem

You can confirm this issue by trying to start Neo4j using the “root” ID. Review the log file to verify that you no longer see the warning messages.

Resolving the problem

Create a User_Home directory for this non-root user and restart Neo4J

Creating neo4j’s home dir if it doesn’t exist

Using the script below run this command:

check_home_directory_exist.sh neo4j
#!/bin/bash
#!/bin/bash
#
# Author: Steve Stonebraker
# name: check_home_directory_exist.sh
# usage: check_home_directory_exist.sh 
#
# description:  provide a user to the script and if their home directory doesn't exist it will be created
#
USER=$1
USER_HOMEDIR=$(cat /etc/passwd | grep ${USER} | cut -d":" -f6)

if [ ! -d "${USER_HOMEDIR}" ]; then
  mkdir ${USER_HOMEDIR}; chown -R ${USER}:${USER} ${USER_HOMEDIR}
  echo "${USER}'s home directory created"
else
  echo "${USER}'s home directory already exists"
fi

If in an HA instance

On all members run 
 service neo4j-service stop

On all instances except master (primary)
 rm -rf /opt/some-neo-dir/data/graph.db

Start neo4j on all members
 service neo4j-service start