-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cloudbase-init localscript exitcode 1003 won't restart when converting Windows Server 2019 to a DomainController #100
Comments
I made many experiments and these are the results: I created all windows-server images installing dependencies with:
and Cloudbase-init 1.1.2 64 bit. What I want to do is converting my windows-server into a domain controller. The idea is this one (not the real script, but a simplified version):
I tested this script on these versions:
What I expect is that after every step, windows will reboot, because there is However the behaviour is not consistent across windows-server versions.
So, to understand why Cloudbase-init is not rebooting the system I added some logs into Cloudbase-init python source code.
def get_plugin_return_value(ret_val):
LOG.warning("get_plugin_return_value called with ret_val = %r", ret_val)
plugin_status = base.PLUGIN_EXECUTION_DONE
reboot = False
LOG.warning("get_plugin_return_value plugin_status = %r", plugin_status)
try:
ret_val = int(ret_val)
LOG.warning("get_plugin_return_value converted ret_val into an integer = %r", ret_val)
except (ValueError, TypeError):
ret_val = 0
LOG.warning("get_plugin_return_value cannot convert ret_val into an integer, forced to 0")
LOG.warning("get_plugin_return_value RET_START = %r", RET_START)
LOG.warning("get_plugin_return_value RET_END = %r", RET_END)
LOG.warning("get_plugin_return_value ret_val = %r", ret_val)
if ret_val and RET_START <= ret_val <= RET_END:
LOG.warning("get_plugin_return_value inside if to check for reboot with ret_val = %r", ret_val)
reboot = bool(ret_val & 1)
LOG.warning("get_plugin_return_value reboot = %r", reboot)
if ret_val & 2:
plugin_status = base.PLUGIN_EXECUTE_ON_NEXT_BOOT
LOG.warning("get_plugin_return_value plugin_status forced to PLUGIN_EXECUTE_ON_NEXT_BOOT, so plugin_status = %r", plugin_status)
LOG.warning("get_plugin_return_value returning plugin_status = %r, and reboot = %r", plugin_status, reboot)
return plugin_status, reboot
def reboot(self):
with privilege.acquire_privilege(win32security.SE_SHUTDOWN_NAME):
ret_val = advapi32.InitiateSystemShutdownExW(
0, "Cloudbase-Init reboot",
0, True, True, 0)
errno1 = ctypes.GetLastError()
LOG.warning("1) InitiateSystemShutdownExW returned ret_val = %r", ret_val)
LOG.warning("1) InitiateSystemShutdownExW result errno1 = %r", errno1)
if not ret_val:
raise exception.WindowsCloudbaseInitException(
"Reboot failed: %r")
def configure_host(self):
LOG.warning("configure_host called")
service = None
osutils = osutils_factory.get_os_utils()
if CONF.reset_service_password and sys.platform == 'win32':
self._reset_service_password_and_respawn(osutils)
LOG.info('Cloudbase-Init version: %s', version.get_version())
osutils.wait_for_boot_completion()
stage_success, reboot_required = self._handle_plugins_stage(
osutils, None, None,
plugins_base.PLUGIN_STAGE_PRE_NETWORKING)
LOG.warning("configure_host stage_success = %r", stage_success)
LOG.warning("configure_host reboot_required = %r", reboot_required)
LOG.warning("configure_host CONF.allow_reboot = %r", CONF.allow_reboot)
self._check_latest_version()
# (... source code omitted, but unchanged)
if reboot_required and CONF.allow_reboot:
LOG.warning("configure_host rebooting check in true")
try:
LOG.info("Rebooting")
osutils.reboot()
LOG.info("osutils.reboot() called without errors")
except Exception as ex:
LOG.error('reboot failed with error \'%s\'' % ex)
else:
LOG.info("Plugins execution done")
if (service and CONF.metadata_report_provisioning_completed and
stage_success):
try:
LOG.info("Reporting provisioning completed")
service.provisioning_completed()
except Exception as ex:
LOG.exception(ex)
if CONF.stop_service_on_exit:
LOG.info("Stopping Cloudbase-Init service")
osutils.terminate() I didn't change any logic! I simply added some logs to print data in cloudbase-init.log. The result for the broken version (windows server 2019) is:
As you can see, Cloudbase-init do everything as expected without errors and it calls This is the main reason of all issues, because every other attempt with workarounds to try to reboot the system in a forced way caused different errors (like the one described HERE about pending shutdown). In fact, if I modify localscript adding a
It causes the errore described in the first post of this issue, because you are trying to restart the system, but also Cloudbase-init is trying to do the same thing. You can easily modify the reboot function of Cloudbase-init to cancel the shutdown and do another shutdown, however this doesn't solve the problem, because the issue is with Do you have suggestions/workarounds to fix this? |
The question is: "why running InitiateSystemShutdownExW after Install-ADDSForest won't work even if the result is a success?" So
|
Unbelievable, I fixed this problem installing Clodubase-Init 1.1.2 as LocalSystem (the checkbox available in the installer). Now it's working on windows-server-2019 |
Hello, We have not seen this error so far with the initial testing of the feature a while back: https://github.com/openstack/heat-templates/blob/master/hot/Windows/ActiveDirectoryController/AD.psm1#L20 I am going to try to reproduce this error on a 2019 with latest updates and will try to raise the issue upstream, I think it s the flag that s not respected in the implementation. Thank you, |
Hi!
Which flag? I'm curious :) What does it means "LocalSystem"? Is it the "Admin/Administrator" account? Thanks |
Hello, We have tried to reproduce the issue, but seems that it works fine on Windows Server 2k19 Standard, latest updates, Build 17763. Here is the exact script to install AD (example script with dummy passwords, please do not use in production): #ps1
$ErrorActionPreference = "STOP"
$SafeModePwd = "Passw0rd"
$DomainName = "cbsl1.local"
$DomainNetbiosName = "cbsl1"
$defaultLocalAdministrator = "Administrator"
## Install tools
$adDSInstall = Install-WindowsFeature AD-Domain-Services -IncludeManagementTools
$mgtmToolInstall = Install-WindowsFeature RSAT-AD-Tools -IncludeManagementTools
if (!($adDSInstall.Success -and $mgtmToolInstall.Success)) {
throw "Failed to install AD-Domain-Services or RSAT-AD-Tools"
}
if ($adDSInstall.RestartNeeded -eq "Yes" -or $mgtmToolInstall.RestartNeeded -eq "Yes") {
exit 1003
}
## Install AD
try {
$adUser = Get-ADUser "Administrator" -ErrorAction SilentlyContinue
if ($adUser) {
exit 0
}
} catch {
Write-Host $_
}
$localAdministratorPath = "WinNT://./$defaultLocalAdministrator"
$user = [ADSI]$localAdministratorPath
$user.SetPassword($SafeModePwd)
Import-Module ADDSDeployment
$secureSafeModePwd = ConvertTo-SecureString $SafeModePwd -AsPlainText -Force
Install-ADDSForest -DomainName $DomainName `
-DomainNetbiosName $DomainNetbiosName `
-SafeModeAdministratorPassword $secureSafeModePwd `
-InstallDns -NoRebootOnCompletion -Force
exit 1003 Note that the script has to be idempotent and to have finality in the sense of an exit 0 when all has been completed. Thank you, |
Weird! Yes, also my script is idempotent to do these steps sequentially across different reboots. It's very similar to my script. The only difference is that I specify more parameters in ADDSForest:
Also, I'm using your same version of Windows Server 2019 (connected to the internet) with Cloudbase 1.1.2 64bit with
I sysprepped the image with My config file contains:
But I don't think that this issue is related to the config of cloudbase-init. What is the purpose of the flag "LocalSystem" in cloudbase-init? Is it a way to run it as Administrator instead of its specific user? Or, is it possible that there is a problem about timing? |
Hello, LocalSystem is a builtin Windows account and it does not get transformed from hostname/username into domainname/username when you create the AD and subsequently you transform the Windows installation into the first AD Domain Controller. What you can do in your script to try to cancel the reboot is to run: Thank you. |
I tried to do this via python without success. It won't reboot.
These are my files in cidata:
These are my cloudbase-init configs:
And the default Note that I'm using a localscript Thanks |
Hello again, I would need the exact localscript you are using in order to reproduce, as I have tried with the one I shared above and works as expected. I think there might be a way to fix it in cloudbase-init code directly -- perform a shutdown abort if need be, but I need to reproduce the issue first. Thank you, |
Hi @ader1990 I'm sorry for the delay. This is my full localscript file executed from a virtual cd-rom with path
The config files used are those #100 (comment) |
I'm stucked with this error since May 2022 and I didn't find any solution.
I also opened a discussion here ask.cloudbase.
It happens only with Windows Server 2019
I tried these configurations:
I sysprepped all of these configurations and used a Powershell script (via local scripts) to convert the OS into a DomainController.
In my powershell script I install required features:
This part of the script works as expected!
Then I create the forest and reboot again with exit 1003:
But this time, cloudbase-init returns an error as shown in log file:
The Italian message says "System shutdown already planned".
Do you have any suggestion? Feel free to ask for more information, because I can reproduce this problem very easily.
The problem is that I cannot convert Windows Server 2019 into a domain controller with Cloudbase-Init. This error happens EVERY TIME. I think that this is a big problem, because it makes cloudbase-init broken on Windows Server 2019 to create a Domain controller.
Is there a workaround? Thank you.
The text was updated successfully, but these errors were encountered: