Orientdb: should console.sh look for .orientdb_history in the home directory of the user who invoked it?

Created on 16 Jul 2015  路  7Comments  路  Source: orientechnologies/orientdb

I'm managed to successfully install orientdb-community-2.0.1 on Ubuntu 14.04.2 in /opt using the instructions at http://www.famvdploeg.com/blog/2013/01/setting-up-an-orientdb-server-on-ubuntu/; when I try running console.sh as myself, however, I observe the following exception:

History file not found
java.io.FileNotFoundException: .orientdb_history (Permission denied)
    at java.io.FileInputStream.open(Native Method)
    at java.io.FileInputStream.<init>(FileInputStream.java:146)
    at java.io.FileReader.<init>(FileReader.java:72)
    at com.orientechnologies.common.console.TTYConsoleReader.<init>(TTYConsoleReader.java:64)
    at com.orientechnologies.orient.graph.console.OGremlinConsole.main(OGremlinConsole.java:60)
Exception in thread "main" com.orientechnologies.common.exception.OException: Cannot access to the input stream. Check permissions of running process
    at com.orientechnologies.common.console.TTYConsoleReader.<init>(TTYConsoleReader.java:84)
    at com.orientechnologies.orient.graph.console.OGremlinConsole.main(OGremlinConsole.java:60)

I can run the console via sudo -u orientdb /opt/orientdb-community-2.0.1/bin/console.sh; however, shouldn't the presence of a Unix user in the orientdb group and making console.sh group executable be sufficient to enable one to run the console as that user?

question wontfix

Most helpful comment

i tried to reproduce the issue in my local environment and it appears the issue is happening due to the console trying to read/write the history file in current directory (which the script has previously set to $ORIENTDB_HOME). since the normal user does not have write permission to ORIENTDB_HOME, it fails.

as a workaround, you can comment out the line in console.sh that says 'cd $ORIENTDB_HOME/bin'.
this will cause the history file to be read/written from the current directory where the normal user runs the console script (which could of course change between runs)

it is also possible to work around this problem by giving write permission to $ORIENTDB_HOME to the orientdb group, but that could result in other security issues, like users being able to read each other's command history (including passwords)

i am inclined to think the proper fix for the issue would be for the console program to read write the history file from the user's home directory.

All 7 comments

if you have previously run the console as root (using sudo), the .orientdb_history file would have been created as root in the current user's home directory and so a normal user would subsequently not be able to write to that file. that's why you are seeing permission denied error. delete this file (it contains the history of commands run at the console, somewhat along the same lines as .bash_history, so if you don't need the history it is safe to delete it) and restart the console as normal user you should be good to go.

After removing the .orientdb_history file, I observe the following exception:

Error creating history file.
java.io.IOException: Permission denied
        at java.io.UnixFileSystem.createFileExclusively(Native Method)
        at java.io.File.createNewFile(File.java:1006)
        at com.orientechnologies.common.console.TTYConsoleReader.getHistoryFile(TTYConsoleReader.java:447)
        at com.orientechnologies.common.console.TTYConsoleReader.<init>(TTYConsoleReader.java:61)
        at com.orientechnologies.orient.graph.console.OGremlinConsole.main(OGremlinConsole.java:60)
History file not found
java.io.FileNotFoundException: .orientdb_history (No such file or directory)
        at java.io.FileInputStream.open(Native Method)
        at java.io.FileInputStream.<init>(FileInputStream.java:146)
        at java.io.FileReader.<init>(FileReader.java:72)
        at com.orientechnologies.common.console.TTYConsoleReader.<init>(TTYConsoleReader.java:64)
        at com.orientechnologies.orient.graph.console.OGremlinConsole.main(OGremlinConsole.java:60)
Exception in thread "main" com.orientechnologies.common.exception.OException: Cannot access to the input stream. Check permissions of running process
        at com.orientechnologies.common.console.TTYConsoleReader.<init>(TTYConsoleReader.java:84)
        at com.orientechnologies.orient.graph.console.OGremlinConsole.main(OGremlinConsole.java:60)

i tried to reproduce the issue in my local environment and it appears the issue is happening due to the console trying to read/write the history file in current directory (which the script has previously set to $ORIENTDB_HOME). since the normal user does not have write permission to ORIENTDB_HOME, it fails.

as a workaround, you can comment out the line in console.sh that says 'cd $ORIENTDB_HOME/bin'.
this will cause the history file to be read/written from the current directory where the normal user runs the console script (which could of course change between runs)

it is also possible to work around this problem by giving write permission to $ORIENTDB_HOME to the orientdb group, but that could result in other security issues, like users being able to read each other's command history (including passwords)

i am inclined to think the proper fix for the issue would be for the console program to read write the history file from the user's home directory.

Thanks - changing cd $ORIENTDB_HOME/bin to cd ~/ eliminated the problem.

I've modified the issue title and will leave it open in case someone wants to apply this change to console.sh in the source.

there are problems with doing that, for example if someone wants to run the console in headless mode feeding a batch script in the 'current directory', the console.sh changes the directory to $HOME which will produce unexpected results or failures. that's one of the reasons why i suggested that the console _java_ program implement the logic to write the history to $HOME instead of relying on the wrapper shell script to do that.
until then, you may also want to store the previous 'current directory' before you cd ~/ and restore it after the java program exits otherwise you will observe that the script always drops you to $HOME when it exits.

Point taken - I modified my console.sh to restore the original pwd as suggested.

Thanks @nagarajasr for your support.

Was this page helpful?
0 / 5 - 0 ratings