Example #1
0
        public override void AfterDeploy(DeploymentContext context)
        {
            var logger = context.GetLoggerFor(this);
            if (!EnvironmentIsValidForPackage(context))
            {
                return;
            }

            // if no such service then install it
            using (var service = ServiceController.GetServices().SingleOrDefault(s => s.ServiceName == context.Package.Id))
            {
                if (service == null)
                {
                    var pathToExecutable = Path.Combine(context.TargetInstallationFolder, context.Package.Id + ".exe");
                    logger.InfoFormat("Installing service {0} from {1}", context.Package.Title, pathToExecutable);

                    System.Configuration.Install.ManagedInstallerClass.InstallHelper(new[] {pathToExecutable});
                }
            }

            using (var service = ServiceController.GetServices().SingleOrDefault(s => s.ServiceName == context.Package.Id))
            {
                // todo: recursively shut down dependent services
                if (!service.Status.Equals(ServiceControllerStatus.Stopped) &&
                    !service.Status.Equals(ServiceControllerStatus.StopPending))
                {
                    return;
                }

                ChangeServiceStateTo(service, ServiceControllerStatus.Running, service.Start, logger);
            }
        }
        public override void BeforeDeploy(DeploymentContext context, Action<ProgressReport> reportProgress)
        {
            var logger = context.GetLoggerFor(this);

            // find an app_online.htm file in the package
            var appOnline = context.Package.GetFiles().SingleOrDefault(f => f.Path.EndsWith(APP_ONLINE_FILE));

            if (appOnline == null)
            {
                return;
            }

            var tempFilePath = Path.Combine(context.WorkingFolder, appOnline.Path);
            var destinationFilePath = Path.Combine(context.TargetInstallationFolder, APP_OFFLINE_FILE);

            if (!File.Exists(tempFilePath))
            {
                return;
            }

            logger.Info("Copying app_offline.htm to destination");
            reportProgress(new ProgressReport(context, GetType(), "Copying app_offline.htm to destination"));

            if (!_fileSystem.Directory.Exists(Path.GetDirectoryName(destinationFilePath)))
            {
                _fileSystem.Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));
            }

            if (!_fileSystem.File.Exists(destinationFilePath))
            {
                _fileSystem.File.Copy(tempFilePath, destinationFilePath);
            }

            WaitForAppToUnload();
        }
 public override bool HookValidForPackage(DeploymentContext context)
 {
     Site site;
     LocateMsDeploy(context.GetLoggerFor(this));
     var iis7SiteInstance = FindIis7Website(context.Package.Title);
     return context.Package.Tags.ToLower().Split(' ', ',', ';').Contains("website")
            && !string.IsNullOrEmpty(MsWebDeployPath)
            && TryFindIis7Website(context.Package.Id, out site);
 }
Example #4
0
        public override void BeforeDeploy(DeploymentContext context)
        {
            var logger = context.GetLoggerFor(this);
            if (!EnvironmentIsValidForPackage(context))
            {
                return;
            }

            ShutdownRequiredServices(context, logger);
        }
 public override void BeforeDeploy(DeploymentContext context)
 {
     var logger = context.GetLoggerFor(this);
     var appPools = GetApplicationPoolsForWebsite(context.Package.Title);
     foreach (var appPool in appPools)
     {
         logger.InfoFormat("Stopping application pool {0}", appPool.Name);
         appPool.Stop();
     }
 }
        public override void AfterDeploy(DeploymentContext context)
        {
            var logger = context.GetLoggerFor(this);
            logger.Info("Removing app_offline.htm to destination");

            var appOfflineFilePath = Path.Combine(context.TargetInstallationFolder, APP_OFFLINE_FILE);

            if (_fileSystem.File.Exists(appOfflineFilePath))
            {
                _fileSystem.File.Delete(appOfflineFilePath);
            }
        }
Example #7
0
        public bool Deploy(string taskId, IPackage package, CancellationTokenSource cancellationToken, Action<ProgressReport> reportProgress)
        {
            var unpackFolder = Path.Combine(AgentSettings.AgentProgramDataPath, _agentSettingsManager.Settings.UnpackingLocation);
            var workingFolder = Path.Combine(unpackFolder, package.GetFullName());
            var targetInstallationFolder = Path.Combine(_agentSettingsManager.Settings.BaseInstallationPath, package.Id);
            using (var deploymentContext = new DeploymentContext(package, _agentSettingsManager, workingFolder, targetInstallationFolder, taskId))
            {

                var logger = deploymentContext.GetLoggerFor(this);
                var frameworks = package.GetSupportedFrameworks();
                foreach (var framework in frameworks)
                {
                    logger.DebugFormat("package supports {0}", framework.FullName);
                }

                try
                {
                    reportProgress(ProgressReport.Info(deploymentContext, this, package.Id,
                                                       package.Version.Version.ToString(), taskId,
                                                       "Extracting package to temp folder..."));
                    new NuGetPackageExtractor(Logger).Extract(package, workingFolder);
                }
                catch (Exception ex)
                {
                    logger.Fatal("Could not extract package", ex);
                }

                try
                {
                    BeforeDeploy(deploymentContext, reportProgress);
                    PerformDeploy(deploymentContext, reportProgress);
                    AfterDeploy(deploymentContext, reportProgress);

                    reportProgress(ProgressReport.Info(deploymentContext, this, package.Id,
                                                       package.Version.Version.ToString(), taskId,
                                                       "Deployment complete"));
                    return true;
                }
                catch (Exception ex)
                {
                    logger.Error("An error occurred", ex);
                    reportProgress(ProgressReport.Error(deploymentContext, this, package.Id,
                                                        package.Version.Version.ToString(), taskId,
                                                        "Deployment failed", ex));
                    return false;
                }
                finally
                {
                    deploymentContext.RemoveAppender();
                }
            }
        }
        public override void AfterDeploy(DeploymentContext context, Action<ProgressReport> reportProgress)
        {
            var logger = context.GetLoggerFor(this);
            logger.Info("Removing app_offline.htm from destination");
            reportProgress(new ProgressReport(context, GetType(), "Removing app_offline.htm from destination"));

            var appOfflineFilePath = Path.Combine(context.TargetInstallationFolder, APP_OFFLINE_FILE);

            if (_fileSystem.File.Exists(appOfflineFilePath))
            {
                _fileSystem.File.Delete(appOfflineFilePath);
            }
        }
 public override void AfterDeploy(DeploymentContext context, Action<ProgressReport> reportProgress)
 {
     var logger = context.GetLoggerFor(this);
     reportProgress(new ProgressReport(context, GetType(), "Starting application pool(s)"));
     var appPools = GetApplicationPoolsForWebsite(context.Package.Title);
     foreach(var appPool in appPools)
     {
         if (appPool.State == ObjectState.Stopped)
         {
             logger.InfoFormat("Starting application pool {0}", appPool.Name);
             appPool.Start();
         }
     }
 }
        public override void AfterDeploy(DeploymentContext context, Action<ProgressReport> reportProgress)
        {
            var logger = context.GetLoggerFor(this);
            if (!EnvironmentIsValidForPackage(context))
            {
                return;
            }

            reportProgress(new ProgressReport(context, GetType(), "Starting service"));

            var pathToExecutable = Path.Combine(Path.Combine(_serviceInstallationPath, context.Package.Id),
                                                context.Package.Id + ".exe");
            var serviceName = DetermineServiceName(context, pathToExecutable, logger);

            // if no such service then install it
            using (var service = GetServiceByNameOrDisplayName(serviceName))
            {
                if (service == null)
                {
                    logger.InfoFormat("Installing service {0} from {1}", serviceName, pathToExecutable);

                    ManagedInstallerClass.InstallHelper(new[] {pathToExecutable});
                    serviceName = DetermineServiceName(context, pathToExecutable, logger);
                }
            }

            // check that installation succeeded
            using (var service = GetServiceByNameOrDisplayName(serviceName))
            {
                // it didn't... installutil might be presenting a credentials dialog on the terminal
                if (service == null)
                {
                    throw new InstallException(
                        string.Format(
                            "The executable {0} was installed, so a service named '{1}' was expected but it could not be found",
                            Path.GetFileNameWithoutExtension(pathToExecutable), serviceName));
                }
            }

            using (var service = GetServiceByNameOrDisplayName(serviceName))
            {
                if (!service.Status.Equals(ServiceControllerStatus.Stopped) &&
                    !service.Status.Equals(ServiceControllerStatus.StopPending))
                {
                    return;
                }

                ChangeServiceStateTo(service, ServiceControllerStatus.Running, service.Start, logger);
            }
        }
Example #11
0
        protected void CopyAllFilesToDestination(DeploymentContext context)
        {
            var installationLogger = context.GetLoggerFor(this);
            // this is where file copy will occur
            var sourceFolder = new DirectoryInfo(Path.Combine(context.WorkingFolder, "content"));

            if (!Directory.Exists(context.TargetInstallationFolder))
            {
                Directory.CreateDirectory(context.TargetInstallationFolder);
            }

            CleanDestinationFolder(context, installationLogger);

            try
            {
                RecursiveCopy(sourceFolder, context.TargetInstallationFolder, installationLogger);
            }
            catch (Exception exception)
            {
                installationLogger.Fatal("Copy failed", exception);
            }
        }
        private void FindAndTransformAppropriateConfiguration(DeploymentContext context, Action<ProgressReport> reportProgress)
        {
            var installationLogger = context.GetLoggerFor(this);

            reportProgress(new ProgressReport(context, GetType(), "Transforming configuration files"));

            //  find base config files
            string baseConfigurationFileName = "app.config";
            string expectedTransformFileName = string.Format("app.{0}{1}",
                                                             AgentSettingsManager.Settings.DeploymentEnvironment,
                                                             Path.GetExtension(baseConfigurationFileName));
            string outputFileName = string.Format("{0}.exe.config", context.Package.Title);

            if (context.Package.Tags.ToLower().Split(' ', ',', ';').Contains("website"))
            {
                baseConfigurationFileName = "web.config";
                expectedTransformFileName = string.Format("web.{0}.config", AgentSettingsManager.Settings.DeploymentEnvironment);
                outputFileName = "web.config";
            }
            var baseConfigurationPath = Path.Combine(context.WorkingFolder + "\\config", baseConfigurationFileName);
            var transformFilePath = Path.Combine(context.WorkingFolder + "\\config", expectedTransformFileName);

            if (!File.Exists(baseConfigurationPath))
            {
                installationLogger.DebugFormat("Config file not found, expected {0}", baseConfigurationPath);
            }

            // find a matching transform
            if (File.Exists(transformFilePath))
            {
                var outputPath = Path.Combine(context.TargetInstallationFolder, outputFileName);
                var transformArgs = string.Format(@"--source=""{0}"" --transform=""{1}"" --destination=""{2}""",
                                                    baseConfigurationPath,
                                                    transformFilePath,
                                                    outputPath);
                RunProcess(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"tools\TransformVsConfiguration.exe"),
                            transformArgs, installationLogger);
            }
        }
        public override void AfterDeploy(DeploymentContext context)
        {
            var installationLogger = context.GetLoggerFor(this);
            //  find base config files
            if (context.Package.Tags.ToLower().Split(' ', ',', ';').Contains("website"))
            {
            }

            var configFiles = context.Package.GetFiles().Where(f=>f.Path.ToLower().StartsWith("config\\", StringComparison.InvariantCultureIgnoreCase));

            foreach(var configFile in configFiles)
            {
                var expectedTransformFileName = string.Format("{0}.{1}{2}",
                    Path.GetFileNameWithoutExtension(configFile.Path),
                    AgentSettings.DeploymentEnvironment,
                    Path.GetExtension(configFile.Path));

                var baseConfigurationPath = Path.Combine(context.WorkingFolder, configFile.Path);
                var transformFilePath = Path.Combine(context.WorkingFolder, Path.Combine(Path.GetDirectoryName(configFile.Path), expectedTransformFileName));
                var outputPath = Path.Combine(context.TargetInstallationFolder, configFile.Path);

                installationLogger.DebugFormat("looking for {0}", transformFilePath);

                if (File.Exists(transformFilePath))
                {
                    // todo: perform transform here
                    installationLogger.InfoFormat(@"Transform ""{0}"" using ""{1}"" to ""{2}""", baseConfigurationPath, transformFilePath, outputPath);
                    var transformArgs = string.Format(@"--source=""{0}"" --transform=""{1}"" --destination=""{2}""",
                        baseConfigurationPath,
                        transformFilePath,
                        outputPath);
                    RunProcess(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"tools\TransformVsConfiguration.exe"), transformArgs, installationLogger);
                }
                else
                {
                    installationLogger.DebugFormat("No transform found for {0}", baseConfigurationPath);
                }
            }
        }
 public override void Deploy(DeploymentContext context, Action<ProgressReport> reportProgress)
 {
     ExecuteScriptIfFoundInPackage(context, "deploy.ps1", context.GetLoggerFor(this), reportProgress);
 }
 public override void Deploy(DeploymentContext context)
 {
     var installationLogger = context.GetLoggerFor(this);
     LocateMsDeploy(installationLogger);
     DeployWebsite(
         "localhost",
         Path.Combine(context.WorkingFolder, "Content\\" + context.Package.Id + ".zip"),
         context.Package.Title,
         installationLogger,
         Ignore.AppOffline().And().LogFiles().And().MaintenanceFile());
 }
 public override void AfterDeploy(DeploymentContext context)
 {
     var installationLogger = context.GetLoggerFor(this);
     RestartApplication(context, installationLogger);
 }
 public override bool HookValidForPackage(DeploymentContext context)
 {
     DirectoryEntry website;
     LocateMsDeploy(context.GetLoggerFor(this));
     return context.Package.Tags.ToLower().Split(' ', ',', ';').Contains("website")
         && !string.IsNullOrEmpty(MsWebDeployPath)
         && TryFindWebsite("localhost", context.Package.Title, out website);
 }
Example #18
0
        private void ForEachHook(DeploymentContext context, string comment, Action<IDeploymentHook> action, Action<ProgressReport> reportProgress)
        {
            var installationLogger = context.GetLoggerFor(this);
            foreach (var hook in _hooks)
            {
                if (hook.HookValidForPackage(context))
                {
                    reportProgress(ProgressReport.InfoFormat(context, this, context.Package.Id, context.Package.Version.Version.ToString(), context.InstallationTaskId, "Running {0} hook {1}...", comment, hook.GetType().Name));

                    action(hook);
                }
                else
                {
                    installationLogger.DebugFormat("Skipping {0} for {1}", comment, hook.GetType());
                }
            }
        }
        public override void Deploy(DeploymentContext context, Action<ProgressReport> reportProgress)
        {
            reportProgress(new ProgressReport(context, GetType(), "Deploying website"));

            var installationLogger = context.GetLoggerFor(this);
            LocateMsDeploy(installationLogger);

            var applicationName = context.MetaData != null
                                      ? context.MetaData.IISPath
                                      : context.Package.Title;

            DeployWebsite(
                "localhost",
                Path.Combine(context.WorkingFolder, "Content\\" + context.Package.Id + ".zip"),
                applicationName,
                installationLogger,
                Ignore.AppOffline().And().LogFiles().And().MaintenanceFile());
        }
        public override void AfterDeploy(DeploymentContext context, Action<ProgressReport> reportProgress)
        {
            reportProgress(new ProgressReport(context, GetType(), "Starting website"));

            var installationLogger = context.GetLoggerFor(this);
            RestartApplication(context, installationLogger);
        }
Example #21
0
 public override void Deploy(DeploymentContext context)
 {
     ExecuteScriptIfFoundInPackage(context, "deploy.ps1", context.GetLoggerFor(this));
 }
        public override void BeforeDeploy(DeploymentContext context, Action<ProgressReport> reportProgress)
        {
            var logger = context.GetLoggerFor(this);
            if (!EnvironmentIsValidForPackage(context))
            {
                return;
            }

            reportProgress(new ProgressReport(context, GetType(), "Stopping service"));
            ShutdownRequiredServices(context, logger);
        }