Skip to content

Commit 97a04d9

Browse files
authored
Merge pull request #169 from naabakkcrypto/main
Add Windows OpenMemory service scripts
2 parents 9d1f44a + 876c808 commit 97a04d9

2 files changed

Lines changed: 72 additions & 0 deletions

File tree

start-openmemory.ps1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
4+
$Node = (Get-Command node.exe -ErrorAction Stop).Source
5+
$Opm = Join-Path $Root "packages\openmemory-js\bin\opm.js"
6+
$DataDir = Join-Path $Root "data"
7+
$LogDir = Join-Path $Root "logs"
8+
$DbPath = Join-Path $DataDir "openmemory.sqlite"
9+
$Stdout = Join-Path $LogDir "openmemory-server.log"
10+
$Stderr = Join-Path $LogDir "openmemory-server.err.log"
11+
12+
function Test-OpenMemoryHealth {
13+
try {
14+
$response = Invoke-RestMethod -Uri "http://127.0.0.1:8080/health" -TimeoutSec 3
15+
return [bool]$response.ok
16+
} catch {
17+
return $false
18+
}
19+
}
20+
21+
if (Test-OpenMemoryHealth) {
22+
return
23+
}
24+
25+
if (-not (Test-Path -LiteralPath $Opm)) {
26+
throw "OpenMemory CLI missing at $Opm. Run npm install in packages\openmemory-js."
27+
}
28+
29+
New-Item -ItemType Directory -Force -Path $DataDir, $LogDir | Out-Null
30+
31+
$env:OPENMEMORY_URL = "http://127.0.0.1:8080"
32+
$env:OM_PORT = "8080"
33+
$env:OM_DB_PATH = $DbPath
34+
$env:OM_TIER = "hybrid"
35+
$env:NO_COLOR = "1"
36+
37+
Start-Process `
38+
-FilePath $Node `
39+
-ArgumentList @("`"$Opm`"", "serve") `
40+
-WorkingDirectory $Root `
41+
-WindowStyle Hidden `
42+
-RedirectStandardOutput $Stdout `
43+
-RedirectStandardError $Stderr | Out-Null
44+
45+
$deadline = (Get-Date).AddSeconds(20)
46+
while ((Get-Date) -lt $deadline) {
47+
if (Test-OpenMemoryHealth) {
48+
return
49+
}
50+
Start-Sleep -Milliseconds 500
51+
}
52+
53+
throw "OpenMemory did not become healthy on http://127.0.0.1:8080/health. Check $Stdout and $Stderr."

stop-openmemory.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
$ErrorActionPreference = "Stop"
2+
3+
$Root = Split-Path -Parent $MyInvocation.MyCommand.Path
4+
$Opm = Join-Path $Root "packages\openmemory-js\bin\opm.js"
5+
$escapedRoot = [regex]::Escape($Root)
6+
$escapedOpm = [regex]::Escape($Opm)
7+
8+
$processes = Get-CimInstance Win32_Process |
9+
Where-Object {
10+
($_.CommandLine -match $escapedOpm -or $_.CommandLine -match $escapedRoot) -and
11+
$_.CommandLine -match "opm\.js" -and
12+
$_.CommandLine -match "\bserve\b"
13+
}
14+
15+
foreach ($process in $processes) {
16+
if ($process.ProcessId -ne $PID) {
17+
Stop-Process -Id $process.ProcessId -Force -ErrorAction SilentlyContinue
18+
}
19+
}

0 commit comments

Comments
 (0)