Beispiel #1
0
        public Result Uninstall(string productCode)
        {
            Logger.Debug($"Uninstalling product {productCode}");
            var msiexec = FindFullPathToMsiExec();

            return(_processExecutor.ExecuteAndWaitForExit(msiexec, $"/qn /x {productCode}", LogInformation, LogError));
        }
Beispiel #2
0
        public Result Run(params string[] args)
        {
            var binDirectory = _fileSystem.FindInstallationDirectoryInPathContaining("chef-client.bat",
                                                                                     $@"{ServerSettings.Instance.InstallRoot}\opscode\chef\bin");
            var chefInstallDirectory = Directory.GetParent(binDirectory).FullName;
            var rubyExecutable       = RubyExecutableWithin(chefInstallDirectory);
            var chefClientLoaderFile = ChefClientLoaderWithin(chefInstallDirectory);

            var arguments = new List <string>()
            {
                chefClientLoaderFile
            };

            arguments.AddRange(args);
            var processArguments = string.Join(" ", arguments);

            Logger.Info($"Running {rubyExecutable} with arguments: {processArguments}");

            string filename = rubyExecutable;
            EventHandler <string> processOnOutputDataReceived = ProcessOnOutputDataReceived;
            EventHandler <string> processOnErrorDataReceived  = ProcessOnErrorDataReceived;

            return(_processExecutor.ExecuteAndWaitForExit(filename, processArguments, processOnOutputDataReceived,
                                                          processOnErrorDataReceived));
        }
Beispiel #3
0
        public ServiceStatus DetermineStatus(string serviceName)
        {
            _cachedOutput.Clear();
            var fullPath = _fileSystem.FindInstallationDirectoryInPathContaining(ServiceControllerExecutable, @"C:\windows\System32");

            _processExecutor.ExecuteAndWaitForExit(Path.Combine(fullPath, ServiceControllerExecutable),
                                                   $"query {serviceName}",
                                                   CacheLog, LogError);
            return(DetermineStateFromCachedOutput());
        }
Beispiel #4
0
        public void ExecuteAndWaitForExit_ShouldReturnFailureIfThrowsWin32Exception()
        {
            var process = new Mock <IProcess>();

            process.Setup(p => p.Start()).Throws <Win32Exception>();
            var processExecutor = new ProcessExecutor(() => process.Object);

            const string processName = "process.exe";
            var          result      = processExecutor.ExecuteAndWaitForExit(processName, "arg1 arg2", DoNothing, DoNothing);

            result.IsSuccess.Should().BeFalse("because the process executor threw an exception");
            result.FailureDescription.Should()
            .Be(
                $"Process {processName} could not run because it requires elevated privileges. Make sure the user running this server has the appropriate rights");
        }
Beispiel #5
0
        protected override Result RunCore(Argument[] args)
        {
            var descriptions       = ServiceStatusProvider.DescribeWindowsStatuses();
            var waitForDescription = descriptions[_waitFor];
            var fullPath           =
                _fileSystem.FindInstallationDirectoryInPathContaining(ServiceStatusProvider
                                                                      .ServiceControllerExecutable, @"C:\windows\System32");

            Presenter.ShowMessage($"Executing command to {_command} the service {_serviceName}", Logger);
            _processExecutor.ExecuteAndWaitForExit(
                Path.Combine(fullPath, ServiceStatusProvider.ServiceControllerExecutable),
                $"{_command} {_serviceName}",
                LogInformation, LogError);
            Presenter.ShowMessage($"Waiting for {_serviceName} to be {waitForDescription}", Logger);
            var status            = _serviceStatusWaiter.WaitFor(_waitFor);
            var statusDescription = descriptions[status];

            Presenter.ShowMessage($"Service {_serviceName} status is now {statusDescription}", Logger);
            return(status == _waitFor
                ? Result.Successful()
                : Result.Failure(
                       $"Expecting {_command} command to put the service in '{waitForDescription}' status but instead it is in '{statusDescription}' status."));
        }
Beispiel #6
0
 private Result DoCafeService(string verb)
 {
     return(_processExecutor.ExecuteAndWaitForExit(Path.Combine(_cafeApplicationDirectory, "cafe.exe"), $"service {verb}",
                                                   LogInformation, LogError));
 }