public bool UninstallExtension(string id) { string installationDirectory = GetInstallationDirectory(id); if (!FileSystemHelpers.DirectoryExists(installationDirectory)) { throw new DirectoryNotFoundException(installationDirectory); } OperationManager.Attempt(() => { var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); } FileSystemHelpers.DeleteDirectorySafe(installationDirectory); }); return(!FileSystemHelpers.DirectoryExists(installationDirectory)); }
public bool UninstallExtension(string id) { string installationDirectory = GetInstallationDirectory(id); SiteExtensionInfo info = GetLocalExtension(id, checkLatest: false); if (info == null || !FileSystemHelpers.DirectoryExists(info.LocalPath)) { throw new DirectoryNotFoundException(installationDirectory); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } OperationManager.Attempt(() => CleanupSiteExtensionJobs(id)); OperationManager.Attempt(() => FileSystemHelpers.DeleteFileSafe(GetNuGetPackageFile(info.Id, info.Version))); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectorySafe(installationDirectory)); return(GetLocalExtension(id, checkLatest: false) == null); }
public async Task <bool> UninstallExtension(string id) { ITracer tracer = _traceFactory.GetTracer(); string installationDirectory = GetInstallationDirectory(id); SiteExtensionInfo info = await GetLocalExtension(id, checkLatest : false); if (info == null || !FileSystemHelpers.DirectoryExists(info.LocalPath)) { tracer.TraceError("Site extension {0} not found.", id); throw new DirectoryNotFoundException(installationDirectory); } if (IsInstalledToWebRoot(id)) { // special handling for package that install in wwwroot instead of under site extension folder tracer.Trace("Clear all content in wwwroot"); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectoryContentsSafe(_environment.WebRootPath)); } else { // default action for site extension uninstall // only site extension has below infomation var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { using (tracer.Step("Execute uninstall.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } using (tracer.Step("Remove site extension job")) { OperationManager.Attempt(() => CleanupSiteExtensionJobs(id)); } } using (tracer.Step("Delete site extension package, directory and arm settings")) { OperationManager.Attempt(() => FileSystemHelpers.DeleteFileSafe(GetNuGetPackageFile(info.Id, info.Version))); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectorySafe(installationDirectory)); SiteExtensionStatus armSettings = new SiteExtensionStatus(_environment.SiteExtensionSettingsPath, id, tracer); await armSettings.RemoveStatus(); } return(await GetLocalExtension(id, checkLatest : false) == null); }
/// <summary> /// <para>1. Download package</para> /// <para>2. Generate xdt file if not exist</para> /// <para>3. Deploy site extension job</para> /// <para>4. Execute install.cmd if exist</para> /// </summary> private async Task <UIPackageMetadata> InstallExtension(UIPackageMetadata package, string installationDirectory, string feedUrl) { ITracer tracer = _traceFactory.GetTracer(); try { if (FileSystemHelpers.DirectoryExists(installationDirectory)) { FileSystemHelpers.DeleteDirectorySafe(installationDirectory); } SourceRepository remoteRepo = GetRemoteRepository(feedUrl); // Copy content folder // Copy nupkg file for package list/lookup FileSystemHelpers.CreateDirectory(installationDirectory); // package path from local repo string packageLocalFilePath = GetNuGetPackageFile(package.Identity.Id, package.Identity.Version.ToString()); using (tracer.Step("Download site extension: {0}", package.Identity)) { await remoteRepo.DownloadPackageToFolder(package.Identity, installationDirectory, pathToLocalCopyOfNudpk : packageLocalFilePath); } // If there is no xdt file, generate default. using (tracer.Step("Check if applicationhost.xdt file existed.")) { GenerateApplicationHostXdt(installationDirectory, '/' + package.Identity.Id, isPreInstalled: false, tracer: tracer); } using (tracer.Step("Trigger site extension job")) { OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Identity.Id)); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { using (tracer.Step("Execute install.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } } catch (Exception ex) { tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return(await _localRepository.GetLatestPackageById(package.Identity.Id)); }
public static void Chmod(string permission, string filePath, IEnvironment environment, IDeploymentSettingsManager deploymentSettingManager, ILogger logger) { var folder = Path.GetDirectoryName(filePath); var exeFactory = new ExternalCommandFactory(environment, deploymentSettingManager, null); Executable exe = exeFactory.BuildCommandExecutable("/bin/chmod", folder, deploymentSettingManager.GetCommandIdleTimeout(), logger); exe.Execute("{0} \"{1}\"", permission, filePath); }
private IPackage InstallExtension(IPackage package, string installationDirectory) { try { if (FileSystemHelpers.DirectoryExists(installationDirectory)) { FileSystemHelpers.DeleteDirectorySafe(installationDirectory); } foreach (IPackageFile file in package.GetContentFiles()) { // It is necessary to place applicationHost.xdt under site extension root. string contentFilePath = file.Path.Substring("content/".Length); string fullPath = Path.Combine(installationDirectory, contentFilePath); FileSystemHelpers.CreateDirectory(Path.GetDirectoryName(fullPath)); using (Stream writeStream = FileSystemHelpers.OpenWrite(fullPath), readStream = file.GetStream()) { OperationManager.Attempt(() => readStream.CopyTo(writeStream)); } } // If there is no xdt file, generate default. GenerateApplicationHostXdt(installationDirectory, '/' + package.Id, isPreInstalled: false); OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Id)); var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } // Copy nupkg file for package list/lookup FileSystemHelpers.CreateDirectory(installationDirectory); string packageFilePath = GetNuGetPackageFile(package.Id, package.Version.ToString()); using ( Stream readStream = package.GetStream(), writeStream = FileSystemHelpers.OpenWrite(packageFilePath)) { OperationManager.Attempt(() => readStream.CopyTo(writeStream)); } } catch (Exception ex) { ITracer tracer = _traceFactory.GetTracer(); tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return(_localRepository.FindPackage(package.Id)); }
protected void RunJobInstance(JobBase job, IJobLogger logger, string runId) { string scriptFileName = Path.GetFileName(job.ScriptFilePath); string scriptFileExtension = Path.GetExtension(job.ScriptFilePath); logger.LogInformation("Run script '{0}' with script host - '{1}'".FormatCurrentCulture(scriptFileName, job.ScriptHost.GetType().Name)); string siteMode = Settings.GetWebSitePolicy(); _analytics.JobStarted(job.Name.Fuzz(), scriptFileExtension, job.JobType, siteMode); try { var exe = _externalCommandFactory.BuildCommandExecutable(job.ScriptHost.HostPath, WorkingDirectory, IdleTimeout, NullLogger.Instance); // Set environment variable to be able to identify all processes spawned for this job exe.EnvironmentVariables[GetJobEnvironmentKey()] = "true"; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsRootPath] = WorkingDirectory; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsName] = job.Name; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsType] = job.JobType; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsDataPath] = JobDataPath; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsRunId] = runId; exe.EnvironmentVariables[WellKnownEnvironmentVariables.WebJobsExtraUrlPath] = JobsManagerBase.GetJobExtraInfoUrlFilePath(JobDataPath); UpdateStatus(logger, "Running"); int exitCode = exe.ExecuteReturnExitCode( TraceFactory.GetTracer(), logger.LogStandardOutput, logger.LogStandardError, job.ScriptHost.ArgumentsFormat, job.RunCommand); if (exitCode != 0) { logger.LogError("Job failed due to exit code " + exitCode); } else { UpdateStatus(logger, "Success"); } } catch (Exception ex) { if (ex is ThreadAbortException) { // We kill the process when refreshing the job logger.LogInformation("Job aborted"); UpdateStatus(logger, "Aborted"); return; } logger.LogError(ex.ToString()); } }
public async Task <bool> UninstallExtension(string id) { ITracer tracer = _traceFactory.GetTracer(); string installationDirectory = GetInstallationDirectory(id); SiteExtensionInfo info = await GetLocalExtension(id, checkLatest : false); if (info == null || !FileSystemHelpers.DirectoryExists(info.LocalPath)) { tracer.TraceError("Site extension {0} not found.", id); throw new DirectoryNotFoundException(installationDirectory); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string uninstallScript = Path.Combine(installationDirectory, _uninstallScriptName); if (FileSystemHelpers.FileExists(uninstallScript)) { using (tracer.Step("Execute uninstall.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(uninstallScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } using (tracer.Step("Remove site extension job")) { OperationManager.Attempt(() => CleanupSiteExtensionJobs(id)); } using (tracer.Step("Delete site extension package and directory")) { OperationManager.Attempt(() => FileSystemHelpers.DeleteFileSafe(GetNuGetPackageFile(info.Id, info.Version))); OperationManager.Attempt(() => FileSystemHelpers.DeleteDirectorySafe(installationDirectory)); } return(await GetLocalExtension(id, checkLatest : false) == null); }
/// <summary> /// <para>1. Download package</para> /// <para>2. Generate xdt file if not exist</para> /// <para>3. Deploy site extension job</para> /// <para>4. Execute install.cmd if exist</para> /// </summary> private async Task <UIPackageMetadata> InstallExtension(UIPackageMetadata package, string installationDirectory, SourceRepository remoteRepo, SiteExtensionInfo.SiteExtensionType type, ITracer tracer, string installationArgs) { try { EnsureInstallationEnviroment(installationDirectory, tracer); string packageLocalFilePath = GetNuGetPackageFile(package.Identity.Id, package.Identity.Version.ToNormalizedString()); bool packageExisted = FileSystemHelpers.DirectoryExists(installationDirectory); using (tracer.Step("Download site extension: {0}", package.Identity)) { string extractPath = installationDirectory; if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { extractPath = _environment.WebRootPath; FileSystemHelpers.EnsureDirectory(extractPath); } // Copy/update content folder // Copy/update nupkg file for package list/lookup if (packageExisted) { await remoteRepo.UpdateLocalPackage(_localRepository, package.Identity, extractPath, packageLocalFilePath, tracer); } else { FileSystemHelpers.EnsureDirectory(installationDirectory); await remoteRepo.DownloadPackageToFolder(package.Identity, extractPath, packageLocalFilePath); } if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { // if install to WebRoot, check if there is any xdt or scmXdt file come with package // if there is, move it to site extension folder string xdtFile = Path.Combine(extractPath, Constants.ApplicationHostXdtFileName); string scmXdtFile = Path.Combine(extractPath, Constants.ScmApplicationHostXdtFileName); bool findXdts = false; if (FileSystemHelpers.FileExists(xdtFile)) { tracer.Trace("Use xdt file from package."); string newXdtFile = Path.Combine(installationDirectory, Constants.ApplicationHostXdtFileName); tracer.Trace("Moving {0} to {1}", xdtFile, newXdtFile); FileSystemHelpers.MoveFile(xdtFile, newXdtFile); findXdts = true; } // if the siteextension applies to both main site and the scm site if (FileSystemHelpers.FileExists(scmXdtFile)) { tracer.Trace("Use scmXdt file from package."); string newScmXdtFile = Path.Combine(installationDirectory, Constants.ScmApplicationHostXdtFileName); tracer.Trace("Moving {0} to {1}", scmXdtFile, newScmXdtFile); FileSystemHelpers.MoveFile(scmXdtFile, newScmXdtFile); findXdts = true; } if (!findXdts) { tracer.Trace("No xdt file come with package."); } } } // ignore below action if we install packge to wwwroot if (SiteExtensionInfo.SiteExtensionType.WebRoot != type) { using (tracer.Step("Check if applicationHost.xdt or scmApplicationHost.xdt file existed.")) { GenerateDefaultScmApplicationHostXdt(installationDirectory, '/' + package.Identity.Id, tracer: tracer); } using (tracer.Step("Trigger site extension job")) { OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Identity.Id)); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { using (tracer.Step("Execute install.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), installationArgs ?? String.Empty); }); } } } } catch (Exception ex) { tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return(await _localRepository.GetLatestPackageByIdFromSrcRepo(package.Identity.Id)); }
/// <summary> /// <para>1. Download package</para> /// <para>2. Generate xdt file if not exist</para> /// <para>3. Deploy site extension job</para> /// <para>4. Execute install.cmd if exist</para> /// </summary> private async Task <UIPackageMetadata> InstallExtension(UIPackageMetadata package, string installationDirectory, string feedUrl, SiteExtensionInfo.SiteExtensionType type, ITracer tracer) { try { if (FileSystemHelpers.DirectoryExists(installationDirectory)) { FileSystemHelpers.DeleteDirectorySafe(installationDirectory); } SourceRepository remoteRepo = GetRemoteRepository(feedUrl); // Copy content folder // Copy nupkg file for package list/lookup FileSystemHelpers.CreateDirectory(installationDirectory); // package path from local repo string packageLocalFilePath = GetNuGetPackageFile(package.Identity.Id, package.Identity.Version.ToString()); using (tracer.Step("Download site extension: {0}", package.Identity)) { string extractPath = installationDirectory; if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { extractPath = _environment.WebRootPath; FileSystemHelpers.EnsureDirectory(extractPath); } await remoteRepo.DownloadPackageToFolder(package.Identity, extractPath, pathToLocalCopyOfNudpk : packageLocalFilePath); if (SiteExtensionInfo.SiteExtensionType.WebRoot == type) { // if install to WebRoot, check if there is any xdt file come with package // if there is one, move it to site extension folder string xdtFile = Path.Combine(extractPath, Constants.ApplicationHostXdtFileName); if (File.Exists(xdtFile)) { tracer.Trace("Use xdt file from package."); string newXdtFile = Path.Combine(installationDirectory, Constants.ApplicationHostXdtFileName); tracer.Trace("Moving {0} to {1}", xdtFile, newXdtFile); FileSystemHelpers.MoveFile(xdtFile, newXdtFile); } else { tracer.Trace("No xdt file come with package."); } } } // ignore below action if we install packge to wwwroot if (SiteExtensionInfo.SiteExtensionType.WebRoot != type) { // If there is no xdt file, generate default. using (tracer.Step("Check if applicationhost.xdt file existed.")) { GenerateApplicationHostXdt(installationDirectory, '/' + package.Identity.Id, isPreInstalled: false, tracer: tracer); } using (tracer.Step("Trigger site extension job")) { OperationManager.Attempt(() => DeploySiteExtensionJobs(package.Identity.Id)); } var externalCommandFactory = new ExternalCommandFactory(_environment, _settings, installationDirectory); string installScript = Path.Combine(installationDirectory, _installScriptName); if (FileSystemHelpers.FileExists(installScript)) { using (tracer.Step("Execute install.cmd")) { OperationManager.Attempt(() => { Executable exe = externalCommandFactory.BuildCommandExecutable(installScript, installationDirectory, _settings.GetCommandIdleTimeout(), NullLogger.Instance); exe.ExecuteWithProgressWriter(NullLogger.Instance, _traceFactory.GetTracer(), String.Empty); }); } } } } catch (Exception ex) { tracer.TraceError(ex); FileSystemHelpers.DeleteDirectorySafe(installationDirectory); throw; } return(await _localRepository.GetLatestPackageById(package.Identity.Id)); }