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:
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
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=22.214.171.124 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-jre126.96.36.199-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
This will tell you that the service is installed, next we check the status:
Which will tell us:
Neo4j is not running. Current status is Stopped
Ahh yes, we need to start it! So let’s do that:
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!