Adds clean service shutdown on Windows
This commit is contained in:
@@ -36,6 +36,7 @@ class InitManager(object):
|
|||||||
|
|
||||||
if self._is_already_configured(osutils):
|
if self._is_already_configured(osutils):
|
||||||
LOG.info('Host already configured, skipping configuration')
|
LOG.info('Host already configured, skipping configuration')
|
||||||
|
osutils.terminate()
|
||||||
return
|
return
|
||||||
|
|
||||||
plugins = plugins_factory.PluginFactory().load_plugins()
|
plugins = plugins_factory.PluginFactory().load_plugins()
|
||||||
@@ -68,3 +69,5 @@ class InitManager(object):
|
|||||||
osutils.reboot()
|
osutils.reboot()
|
||||||
except Exception, ex:
|
except Exception, ex:
|
||||||
LOG.error('reboot failed with error \'%s\'' % ex)
|
LOG.error('reboot failed with error \'%s\'' % ex)
|
||||||
|
|
||||||
|
osutils.terminate()
|
||||||
|
|||||||
@@ -66,3 +66,6 @@ class BaseOSUtils(object):
|
|||||||
|
|
||||||
def wait_for_boot_completion(self):
|
def wait_for_boot_completion(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def terminate(self):
|
||||||
|
pass
|
||||||
|
|||||||
@@ -62,6 +62,7 @@ class WindowsUtils(base.BaseOSUtils):
|
|||||||
ERROR_INVALID_MEMBER = 1388
|
ERROR_INVALID_MEMBER = 1388
|
||||||
|
|
||||||
_config_key = 'SOFTWARE\\Cloudbase Solutions\\Cloudbase-Init\\'
|
_config_key = 'SOFTWARE\\Cloudbase Solutions\\Cloudbase-Init\\'
|
||||||
|
_service_name = 'cloudbase-init'
|
||||||
|
|
||||||
def _enable_shutdown_privilege(self):
|
def _enable_shutdown_privilege(self):
|
||||||
process = win32process.GetCurrentProcess()
|
process = win32process.GetCurrentProcess()
|
||||||
@@ -299,3 +300,20 @@ class WindowsUtils(base.BaseOSUtils):
|
|||||||
'skipping sysprep completion check.')
|
'skipping sysprep completion check.')
|
||||||
else:
|
else:
|
||||||
raise ex
|
raise ex
|
||||||
|
|
||||||
|
def _stop_service(self, service_name):
|
||||||
|
LOG.debug('Stopping service %s' % service_name)
|
||||||
|
|
||||||
|
conn = wmi.WMI(moniker='//./root/cimv2')
|
||||||
|
service = conn.Win32_Service(Name=service_name)[0]
|
||||||
|
|
||||||
|
(ret_val,) = service.StopService()
|
||||||
|
if ret_val != 0:
|
||||||
|
raise Exception('Stopping service %(service_name)s failed with '
|
||||||
|
'return value: %(ret_val)d' % locals())
|
||||||
|
|
||||||
|
def terminate(self):
|
||||||
|
# Wait for the service to start. Polling the service "Started" property
|
||||||
|
# is not enough
|
||||||
|
time.sleep(3)
|
||||||
|
self._stop_service(self._service_name)
|
||||||
|
|||||||
Reference in New Issue
Block a user