public static void CheckInstalledComponents() { // Check if CMP Service is installed if (CheckProductByUpgradeCode(SetupConstants.GetUpgradeCode(SetupFeatures.Server), true)) { SetupLogger.LogInfo("CheckInstalledComponents: CMP server found"); PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.ServerVersion, "1"); SetupInputs.Instance.EditItem(SetupInputTags.BinaryInstallLocationTag, SetupConstants.GetServerInstallPath()); } // Check if Tenant Extension is installed if (CheckProductByUpgradeCode(SetupConstants.GetUpgradeCode(SetupFeatures.TenantExtension), true)) { SetupLogger.LogInfo("CheckInstalledComponents: Tenant extension found"); PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.TenantExtensionVersion, "1"); SetupInputs.Instance.EditItem(SetupInputTags.BinaryInstallLocationTag, SetupConstants.GetTenantExtensionInstallPath()); } // Check if Extension Common Components are installed if (CheckProductByUpgradeCode(SetupConstants.GetUpgradeCode(SetupFeatures.ExtensionCommon), true)) { SetupLogger.LogInfo("CheckInstalledComponents: Extension common components found"); PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.ExtensionCommonVersion, "1"); SetupInputs.Instance.EditItem(SetupInputTags.BinaryInstallLocationTag, SetupConstants.GetExtensionCommonInstallPath()); } // Determine if the VMM WebPortal msi is already installed. if (CheckProductByUpgradeCode(SetupConstants.GetUpgradeCode(SetupFeatures.AdminExtension), true)) { SetupLogger.LogInfo("CheckInstalledComponents: Admin extension found"); PropertyBagDictionary.Instance.SafeAdd(PropertyBagConstants.AdminExtensionVersion, "1"); SetupInputs.Instance.EditItem(SetupInputTags.BinaryInstallLocationTag, SetupConstants.GetAdminExtensionInstallPath()); } return; }
/// <summary> /// Create the engine service and start it /// </summary> public static void ConfigureCMPWorkerService(ServiceConfigurationHandler serviceConfigurationHandler) { AppAssert.AssertNotNull(serviceConfigurationHandler, "serviceConfigurationHandler"); string installPath = SetupConstants.GetServerInstallPath(); //attempt to remove services first. //this will ignore errors of service does not exist and service marked for deletion //If service is marked for deletion, then exception will be thrown at create time as //we will be unable to create the service. //reason: //1. Keeps the code path of Install and Repair same //2. Handles corner case of service already existing in Install mode //3. Repairs the configuration of the service if broken IntPtr hSCManager = NativeMethods.NullIntPtr; IntPtr password = NativeMethods.NullIntPtr; try { hSCManager = ServiceConfigurationHandler.GetSCMHandle(); //TODO: Handle rollback if exception is thrown ServiceConfigurationHandler.StopAndRemoveService(hSCManager, SetupConstants.EngineServiceName); //construct paths to service binaries string servicePathEngine = PathHelper.QuoteString(installPath + @"MSIT\CmpWorkerService\" + SetupConstants.EngineServiceBinary); SetupLogger.LogInfo("BackEnd.Configure: Engine Service path is : {0}", servicePathEngine); //Get account string userAccountName = null; bool runasLocalAccount = SetupInputs.Instance.FindItem(SetupInputTags.CmpServiceLocalAccountTag); if (!runasLocalAccount) { userAccountName = UserAccountHelper.GetVmmServiceDomainAccount(); password = Marshal.SecureStringToGlobalAllocUnicode(SetupInputs.Instance.FindItem(SetupInputTags.CmpServiceUserPasswordTag)); } //create engine service ServiceConfigurationHandler.CreateService( hSCManager, SetupConstants.EngineServiceName, Resources.EngineServiceDisplayName, Resources.EngineServiceDescription, servicePathEngine, null, // dependent services userAccountName, password: password, autoStart: true, interactive: false); //set failure actions for VMMService NativeMethods.SERVICE_FAILURE_ACTIONS sfa = new NativeMethods.SERVICE_FAILURE_ACTIONS(); NativeMethods.SC_ACTION[] sca = new NativeMethods.SC_ACTION[SetupConstants.ServiceActionsCount + 1]; for (int i = 0; i < SetupConstants.ServiceActionsCount; i++) { sca[i].Delay = SetupConstants.ServiceRestartDelay; sca[i].Type = NativeMethods.SC_ACTION_TYPE.SC_ACTION_RESTART; } sca[SetupConstants.ServiceActionsCount].Delay = 0; sca[SetupConstants.ServiceActionsCount].Type = NativeMethods.SC_ACTION_TYPE.SC_ACTION_NONE; IntPtr unmanagedStructArray = NativeMethods.NullIntPtr; try { unmanagedStructArray = GetUnmanagedStructArray(sca); sfa.sc_Action = unmanagedStructArray; sfa.cActions = SetupConstants.ServiceActionsCount + 1; sfa.dwResetPeriod = SetupConstants.ServiceResetPeriod; sfa.lpCommand = null; sfa.lpRebootMsg = null; //set service failure actions for engine service ServiceConfigurationHandler.SetFailureActions(SetupConstants.EngineServiceName, ref sfa); //ConfigurationProgressEvent(this, new EventArgs()); } finally { if (NativeMethods.NullIntPtr != unmanagedStructArray) { Marshal.FreeHGlobal(unmanagedStructArray); } } } finally { if (!NativeMethods.NullIntPtr.Equals(hSCManager)) { NativeMethods.CloseServiceHandle(hSCManager); } if (!NativeMethods.NullIntPtr.Equals(password)) { Marshal.ZeroFreeGlobalAllocUnicode(password); } } }