示例#1
0
        public static OutputQueue CopyApplicationBinContent(int timeOut)
        {
            var output = new OutputQueue();

            Parallel.ForEach(LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)),
                             server =>
            {
                if (SPWebService.ContentService.Instances.Any(p => p.Server.Id == server.Id) || SPWebService.AdministrationService.Instances.Any(p => p.Server.Id == server.Id))
                {
                    var command = string.Format(CultureInfo.InvariantCulture, @"{0} -o copyappbincontent", SPUtility.GetGenericSetupPath(@"bin\stsadm.exe"));

                    output.Add(string.Format(CultureInfo.CurrentUICulture, UserDisplay.RunningCommandOn, command, server.Address));

                    try
                    {
                        var processWMI = new Threading.ProcessWMI();
                        processWMI.ExecuteRemoteProcessWMI(server.Address, command, timeOut);
                    }
                    catch (Exception exception)
                    {
                        output.Add(string.Format(CultureInfo.CurrentUICulture, Exceptions.ExceptionRunningCommandOn, command, server.Address, exception.Message), OutputType.Error, exception.ToString(), exception);
                    }
                }
            });

            return(output);
        }
        internal static OutputQueue IsWMIAvailable(out bool isWMIAvailable)
        {
            var outputQueue = new OutputQueue();

            isWMIAvailable = true;

            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisite, UserDisplay.PrerequisiteWMIAvailable));
            try
            {
                var farm = LocalFarm.Get();
                foreach (var server in farm.Servers.Where(f => Server.ValidSPServerRole(f.Role)))
                {
                    var machineServices = ServiceController.GetServices(server.Address);
                    if (null == machineServices || machineServices.Length == 0)
                    {
                        isWMIAvailable = false;
                        outputQueue.Add("Unable to list services on server.", OutputType.Error, "Unable to list services on server: " + server.Address);
                        break;
                    }

                    // var command = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "where.exe");
                    // https://fogbugz.corp.newsgator.com/default.asp?304837
                    // Removing specific path and providing parameter for the where command
                    var command    = "where.exe iisreset.exe";
                    var processWMI = new Threading.ProcessWMI();
                    processWMI.ExecuteRemoteProcessWMI(server.Address, command, 15000);
                }
            }
            catch (Exception exception)
            {
                isWMIAvailable = false;
                outputQueue.Add(exception.Message, OutputType.Error, null, exception);
            }
            outputQueue.Add(string.Format(System.Globalization.CultureInfo.CurrentCulture, UserDisplay.CheckingPrerequisiteComplete, UserDisplay.PrerequisiteWMIAvailable, isWMIAvailable ? UserDisplay.CheckingPrerequisitePassed : UserDisplay.CheckingPrerequisiteFailed));

            return(outputQueue);
        }
示例#3
0
        internal static OutputQueue RestartServices(int timeOut)
        {
            var output = new OutputQueue();

            try
            {
                Parallel.ForEach(LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)),
                                 server =>
                {
                    var services = new Collection <string>()
                    {
                        "SPTimerV4", "SPAdminV4", "FIMService"
                    };
                    switch (LocalFarm.Get().BuildVersion.Major)
                    {
                    case 14:
                        services.Add("OSearch14");
                        services.Add("SPSearch4");
                        services.Add("WebAnalyticsService");
                        break;

                    case 15:
                        services.Add("OSearch15");
                        break;

                    case 16:
                        services.Add("OSearch16");
                        break;
                    }

                    ServiceController[] machineServices = ServiceController.GetServices(server.Address);

                    foreach (var serviceName in services)
                    {
                        try
                        {
                            var service = machineServices.FirstOrDefault(s => s.ServiceName == serviceName);
                            if (service != null)
                            {
                                output.Add(string.Format(CultureInfo.InvariantCulture, "Restarting {0} on {1}", serviceName, server.Address));
                                if (service.Status == ServiceControllerStatus.Running && service.CanStop)
                                {
                                    service.Stop();
                                    service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(90));
                                    service.Start();
                                    service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(90));
                                }
                            }
                        }
                        catch (InvalidOperationException) { }
                        catch (Exception exception)
                        {
                            output.Add(exception.Message, OutputType.Error, exception.ToString(), exception);
                        }
                    }

                    // Restart IIS
                    var command = string.Format(CultureInfo.InvariantCulture, @"{0} /restart", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "iisreset.exe"));
                    // var command = string.Format(CultureInfo.InvariantCulture, @"{0} /restart /noforce", Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.System), "iisreset.exe"));
                    // Removed /noforce

                    output.Add(string.Format(CultureInfo.CurrentUICulture, UserDisplay.RunningCommandOn, command, server.Address));

                    try
                    {
                        var processWMI = new Threading.ProcessWMI();
                        processWMI.ExecuteRemoteProcessWMI(server.Address, command, timeOut / 2);
                    }
                    catch (Exception exception)
                    {
                        output.Add(string.Format(CultureInfo.CurrentUICulture, Exceptions.ExceptionRunningCommandOn, command, server.Address, exception.Message), OutputType.Error, exception.ToString(), exception);
                    }
                });
            }
            catch (Exception exception)
            {
                output.Add(exception.Message, OutputType.Error, exception.ToString(), exception);
            }

            return(output);
        }
示例#4
0
        internal static OutputQueue ExecuteAdminServiceJobs(int timeOut)
        {
            var output = new OutputQueue();

            try
            {
                Parallel.ForEach(LocalFarm.Get().Servers.Where(p => Server.ValidSPServerRole(p.Role)),
                                 server =>
                {
                    ServiceController[] machineServices = ServiceController.GetServices(server.Address);

                    try
                    {
                        var service = machineServices.FirstOrDefault(s => s.ServiceName == AdminServiceName);
                        if (service != null)
                        {
                            output.Add(string.Format(CultureInfo.InvariantCulture, "Stopping {0} on {1}", AdminServiceName, server.Address));
                            if (service.Status == ServiceControllerStatus.Running && service.CanStop)
                            {
                                service.Stop();
                                service.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(90));
                            }
                        }
                    }
                    catch (InvalidOperationException) { }
                    catch (Exception exception)
                    {
                        output.Add(exception.Message, OutputType.Error, exception.ToString(), exception);
                    }

                    var command = string.Format(CultureInfo.InvariantCulture, @"{0} -o execadmsvcjobs", SPUtility.GetGenericSetupPath(@"bin\stsadm.exe"));

                    output.Add(string.Format(CultureInfo.CurrentUICulture, UserDisplay.RunningCommandOn, command, server.Address));

                    try
                    {
                        var processWMI = new Threading.ProcessWMI();
                        processWMI.ExecuteRemoteProcessWMI(server.Address, command, timeOut);
                    }
                    catch (Exception exception)
                    {
                        output.Add(string.Format(CultureInfo.CurrentUICulture, Exceptions.ExceptionRunningCommandOn, command, server.Address, exception.Message), OutputType.Error, exception.ToString(), exception);
                    }

                    // Start Admin Service
                    machineServices = ServiceController.GetServices();

                    try
                    {
                        var service = machineServices.FirstOrDefault(s => s.ServiceName == AdminServiceName);
                        if (service != null)
                        {
                            output.Add(string.Format(CultureInfo.InvariantCulture, "Starting {0} on {1}", AdminServiceName, server.Address));
                            if (service.Status == ServiceControllerStatus.Stopped)
                            {
                                service.Start();
                                service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(90));
                            }
                        }
                    }
                    catch (InvalidOperationException) { }
                    catch (Exception exception)
                    {
                        output.Add(exception.Message, OutputType.Error, exception.ToString(), exception);
                    }
                });
            }
            catch (Exception exception)
            {
                output.Add(exception.Message, OutputType.Error, exception.ToString(), exception);
            }

            return(output);
        }