cancel
Showing results for 
Search instead for 
Did you mean: 

Join the community at Nodes 2022, our free virtual event on November 16 - 17.

What happens if you have two directories of Neo4j?

Ooker
Node

I have two directories of Neo4j, one is made by Neo4j Desktop (folder A), and one is downloaded from community server (folder B). The shell and the service running the those folder will be respectively called as shell A and service A, shell B and service B.

  1. It seems that services don't run globally? I open shell A and start service A, and in shell B it says Neo4j is not running. It's the same if I stop service A and start service B: shell A says Neo4j is not running.

  2. Nevertheless, if I start service A not service B, in shell B running cypher-shell can still ask for the username and password. The reverse is the same: if I start service B not service A, in shell A running cypher-shell can still ask for the username and password. Why is that?

  3. Now if I open Desktop, then start service B, then it only runs for a moment before stopping. I suppose this is an expected behavior to avoid clashing. However, service A doesn't stop. I wonder why is that?

1 ACCEPTED SOLUTION

I can answer these.

  1. I assume you were using neo4j status to check if Neo4j is running. When Neo4j is launched via neo4j start, it creates a file with the pid of the launched process (this file is removed when neo4j stops), and neo4j status looks for that file for that specific instance, and if it finds it, double-checks that it's running, and at that point it knows that its neo4j is running. If neo4j status is run on a different instance, since neo4j was not started for that instance, it has no file to reference with the pid, so it believes neo4j is not running. If you are starting neo4j from a service or systemd or similar, then you should not use neo4j status, and should use the service instead to determine if neo4j is running.

  2. cypher-shell doesn't look for any pid files. It is only looking to make a bolt connection to the given address when invoked (or if not provided, it will default to look for a bolt connection to localhost:7687). So it doesn't matter which neo4j you start, if both are configured for bolt on 7687 on your local machine, cypher-shell will connect.

  3. By default Neo4j, on desktop or standalone, will run on your local machine and will listen for bolt connections on port 7687. If you launch another Neo4j instance that is trying to bind to ports already bound to another running Neo4j instance, that will fail and neo4j will stop. If you want to run two Neo4j instances simultaneously on the same machine, at least one of those instances needs to have its configuration changed so the ports used do not conflict.

View solution in original post

2 REPLIES 2

I can answer these.

  1. I assume you were using neo4j status to check if Neo4j is running. When Neo4j is launched via neo4j start, it creates a file with the pid of the launched process (this file is removed when neo4j stops), and neo4j status looks for that file for that specific instance, and if it finds it, double-checks that it's running, and at that point it knows that its neo4j is running. If neo4j status is run on a different instance, since neo4j was not started for that instance, it has no file to reference with the pid, so it believes neo4j is not running. If you are starting neo4j from a service or systemd or similar, then you should not use neo4j status, and should use the service instead to determine if neo4j is running.

  2. cypher-shell doesn't look for any pid files. It is only looking to make a bolt connection to the given address when invoked (or if not provided, it will default to look for a bolt connection to localhost:7687). So it doesn't matter which neo4j you start, if both are configured for bolt on 7687 on your local machine, cypher-shell will connect.

  3. By default Neo4j, on desktop or standalone, will run on your local machine and will listen for bolt connections on port 7687. If you launch another Neo4j instance that is trying to bind to ports already bound to another running Neo4j instance, that will fail and neo4j will stop. If you want to run two Neo4j instances simultaneously on the same machine, at least one of those instances needs to have its configuration changed so the ports used do not conflict.

Ooker
Node

Thanks for your help. I understand now.

@abk also answers this question, and I will copy it here for anyone interested:

  1. On the server-side: Each mechanism for launching Neo4j is only aware of itself. There is no global state through which the DBMSes can check with each other.
  2. On the client-side: cypher-shell makes assumptions about the default hostname and port for a neo4j database. It will connect to whatever DBMS server is running at the hostname and port, regardless of how that server was launched.
  3. Neo4j Desktop attempts to manage port conflicts. It monitors a DBMS when you click "start" to ensure that it is running, and to look for port conflicts as one reason the DBMS may fail to start. When that is a problem Desktop will offer to start Neo4j on a different port by rewriting the neo4j.conf file. You can see this behavior by first starting a DBMS manually from the command line, and then starting a DBMS from within Desktop.
    Conversely, a manually started Neo4j DBMS will only use the ports that are specified within the neo4j.conf file. Neo4j DBMS itself will realize there is a port conflict but will not attempt to change ports. It only uses the port specified. The result is that a port conflict will prevent Neo4j DBMS from starting.