-
Notifications
You must be signed in to change notification settings - Fork 2.3k
/
Get-Neo4jPrunsrv.ps1
175 lines (147 loc) · 7.14 KB
/
Get-Neo4jPrunsrv.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Copyright (c) 2002-2018 "Neo Technology,"
# Network Engine for Objects in Lund AB [http://neotechnology.com]
#
# This file is part of Neo4j.
#
# Neo4j is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
<#
.SYNOPSIS
Retrieves information about PRunSrv on the local machine to start Neo4j programs
.DESCRIPTION
Retrieves information about PRunSrv (Apache Commons Daemon) on the local machine to start Neo4j services and utilites, tailored to the type of Neo4j edition
.PARAMETER Neo4jServer
An object representing a valid Neo4j Server object
.PARAMETER ForServerInstall
Retrieve the PrunSrv command line to install a Neo4j Server
.PARAMETER ForServerUninstall
Retrieve the PrunSrv command line to install a Neo4j Server
.PARAMETER ForConsole
Retrieve the PrunSrv command line to start a Neo4j Server in the console.
.OUTPUTS
System.Collections.Hashtable
.NOTES
This function is private to the powershell module
#>
Function Get-Neo4jPrunsrv
{
[cmdletBinding(SupportsShouldProcess=$false,ConfirmImpact='Low',DefaultParameterSetName='ConsoleInvoke')]
param (
[Parameter(Mandatory=$true,ValueFromPipeline=$false)]
[PSCustomObject]$Neo4jServer
,[Parameter(Mandatory=$true,ValueFromPipeline=$false,ParameterSetName='ServerInstallInvoke')]
[switch]$ForServerInstall
,[Parameter(Mandatory=$true,ValueFromPipeline=$false,ParameterSetName='ServerUninstallInvoke')]
[switch]$ForServerUninstall
,[Parameter(Mandatory=$true,ValueFromPipeline=$false,ParameterSetName='ConsoleInvoke')]
[switch]$ForConsole
)
Begin
{
}
Process
{
$JavaCMD = Get-Java -Neo4jServer $Neo4jServer -ForServer -ErrorAction Stop
if ($JavaCMD -eq $null)
{
Write-Error 'Unable to locate Java'
return 255
}
# JVMDLL is in %JAVA_HOME%\bin\server\jvm.dll
$JvmDLL = Join-Path -Path (Join-Path -Path (Split-Path $JavaCMD.java -Parent) -ChildPath 'server') -ChildPath 'jvm.dll'
if (-Not (Test-Path -Path $JvmDLL)) { Throw "Could not locate JVM.DLL at $JvmDLL" }
# Get the Service Name
$Name = Get-Neo4jWindowsServiceName -Neo4jServer $Neo4jServer -ErrorAction Stop
# Find PRUNSRV for this architecture
# This check will return the OS architecture even when running a 32bit app on 64bit OS
switch ( (Get-WMIObject -Class Win32_Processor | Select-Object -First 1).Addresswidth ) {
32 { $PrunSrvName = 'prunsrv-i386.exe' } # 4 Bytes = 32bit
64 { $PrunSrvName = 'prunsrv-amd64.exe' } # 8 Bytes = 64bit
default { throw "Unable to determine the architecture of this operating system (Integer is $([IntPtr]::Size))"}
}
$PrunsrvCMD = Join-Path (Join-Path -Path(Join-Path -Path $Neo4jServer.Home -ChildPath 'bin') -ChildPath 'tools') -ChildPath $PrunSrvName
if (-not (Test-Path -Path $PrunsrvCMD)) { throw "Could not find PRUNSRV at $PrunsrvCMD"}
# Build the PRUNSRV command line
switch ($PsCmdlet.ParameterSetName) {
"ServerInstallInvoke" {
$PrunArgs += @("`"//IS//$($Name)`"")
$JvmOptions = @()
Write-Verbose "Reading JVM settings from configuration"
# Try neo4j.conf first, but then fallback to neo4j-wrapper.conf for backwards compatibility reasons
$setting = (Get-Neo4jSetting -ConfigurationFile 'neo4j.conf' -Name 'dbms.jvm.additional' -Neo4jServer $Neo4jServer)
if ($setting -ne $null) {
$JvmOptions = [array](Merge-Neo4jJavaSettings -Source $JvmOptions -Add $setting.Value)
} else {
$setting = (Get-Neo4jSetting -ConfigurationFile 'neo4j-wrapper.conf' -Name 'dbms.jvm.additional' -Neo4jServer $Neo4jServer)
if ($setting -ne $null) {
$JvmOptions = [array](Merge-Neo4jJavaSettings -Source $JvmOptions -Add $setting.Value)
}
}
# Pass through appropriate args from Java invocation to Prunsrv
# These options take priority over settings in the wrapper
Write-Verbose "Reading JVM settings from console java invocation"
$JvmOptions = [array](Merge-Neo4jJavaSettings -Source $JvmOptions -Add ($JavaCMD.args | Where-Object { $_ -match '(^-D|^-X)' }))
$PrunArgs += @("`"--StartMode=jvm`"",
"`"--StartMethod=start`"",
"`"--StartPath=$($Neo4jServer.Home)`"",
"`"--StartParams=--config-dir=$($Neo4jServer.ConfDir)`"",
"`"++StartParams=--home-dir=$($Neo4jServer.Home)`"",
"`"--StopMode=jvm`"",
"`"--StopMethod=stop`"",
"`"--StopPath=$($Neo4jServer.Home)`"",
"`"--Description=Neo4j Graph Database - $($Neo4jServer.Home)`"",
"`"--DisplayName=Neo4j Graph Database - $Name`"",
"`"--Jvm=$($JvmDLL)`"",
"`"--LogPath=$($Neo4jServer.LogDir)`"",
"`"--StdOutput=$(Join-Path -Path $Neo4jServer.LogDir -ChildPath 'neo4j.log')`"",
"`"--StdError=$(Join-Path -Path $Neo4jServer.LogDir -ChildPath 'service-error.log')`"",
"`"--LogPrefix=neo4j-service`"",
"`"--Classpath=lib/*;plugins/*`"",
"`"--JvmOptions=$($JvmOptions -join ';')`"",
"`"--Startup=auto`""
)
# Check if Java invocation includes Java memory sizing
$JavaCMD.args | ForEach-Object -Process {
if ($Matches -ne $null) { $Matches.Clear() }
if ($_ -match '^-Xms([\d]+)m$') {
$PrunArgs += "`"--JvmMs`""
$PrunArgs += "`"$($matches[1])`""
Write-Verbose "Use JVM Start Memory of $($matches[1]) MB"
}
if ($Matches -ne $null) { $Matches.Clear() }
if ($_ -match '^-Xmx([\d]+)m$') {
$PrunArgs += "`"--JvmMx`""
$PrunArgs += "`"$($matches[1])`""
Write-Verbose "Use JVM Max Memory of $($matches[1]) MB"
}
}
if ($Neo4jServer.ServerType -eq 'Enterprise') { $serverMainClass = 'org.neo4j.server.enterprise.EnterpriseEntryPoint' }
if ($Neo4jServer.ServerType -eq 'Community') { $serverMainClass = 'org.neo4j.server.CommunityEntryPoint' }
if ($Neo4jServer.DatabaseMode.ToUpper() -eq 'ARBITER') { $serverMainClass = 'org.neo4j.server.enterprise.ArbiterEntryPoint' }
if ($serverMainClass -eq '') { Write-Error "Unable to determine the Server Main Class from the server information"; return $null }
$PrunArgs += @("`"--StopClass=$($serverMainClass)`"",
"`"--StartClass=$($serverMainClass)`"")
}
"ServerUninstallInvoke" { $PrunArgs += @("`"//DS//$($Name)`"") }
"ConsoleInvoke" { $PrunArgs += @("`"//TS//$($Name)`"") }
default {
throw "Unknown ParameterSerName $($PsCmdlet.ParameterSetName)"
return $null
}
}
Write-Output @{'cmd' = $PrunsrvCMD; 'args' = $PrunArgs}
}
End
{
}
}