Running Neo4j as a Service on Windows Server 2019 Core

I know most of you will be here for the EPIC title picture, the dinosaurs are from http://deviantart.com/susannehs/ – I hope she isn’t too disappointed 😮 The other art, well, that’s all mine… if you want graph information – feel free to ask, and if after seeing that picture you want art – let’s talk!

In the last post we looked at running Neo4j on a server running Windows Server 2019 Core. But what we did was run it in console mode so whenever you logged off, the server would shut down – which many would say is not ideal for a server.

So let’s install it as a service, as we’re adding a service into the server, we’re going to need to be an admin, so log on to your server as an admin (or use SSH – I will be).

Get to the right place

You don’t need to do this – but it makes life a bit easier. In your PowerShell window, let’s get to the right directory:

cd C:\Neo4j\neo4j-enterprise-4.2.1\

NB your Neo4j version might be different depending on when you do this. The script in the previous post will get the latest version.

Install as a service

.\bin\neo4j.bat install-service

Uh oh:

Invoke-Neo4j : Unable to determine the path to java.exe
At C:\Neo4j\neo4j-enterprise-4.2.1\bin\neo4j.ps1:18 char:7
+ Exit (Invoke-Neo4j -Verbose:$Arguments.Verbose -Command $Arguments.Ar ...
+       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
    + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,Invoke-Neo4j

Setup the Environment

This is because the scripts we’ve used to start the server so far call an environment.bat file beforehand – which sets up Java etc, but that is on a session by session basis – so we need to add the JAVA_HOME environment variable now:

If you look at the environment.bat file (micro ..\scripts\environment.bat) you’ll see this:

set zuluVersion=11.43.55
set jreVersion=11.0.9.1

set JAVA_HOME=%CD%\zulu%zuluVersion%-ca-jre%jreVersion%-win_x64

Again Version alert!! They may be different values on your server!!

So we want to set the JAVA_HOME environment variable, and we’ll add it to the path as well, unfortunately, these are cmd commands, so set JAVA_HOME doesn’t work in PowerShell, so we need to run:

$javaPath = "C:\Neo4j\zulu11.43.55-ca-jre11.0.9.1-win_x64\"


$oldpath = (Get-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH).path
$newpath = "$oldpath;$javaPath\bin"
Set-ItemProperty -Path 'Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Session Manager\Environment' -Name PATH -Value $newpath


[System.Environment]::SetEnvironmentVariable('JAVA_HOME',$javaPath,[System.EnvironmentVariableTarget]::Machine)

You’ll want to restart the computer after this (Restart-Computer) and now we should be able to install our service.

Install as a service

C:\Neo4j\neo4j-enterprise-4.2.1\bin\neo4j.bat install-service

This will tell you that the service is installed, next we check the status:

C:\Neo4j\neo4j-enterprise-4.2.1\bin\neo4j.bat install-service

Which will tell us:

Neo4j is not running.  Current status is Stopped

Ahh yes, we need to start it! So let’s do that:

C:\Neo4j\neo4j-enterprise-4.2.1\bin\neo4j.bat start

Now, this might say Neo4j service did not start – but always use status to see where things are, as when I run status subsequently, I get:

Neo4j is running

Right, so now, if we Restart-Computer again, and reconnect, we can run the status command again, and yes!

Neo4j is still running, we have succeeded!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.