diff --git a/.gitignore b/.gitignore index 262bb60..684398a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -*.exe .idea mac/dist windows/dist diff --git a/windows/PortQry.exe b/windows/PortQry.exe new file mode 100644 index 0000000..075547c Binary files /dev/null and b/windows/PortQry.exe differ diff --git a/windows/datashare.bat b/windows/datashare.bat index 56338dd..3fee204 100755 --- a/windows/datashare.bat +++ b/windows/datashare.bat @@ -1,5 +1,64 @@ @echo off -set CURRENT_RUNNING_BATCH_PATH=%~dp0 -PowerShell.exe -Command "& '%CURRENT_RUNNING_BATCH_PATH%\datashare.ps1'" -PAUSE +docker info 2>NUL + +if ERRORLEVEL 1 ( + echo docker is not running, launching it + start "" "\Program Files\Docker\Docker\Docker for Windows.exe" + call :wait_docker_is_up +) + +set datashare_id= +for /f "delims=" %%a in ('docker-compose -p datashare ps -q datashare') do @set datashare_id=%%a +set datashare_status= +if [%datashare_id] == [] ( + for /f "delims=" %%a in ('docker inspect %datashare_id% -f "{{.State.Status}}"') do @set datashare_status=%%a +) +set mem_size= +for /f "skip=1" %%a in ('wmic os get totalvirtualmemorysize') do ( + set mem_size=%%a + goto :done +) +:done +set /a mem_allocated=mem_size/(2*1024) +set DS_JAVA_OPTS=-Xmx%mem_allocated%m + +if "%datashare_status%"=="running" ( + docker-compose -p datashare restart datashare +) else ( + docker-compose -p datashare up -d +) + +call :wait_idx_is_up + +if not ERRORLEVEL 1 ( + start "" http://localhost:8080 +) + +exit /B %ERRORLEVEL% + +:wait_docker_is_up +echo|set /p="waiting for docker to be up" +for /l %%x in (1, 1, 60) do ( + docker info 2>NUL + if not ERRORLEVEL 1 ( + echo OK + exit /B 0 + ) + echo|set /p="." + timeout /t 1 /nobreak > NUL +) + +:wait_idx_is_up +echo|set /p="waiting for datashare to be up" +for /l %%x in (1, 1, 60) do ( + timeout /t 1 /nobreak >NUL + "%~dp0/PortQry.exe" -n "localhost" -e 8080 >NUL 2>NUL + if not ERRORLEVEL 1 ( + echo OK + exit /B 0 + ) + echo|set /p="." +) +echo KO +exit /B %ERRORLEVEL% diff --git a/windows/installDatashare.nsi b/windows/installDatashare.nsi index ea16249..8a763a7 100644 --- a/windows/installDatashare.nsi +++ b/windows/installDatashare.nsi @@ -73,8 +73,8 @@ Function InstallDatashare exch $R0 SetOutPath "$INSTDIR" file "datashare.ico" - File "datashare.ps1" File "datashare.bat" + File "PortQry.exe" File /oname=docker-compose.yml "dist/docker-compose.yml" # Start Menu