private static bool TryInstallAgent() { Logger.Info("Installing GCE Agent (version {0}).", ReleaseVersion); string backupPath = InstallerUtils.GetTempDirName(); try { // After version 3.1.0.0, we switched the service name and // display name for the agent. For back compatibility, we need // check both service name and display name here. if (ServiceController.GetServices().Any(x => x.ServiceName.Equals(ServiceName, StringComparison.InvariantCultureIgnoreCase) || x.DisplayName.Equals(ServiceName, StringComparison.InvariantCultureIgnoreCase))) { InstallerUtils.InstallBinaries( ReleaseVersion, AgentBinaries, AgentPath, backupPath, service: ServiceName); } else { InstallerUtils.InstallBinaries( ReleaseVersion, AgentBinaries, AgentPath, backupPath, service: null); InstallerUtils.RegisterService( string.Format(@"{0}\{1}", AgentPath, AgentBinaries[0]), ServiceName, ServiceDisplayName); using (ServiceController serviceController = new ServiceController(ServiceName)) { serviceController.Start(); serviceController.WaitForStatus(ServiceControllerStatus.Running); } } } catch (Exception e) { Logger.Error( "Failed to install GCE Agent (version {0}). Exception: {1}.", ReleaseVersion, e.ToString()); return(false); } finally { InstallerUtils.DeleteDir(backupPath); } Logger.Info("GCE Agent (version {0}) installation completed.", ReleaseVersion); return(true); }
private static void TryWriteRegistry() { try { InstallerUtils.WriteUpdateStatsKey(ApplicationId); InstallerUtils.WriteUpdateKey(ApplicationId, ReleaseVersion, ApplicationName); } catch (Exception ex) { // This branch should never happen when the installer is // executed by Omaha client. // However, if a user run the installer manually and does not // have access to HKLM, this step will fail. Logger.Error("Failed to write registry. Exception: {0}.", ex.ToString()); } }
private static bool TryInstallSysprep() { InstallerUtils.GetSources(ReleaseVersion, ComputeEnginePath); string sourcePath = Path.Combine(ComputeEnginePath, InstallerUtils.SourcePath); string sysprepSource = Path.Combine( sourcePath, string.Format(@"compute-image-windows-{0}", ReleaseVersion), "gce", SysprepDirectory); string[] sysprepFileNames = Directory.GetFiles(sysprepSource).Select(Path.GetFileName).ToArray(); string destPath = Path.Combine(ComputeEnginePath, SysprepDirectory); string backupPath = InstallerUtils.GetTempDirName(); try { InstallerUtils.ReplaceFiles( sysprepFileNames, sysprepSource, destPath, backupPath, suffix: string.Empty); } catch (Exception e) { Logger.Error( "Failed to install Sysprep (version {0}). Exception: {1}.", ReleaseVersion, e.ToString()); InstallerUtils.Rollback(sysprepFileNames, destPath, backupPath, service: null); return(false); } finally { InstallerUtils.CleanUp(sysprepFileNames, destPath); InstallerUtils.DeleteDir(sourcePath); InstallerUtils.DeleteDir(backupPath); } return(true); }