Last active
April 19, 2018 13:00
-
-
Save jjaderberg/dea414e4870568485bd0cfa19a4d5f2b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Update installed Neo4j service configuration | |
# | |
# Script to illustrate the update service command. | |
# | |
# 1. Configure heap size in neo4j.conf; install and run service. Check memory config in debug.log. | |
# 2. Stop service and change heap size in neo4j.conf. | |
# 3. Run update service command | |
# 4. Start service and check memory config in debug.log. | |
$neo4jDir = Get-Item "C:\Neo4j\neo4j-enterprise-3.3.3\" | |
$debugLog = Get-ChildItem $neo4jDir -Filter "logs\debug.log" -File | |
$configFile = Get-ChildItem $neo4jDir -Filter "conf\neo4j.conf" -File | |
$configBackup = ($configFile | Get-Content) | |
function Get-EffectiveMemoryConfig { | |
Write-Output "[+] Checking debug.log for effective memory configuration" | |
$debugLog | Get-Content | Select-String -Pattern '(Total|Max)\s+memory:' | Select -ExpandProperty line | |
} | |
function Add-Configuration { | |
param($ConfigLines) | |
$configFile | Add-Content -Value $configLines | |
} | |
function Restore-Configuration { | |
$configFile | Set-Content -Value $configBackup | |
} | |
function Clear-DebugLog { | |
$debugLog | Clear-Content | |
} | |
Join-Path $neo4jDir -ChildPath "bin\Neo4j-Management.psd1" | Import-Module -Force | |
$debugLog | Clear-Content | |
# Add memory configuration to neo4j.conf; install and start service | |
Add-Configuration @("", "dbms.memory.heap.initial_size=300m", "dbms.memory.heap.max_size=500m") | |
Invoke-Neo4j install-service -Verbose | |
Invoke-Neo4j start | |
Start-Sleep 10 | |
# Check debug.log for the effective memory configuration | |
Get-EffectiveMemoryConfig | |
# Stop Neo4j and change the memory configuration | |
Invoke-Neo4j stop | |
Restore-Configuration | |
Add-Configuration @("", "dbms.memory.heap.initial_size=400m", "dbms.memory.heap.max_size=600m") | |
# Run update service command to update the service definition | |
Invoke-Neo4j update-service -Verbose | |
# Restart Neo4j | |
Invoke-Neo4j start | |
Start-Sleep 10 | |
# Check debug.log for the effective memory configuration | |
Get-EffectiveMemoryConfig | |
# Clean up | |
Restore-Configuration | |
Invoke-Neo4j uninstall-service -Verbose |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment