ci: add Windows service start/stop test to CI workflow#606
ci: add Windows service start/stop test to CI workflow#606
Conversation
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/b8d7e4b7-e6e7-45c5-b70c-b90833a88d84 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
Agent-Logs-Url: https://github.com/OpenIdentityPlatform/OpenDJ/sessions/a07e721d-23f2-4511-976c-3682f3473369 Co-authored-by: vharseko <6818498+vharseko@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds coverage in the Windows CI job to validate OpenDJ can be registered, started, and stopped as a Windows Service (not just run as a foreground process).
Changes:
- Register OpenDJ as a Windows service at the end of the existing Windows test run.
- Start the service, wait for LDAPS port readiness, and re-run an LDAP query for verification.
- Stop and unregister the service after validation.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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 |
There was a problem hiding this comment.
The added readiness loop on line 239 is PowerShell syntax, but this run: block also contains cmd-style constructs (e.g., set ... earlier in the step, plus find/findstr pipelines). If the step is executed with shell: cmd (or its shell changes), line 239 will fail immediately. Make the shell for this step explicit and consistent (e.g., shell: pwsh with corresponding updates), or explicitly invoke the readiness loop via pwsh -Command ... so it runs reliably regardless of the step shell.
| 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 } } |
There was a problem hiding this comment.
This loop can complete without confirming success (e.g., after 12 retries it exits silently), which makes failures harder to diagnose. After the loop, add an explicit failure condition when the port never becomes reachable (e.g., track success in a flag and exit with a clear error message if the port is still closed).
| 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 } } | |
| $servicePortOpen = $false | |
| for ($i=0; $i -lt 12; $i++) { | |
| try { | |
| $c = New-Object System.Net.Sockets.TcpClient('localhost', 1636) | |
| $c.Close() | |
| $servicePortOpen = $true | |
| break | |
| } | |
| catch { | |
| Start-Sleep -Seconds 5 | |
| } | |
| } | |
| if (-not $servicePortOpen) { | |
| Write-Error "OpenDJ Server did not start listening on port 1636 after 12 attempts (60 seconds). Failing the build." | |
| exit 1 | |
| } |
| 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 |
There was a problem hiding this comment.
If any command between --enableService and --disableService fails, the step will stop and the disable/cleanup won’t run. Even on ephemeral runners, leaving the service registered can complicate subsequent troubleshooting within the same job log and can produce misleading follow-on failures if more commands are added later. Consider structuring the service block so cleanup runs in a finally/guaranteed cleanup section (or move cleanup into a separate step with if: always() if project constraints allow).
| 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 | |
| try { | |
| 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" | |
| } | |
| finally { | |
| opendj-server-legacy\target\package\opendj\bat\windows-service.bat --disableService | |
| } |
| 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 |
There was a problem hiding this comment.
If any command between --enableService and --disableService fails, the step will stop and the disable/cleanup won’t run. Even on ephemeral runners, leaving the service registered can complicate subsequent troubleshooting within the same job log and can produce misleading follow-on failures if more commands are added later. Consider structuring the service block so cleanup runs in a finally/guaranteed cleanup section (or move cleanup into a separate step with if: always() if project constraints allow).
| 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 | |
| try { | |
| 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" | |
| } finally { | |
| net stop "OpenDJ Server" -ErrorAction SilentlyContinue | |
| opendj-server-legacy\target\package\opendj\bat\windows-service.bat --disableService | |
| } |
net start/stop OpenDJ→net start/stop "OpenDJ Server"(correct service name from pom.xml<name>OpenDJ Server</name>)powershell -Command "..."wrapper since shell is alreadypwsh(prevents$i/$cbeing expanded to empty by the outer shell)Original prompt
This pull request was created from Copilot chat.