From 87c404828cf632b634c798a02df85bf4e90155cc Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Sun, 4 May 2025 17:44:57 +0200 Subject: [PATCH] add powershell run scripts --- run-wrapper/run.ps1 | 48 ++++++++++++++++++++++++++++++++++++++++ run-wrapper/stop.ps1 | 24 ++++++++++++++++++++ run-wrapper/update.ps1 | 50 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 run-wrapper/run.ps1 create mode 100644 run-wrapper/stop.ps1 create mode 100644 run-wrapper/update.ps1 diff --git a/run-wrapper/run.ps1 b/run-wrapper/run.ps1 new file mode 100644 index 00000000..8549e694 --- /dev/null +++ b/run-wrapper/run.ps1 @@ -0,0 +1,48 @@ +$ErrorActionPreference = 'Stop' + +$PIDFILE = Join-Path $PSScriptRoot ".pid" +$EXTRAOPTS = Join-Path $PSScriptRoot "extra-opts" + +if (-Not (Test-Path $EXTRAOPTS)) { + New-Item -ItemType File -Path $EXTRAOPTS | Out-Null +} + +if (Test-Path $PIDFILE) { + $ReadPID = Get-Content $PIDFILE + if (Get-Process -Id $ReadPID -ErrorAction SilentlyContinue) { + Write-Host "Already running: $ReadPID" + exit 2 + } +} + +$ExtraOptsParsed = Get-Content $EXTRAOPTS | Where-Object {$_} + +Write-Host "Extra options: $($ExtraOptsParsed -join ' ')" + +$JAVA_OPTS = @( + "-Xmx512M" + "--enable-preview" + "-Ddhfs.objects.writeback.limit=134217728" + "-Ddhfs.objects.lru.limit=134217728" + "--add-exports", "java.base/sun.nio.ch=ALL-UNNAMED" + "--add-exports", "java.base/jdk.internal.access=ALL-UNNAMED" + "--add-opens=java.base/java.nio=ALL-UNNAMED" + "-Ddhfs.objects.persistence.files.root=$($PSScriptRoot)\..\data\objects" + "-Ddhfs.objects.persistence.stuff.root=$($PSScriptRoot)\..\data\stuff" + "-Ddhfs.objects.persistence.lmdb.size=1000000000" + "-Ddhfs.fuse.root=Z:\" + "-Dquarkus.http.host=0.0.0.0" + '-Dquarkus.log.category.\"com.usatiuk\".level=INFO' + '-Dquarkus.log.category.\"com.usatiuk.dhfs\".level=INFO' + "-Ddhfs.webui.root=$($PSScriptRoot)\Webui" +) + $ExtraOptsParsed + @( + "-jar", "`"$PSScriptRoot\Server\quarkus-run.jar`"" +) + +$Process = Start-Process -FilePath "java" -ArgumentList $JAVA_OPTS ` + -RedirectStandardOutput "$PSScriptRoot\quarkus.log" ` + -RedirectStandardError "$PSScriptRoot\quarkus.log.err" ` + -NoNewWindow -PassThru + +Write-Host "Started $($Process.Id)" +$Process.Id | Out-File -FilePath $PIDFILE diff --git a/run-wrapper/stop.ps1 b/run-wrapper/stop.ps1 new file mode 100644 index 00000000..636c58d7 --- /dev/null +++ b/run-wrapper/stop.ps1 @@ -0,0 +1,24 @@ +$ErrorActionPreference = 'Stop' + +$PIDFILE = Join-Path $PSScriptRoot ".pid" + +if (-Not (Test-Path $PIDFILE)) { + Write-Host "Not running" + exit 2 +} + +$ReadPID = Get-Content $PIDFILE + +if (-Not (Get-Process -Id $ReadPID -ErrorAction SilentlyContinue)) { + Write-Host "Not running" + Remove-Item $PIDFILE -Force + exit 2 +} + +Write-Host "Killing $ReadPID" + +# TODO: Graceful shutdown + +Stop-Process -Id $ReadPID + +Remove-Item $PIDFILE -Force diff --git a/run-wrapper/update.ps1 b/run-wrapper/update.ps1 new file mode 100644 index 00000000..597f4dc4 --- /dev/null +++ b/run-wrapper/update.ps1 @@ -0,0 +1,50 @@ +$ErrorActionPreference = 'Stop' + +$PIDFILE = Join-Path $PSScriptRoot ".pid" +$VERSION_FILE = Join-Path $PSScriptRoot "version" + +if (Test-Path $PIDFILE) { + $ReadPID = Get-Content $PIDFILE + if (Get-Process -Id $ReadPID -ErrorAction SilentlyContinue) { + Write-Host "Already running: $ReadPID" + exit 2 + } +} + +$response = Invoke-RestMethod -Uri "https://api.github.com/repos/usatiuk/dhfs/actions/runs?branch=main&status=completed&per_page=1" + +$LATEST = $response.workflow_runs[0].id +Write-Host "Latest: $LATEST" + +$CUR = (Get-Content $VERSION_FILE -Raw).Trim() +Write-Host "Current: $CUR" + +if ([long]$CUR -ge [long]$LATEST) { + Write-Host "Already latest!" + exit 1 +} + +Write-Host "Downloading..." + +Set-Location $PSScriptRoot + +$zipFile = "Run wrapper.zip" +$tarFile = "run-wrapper.tar.gz" +$dhfsDir = "dhfs" + +Remove-Item $zipFile, $tarFile -Force -ErrorAction SilentlyContinue +Remove-Item $dhfsDir -Recurse -Force -ErrorAction SilentlyContinue + +Invoke-WebRequest -Uri "https://nightly.link/usatiuk/dhfs/actions/runs/$LATEST/Run%20wrapper.zip" -OutFile $zipFile + +Expand-Archive -LiteralPath $zipFile -DestinationPath $PSScriptRoot +Remove-Item $zipFile -Force + +tar -xf $tarFile --strip-components=2 +Remove-Item $tarFile -Force + +Remove-Item "Server", "Webui", "NativeLibs" -Recurse -Force -ErrorAction SilentlyContinue +Move-Item "$dhfsDir\app\*" . -Force +Remove-Item $dhfsDir -Recurse -Force + +Write-Host "Update complete!"