Esempio n. 1
0
        //private void CopyResourceFiles(Assembly assembly, IEnumerable<string> resources, ServerConfig server, ConDepSettings settings)
        //{
        //    if (resources == null || assembly == null) return;

        //    var scriptPublisher = new PowerShellScriptPublisher(settings);
        //    scriptPublisher.PublishDslScripts(server);
        //}

        private void PublishConDepNode(ServerConfig server, ConDepSettings settings)
        {
            Logger.WithLogSection("Validating ConDepNode", () =>
            {
                string path;

                var executionPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "ConDepNode.exe");
                if (!File.Exists(executionPath))
                {
                    var currentPath = Path.Combine(Directory.GetCurrentDirectory(), "ConDepNode.exe");
                    if (!File.Exists(currentPath))
                    {
                        throw new FileNotFoundException("Could not find ConDepNode.exe. Paths tried: \n" +
                                                        executionPath + "\n" + currentPath);
                    }
                    path = currentPath;
                }
                else
                {
                    path = executionPath;
                }

                var nodeUrl = new ConDepNodeUrl(server, settings);

                var nodePublisher = new ConDepNodePublisher(path, Path.Combine(server.GetServerInfo().OperatingSystem.ProgramFilesFolder, "ConDepNode", Path.GetFileName(path)), nodeUrl);
                nodePublisher.Execute(server);
                if (!nodePublisher.ValidateNode(nodeUrl, server.DeploymentUser.UserName, server.DeploymentUser.Password, server))
                {
                    throw new ConDepNodeValidationException("Unable to make contact with ConDep Node or return content from API.");
                }

                Logger.Info(string.Format("ConDep Node successfully validated on {0}", server.Name));
                Logger.Info(string.Format("Node listening on {0}", nodeUrl.ListenUrl));
            });
        }
Esempio n. 2
0
        public override void Execute(ServerConfig server, IReportStatus status, ConDepSettings settings, CancellationToken token)
        {
            var canPingServer = CanPingServer(server);

            Logger.Verbose(string.Format("Can {0}use ping for validation", canPingServer ? "" : "NOT "));

            Logger.WithLogSection("Restarting", () =>
            {
                Logger.Info(string.Format("Executing restart command on server {0}", server.Name));
                var powershellExecutor = new PowerShellExecutor(server);
                powershellExecutor.Execute(string.Format("cmd /c \"shutdown /r /t {0}\"", _delayInSeconds));

                if (canPingServer)
                {
                    Logger.Verbose("Waiting for ping to fail");
                    Logger.Info("Waiting for server to stop responding");
                    WaitForPing(WaitForStatus.Failure, server);
                    Logger.Info("Server stopped responding");
                    Logger.Verbose("Waiting for ping to Succeed");
                    Logger.Info("Waiting for server to respond again");
                    WaitForPing(WaitForStatus.Success, server);
                    Logger.Info("Server started to respond");
                }
                else
                {
                    Logger.Verbose("Waiting for WinRM to fail");
                    Logger.Info("Waiting for server to stop responding");
                    WaitForWinRm(WaitForStatus.Failure, server);
                    Logger.Info("Server stopped responding");
                }
                Logger.Verbose("Waiting for WinRM to succeed");
                Logger.Info("Waiting for server to respond to PowerShell commands");
                WaitForWinRm(WaitForStatus.Success, server);
                Logger.Info("Serve successfully responds to PowerShell commands");
                Logger.Info("Computer successfully restarted");
                Logger.WithLogSection("Starting ConDepNode", () => ConDepNodePublisher.StartNode(server));
            });
        }