Here is what to do if you are getting Error Log Messages from Karaf Console about history

I had been having this issue for some reason and wasn’t sure what the issue was or how to fix it really. It wasn’t a big deal as it didn’t seem to affect anything, but I figured out how to fix it so I thought I would share in case anyone else searches for this error.

I would get this warning every time I logged into and out of the Karaf console:

19:30:44.510 [WARN ] [org.jline                            ] - Failed to save history
java.nio.file.FileAlreadyExistsException: /var/lib/openhab/.karaf
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:88) [?:?]
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) [?:?]
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) [?:?]
        at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384) [?:?]
        at java.nio.file.Files.createDirectory(Files.java:674) [?:?]
        at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781) [?:?]
        at java.nio.file.Files.createDirectories(Files.java:727) [?:?]
        at org.jline.reader.impl.history.DefaultHistory.save(DefaultHistory.java:119) [14:org.jline:3.5.1.sp1]
        at org.jline.reader.impl.history.DefaultHistory.add(DefaultHistory.java:248) [14:org.jline:3.5.1.sp1]
        at org.jline.reader.impl.LineReaderImpl.finishBuffer(LineReaderImpl.java:870) [14:org.jline:3.5.1.sp1]
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:561) [14:org.jline:3.5.1.sp1]
        at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:349) [11:org.apache.karaf.shell.core:4.1.3]
        at java.lang.Thread.run(Thread.java:748) [?:?]
19:30:56.712 [WARN ] [org.jline                            ] - Failed to save history
java.nio.file.FileAlreadyExistsException: /var/lib/openhab/.karaf
        at sun.nio.fs.UnixException.translateToIOException(UnixException.java:88) [?:?]
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:102) [?:?]
        at sun.nio.fs.UnixException.rethrowAsIOException(UnixException.java:107) [?:?]
        at sun.nio.fs.UnixFileSystemProvider.createDirectory(UnixFileSystemProvider.java:384) [?:?]
        at java.nio.file.Files.createDirectory(Files.java:674) [?:?]
        at java.nio.file.Files.createAndCheckIsDirectory(Files.java:781) [?:?]
        at java.nio.file.Files.createDirectories(Files.java:727) [?:?]
        at org.jline.reader.impl.history.DefaultHistory.save(DefaultHistory.java:119) [14:org.jline:3.5.1.sp1]
        at org.jline.reader.impl.history.DefaultHistory.add(DefaultHistory.java:248) [14:org.jline:3.5.1.sp1]
        at org.jline.reader.impl.LineReaderImpl.finishBuffer(LineReaderImpl.java:870) [14:org.jline:3.5.1.sp1]
        at org.jline.reader.impl.LineReaderImpl.readLine(LineReaderImpl.java:561) [14:org.jline:3.5.1.sp1]
        at org.apache.karaf.shell.impl.console.ConsoleSessionImpl.run(ConsoleSessionImpl.java:349) [11:org.apache.karaf.shell.core:4.1.3]
        at java.lang.Thread.run(Thread.java:748) [?:?]

What it is doing is trying to save the commands that are input into the Karaf console. Here is an example of a file that gets put here:

1521156656710:log:tail
1521156787011:logout
1521156799578:log:tail

I have no idea why it wants to save it where it is trying to save it since it. My environment is OH1 to OH2 migration with both still installed currently.

In any event, the solution is easy. I was unsure if .karaf was a file or a folder, so I had to try different combinations, but it is a hidden folder.

Note, pay attention to the location where karaf is trying to store this file as it may be different on your install.

#Change to the proper directory
cd /var/lib/openhab

#Create the necessary directory
mkdir .karaf

#sudo, if needed here
chown openhab.openhab .karaf

#Permissions should be 0755
chmod 0755 .karaf

#Check it is all correct
ls -la .karaf

Should look like this:
drwxr-xr-x  2 openhab openhab 4096 Mar 15 19:33 .karaf

Logout and log back into Karaf and you should see the warning has disappeared.

May be simple, or well-known issue, but I couldn’t find anything on it, so hope this helps someone.

1 Like