private static bool AllowDynamicPortsTraffic(string protocol, int startPort, int endPort) { string firewallRuleName = string.Format( CultureInfo.InvariantCulture, "Windows Fabric Dynamic Ports - {0} ({1})", protocol, RoleEnvironment.CurrentRoleInstance.Id); string deleteExistingRule = string.Format( CultureInfo.InvariantCulture, "advfirewall firewall delete rule name=\"{0}\"", firewallRuleName); string addAllowRule = string.Format( CultureInfo.InvariantCulture, "advfirewall firewall add rule name=\"{0}\" action=allow dir=in protocol={1} localport={2}-{3}", firewallRuleName, protocol, startPort, endPort); WindowsFabricAzureWrapperServiceCommon.ExecuteNetshCommand(deleteExistingRule); int exitCode = WindowsFabricAzureWrapperServiceCommon.ExecuteNetshCommand(addAllowRule); return(exitCode == 0); }
private static bool UninstallService(string pluginDirectory) { LogInfo("Uninstalling any previously installed version of Windows Fabric AzureWrapper Service."); ServiceController service = GetInstalledService(); if (service == null) { LogInfo("Windows Fabric AzureWrapper Service is not installed. Skip uninstalling."); return(true); } string serviceBinaryPath = Path.Combine(pluginDirectory, WindowsFabricAzureWrapperServiceCommon.WindowsFabricAzureWrapperBinaryName); LogInfo("Uninstalling Windows Fabric AzureWrapper Service from {0}", serviceBinaryPath); int exitCode = WindowsFabricAzureWrapperServiceCommon.UninstallService(serviceBinaryPath); LogInfo("Uninstallation returned with exit code {0}.", exitCode); service = GetInstalledService(); if (service == null) { LogInfo("Successfully uninstalled Windows Fabric AzureWrapper Service."); return(true); } LogError("Failed to uninstall Windows Fabric AzureWrapper Service."); return(false); }
// WindowsFabric AzureWrapper service should be restarted immediately upon failures private static bool SetServiceRecoveryOptions() { string command = Environment.ExpandEnvironmentVariables(@"%WINDIR%\System32\Sc.exe"); string arguments = string.Format(CultureInfo.InvariantCulture, "Failure {0} Reset= 0 Actions= Restart/0/Restart/0/Restart/0", WindowsFabricAzureWrapperServiceCommon.WindowsFabricAzureWrapperServiceName); LogInfo("Setting recovery options for WindowsFabricAzureWrapperService with command {0} {1}", command, arguments); int exitCode = WindowsFabricAzureWrapperServiceCommon.ExecuteCommand(command, arguments); LogInfo("Setting recovery options for WindowsFabricAzureWrapperService returns with exit code {0}", exitCode); return(exitCode == 0); }
private static bool ReduceDynamicPortRange(int startPort, int portCount, string networkInterface, string transportProtocol) { int exitCode = WindowsFabricAzureWrapperServiceCommon.ExecuteNetshCommand( string.Format( CultureInfo.InvariantCulture, "int {0} set dynamicport {1} start={2} num={3}", networkInterface, transportProtocol, startPort, portCount)); return(exitCode == 0); }
private static bool InstallAndStartService(string pluginDirectory) { string serviceBinaryPath = Path.Combine(pluginDirectory, WindowsFabricAzureWrapperServiceCommon.WindowsFabricAzureWrapperBinaryName); LogInfo("Installing Windows Fabric AzureWrapper Service from {0}", serviceBinaryPath); int exitCode = WindowsFabricAzureWrapperServiceCommon.InstallService(serviceBinaryPath); LogInfo("Installation returned with exit code {0}.", exitCode); ServiceController service = GetInstalledService(); if (service == null || !SetServiceRecoveryOptions()) { LogError("Failed to install Windows Fabric AzureWrapper Service and set recovery options for it."); return(false); } if (service.Status != ServiceControllerStatus.Running) { if (service.Status != ServiceControllerStatus.StartPending) { LogInfo("Windows Fabric AzureWrapper Service is not started yet. Starting it."); service.Start(); } service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromMinutes(WaitForServiceRunningTimeoutMinutes)); } if (service.Status == ServiceControllerStatus.Running) { LogInfo("Successfully started Windows Fabric AzureWrapper Service."); return(true); } LogError("Failed to start Windows Fabric AzureWrapper Service."); return(false); }
private static bool TryGetConfigurationSettingValueAsInt(string configurationSettingName, out int configurationSettingValue) { configurationSettingValue = 0; try { string configurationSettingValueStr = RoleEnvironment.GetConfigurationSettingValue(configurationSettingName); return(int.TryParse(configurationSettingValueStr, out configurationSettingValue)); } catch (Exception e) { if (WindowsFabricAzureWrapperServiceCommon.IsFatalException(e)) { throw; } return(false); } }
private static bool GetConfigurationSettingValueAsBool(string configurationSettingName, bool defaultConfigurationSettingValue) { bool configurationSettingValue; try { string configurationSettingValueStr = GetConfigurationSettingValue(configurationSettingName); configurationSettingValue = bool.Parse(configurationSettingValueStr); } catch (Exception e) { if (WindowsFabricAzureWrapperServiceCommon.IsFatalException(e)) { throw; } configurationSettingValue = defaultConfigurationSettingValue; } return(configurationSettingValue); }
private static TraceLevel GetConfigurationSettingValueAsTraceLevel(string configurationSettingName, string defaultConfigurationSettingValue) { TraceLevel configurationSettingValue; try { string configurationSettingValueStr = GetConfigurationSettingValue(configurationSettingName); configurationSettingValue = (TraceLevel)Enum.Parse(typeof(TraceLevel), configurationSettingValueStr, true); } catch (Exception e) { if (WindowsFabricAzureWrapperServiceCommon.IsFatalException(e)) { throw; } configurationSettingValue = (TraceLevel)Enum.Parse(typeof(TraceLevel), defaultConfigurationSettingValue, true); } return(configurationSettingValue); }
private static int GetConfigurationSettingValueAsInt(string configurationSettingName, int defaultConfigurationSettingValue) { int configurationSettingValue; try { string configurationSettingValueStr = GetConfigurationSettingValue(configurationSettingName); configurationSettingValue = int.Parse(configurationSettingValueStr, CultureInfo.InvariantCulture); } catch (Exception e) { if (WindowsFabricAzureWrapperServiceCommon.IsFatalException(e)) { throw; } configurationSettingValue = defaultConfigurationSettingValue; } return(configurationSettingValue); }
private static bool TryStartProcess(string pluginDirectory) { try { int currentRoleInstanceIndex = GetRoleInstanceIndex(RoleEnvironment.CurrentRoleInstance); string currentNodeName = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", RoleEnvironment.CurrentRoleInstance.Role.Name, currentRoleInstanceIndex); string minNodeName = GetMinNodeName(); if (string.IsNullOrEmpty(minNodeName)) { LogError("No roles have defined Windows Fabric endpoints."); return(false); } // only the role instance with the minimum node name in form of roleName.roleInstanceIndex will run WindowsFabric AzureWrapper Service as a process to start a scale-min WindowsFabric cluster if (string.Compare(currentNodeName, minNodeName, StringComparison.OrdinalIgnoreCase) == 0) { string serviceBinaryPath = Path.Combine(pluginDirectory, WindowsFabricAzureWrapperServiceCommon.WindowsFabricAzureWrapperBinaryName); string arguments = string.Empty; LogInfo("Starting Windows Fabric AzureWrapper Service as a process from {0}", serviceBinaryPath); bool succeeded = WindowsFabricAzureWrapperServiceCommon.TryStartProcess(serviceBinaryPath, arguments); LogInfo("Starting Windows Fabric AzureWrapper Service as a process {0}", succeeded ? "succeeded" : "failed"); return(succeeded); } return(true); } catch (Exception e) { LogError("Running occurred when starting Windows Fabric AzureWrapper Service as a process : {0}", e); return(false); } }
private static bool TryInstallVcRuntime(string pluginDirectory) { try { string installationCommand = Path.Combine(pluginDirectory, WindowsFabricAzureWrapperServiceCommon.Vc11RuntimeInstallerBinaryName); string arguments = "/q /norestart"; LogInfo("Installing VC 11 runtime with command {0} {1}", installationCommand, arguments); int exitCode = WindowsFabricAzureWrapperServiceCommon.ExecuteCommand(installationCommand, arguments, TimeSpan.FromMinutes(WaitForInstallationTimeoutMinutes)); LogInfo("Installing VC 11 runtime returns with exit code {0}", exitCode); return(exitCode == 0); } catch (Exception e) { LogError("Exception occurred when installing VC 11 runtime : {0}", e); return(false); } }
private static ServiceController GetInstalledService() { return(WindowsFabricAzureWrapperServiceCommon.GetInstalledService(WindowsFabricAzureWrapperServiceCommon.WindowsFabricAzureWrapperServiceName)); }