diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 26894a3684..9123cd54d3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -42,11 +42,21 @@ jobs: path: ~/.m2/repository key: ${{ runner.os }}-m2-repository-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2-repository + - name: Build Windows native executables + if: runner.os == 'Windows' + shell: cmd + run: | + call "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x86 + cd opendj-server-legacy\src\build-tools\windows + nmake all + xcopy /Y *.exe ..\..\..\lib\ + git status - name: Set Integration Test Environment id: failsafe if: runner.os != 'Windows' run: | echo "MAVEN_PROFILE_FLAG=-P precommit" >> $GITHUB_OUTPUT + - name: Build with Maven timeout-minutes: 180 env: @@ -234,6 +244,21 @@ jobs: opendj-server-legacy\target\package\opendj\bat\rebuild-index.bat --bindDN "cn=Directory Manager" --bindPassword password --baseDN "dc=example2,dc=com" --rebuildAll --trustAll opendj-server-legacy\target\package\opendj\bat\ldapsearch.bat --hostname localhost --port 1636 --bindDN "cn=Directory Manager" --bindPassword password --useSsl --trustAll --baseDN "dc=example2,dc=com" --searchScope sub "(uid=user.*)" dn | find /c '"dn:"' | findstr "10000" opendj-server-legacy\target\package\opendj\bat\stop-ds.bat + opendj-server-legacy\target\package\opendj\bat\windows-service.bat --enableService + net start "OpenDJ Server" + for ($i=0; $i -lt 12; $i++) { try { $c = New-Object System.Net.Sockets.TcpClient('localhost', 1636); $c.Close(); break } catch { Start-Sleep -Seconds 5 } } + opendj-server-legacy\target\package\opendj\bat\ldapsearch.bat --hostname localhost --port 1636 --bindDN "cn=Directory Manager" --bindPassword password --useSsl --trustAll --baseDN "dc=example2,dc=com" --searchScope sub "(uid=user.*)" dn | find /c '"dn:"' | findstr "10000" + net stop "OpenDJ Server" + opendj-server-legacy\target\package\opendj\bat\windows-service.bat --disableService + + - name: Upload Windows exe artifacts + if: runner.os == 'Windows' + uses: actions/upload-artifact@v4 + with: + name: windows-exe-${{ matrix.java }} + retention-days: 5 + path: opendj-server-legacy/src/build-tools/windows/*.exe + - name: Upload artifacts OpenDJ Server uses: actions/upload-artifact@v4 with: diff --git a/opendj-server-legacy/src/build-tools/windows/service.c b/opendj-server-legacy/src/build-tools/windows/service.c index 0f9f6e0fc0..42082bc2e3 100644 --- a/opendj-server-legacy/src/build-tools/windows/service.c +++ b/opendj-server-legacy/src/build-tools/windows/service.c @@ -13,6 +13,7 @@ * * Copyright 2008-2010 Sun Microsystems, Inc. * Portions Copyright 2011-2013 ForgeRock AS. + * Portions Copyright 2026 3A Systems, LLC. */ #include "service.h" @@ -563,12 +564,44 @@ ServiceReturnCode doStartApplication() if (createOk && waitOk) { - BOOL running; - // Just check once if the server is running or not: since the wait - // wait was successful, if the server is getting the lock, it already - // got it. - isServerRunning(&running, TRUE); - if (running) + // The batch file process completed successfully, but the Java server + // process may not have acquired the lock file yet (especially on + // Windows 11 where JVM startup can be slower). Retry with a loop + // similar to the else-if branch below. + // See: https://github.com/OpenIdentityPlatform/OpenDJ/issues/259 + const DWORD DEFAULT_TRIES = 100; + int nTries = DEFAULT_TRIES; + char * nTriesEnv = getenv("OPENDJ_WINDOWS_SERVICE_START_NTRIES"); + BOOL running = FALSE; + if (nTriesEnv != NULL) + { + debug("OPENDJ_WINDOWS_SERVICE_START_NTRIES env var set to %s", nTriesEnv); + nTries = (int)strtol(nTriesEnv, (char **)NULL, 10); + if (nTries <= 0) + { + nTries = DEFAULT_TRIES; + } + } + else + { + debug("OPENDJ_WINDOWS_SERVICE_START_NTRIES is not set. Using default %d tries.", nTries); + } + + while ((nTries > 0) && !running) + { + nTries--; + if (isServerRunning(&running, TRUE) != SERVICE_RETURN_OK) + { + break; + } + if (!running) + { + debug("Sleeping for 5 seconds to allow the process to get the lock. %d tries remaining.", + nTries); + Sleep(5000); + } + } + if (running) { returnValue = SERVICE_RETURN_OK; debug("doStartApplication: server running.");