private void tsmiRedeployUpdate_Click(object sender, EventArgs e) { if (tvManager.SelectedNode == null || tvManager.SelectedNode.Tag is Business.Server == false) { return; } Business.Server server = (Business.Server)tvManager.SelectedNode.Tag; if (MessageBox.Show("Would you like to update " + server.ServerName + " with your copy of MemCacheD?\n(This will restart all currently running instances of MemCacheD on this server.)", "Update MemCacheD", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK) { Cursor = Cursors.WaitCursor; try { foreach (Business.Instance instance in server.Instances) { SetStatusLabel("Stopping instance: " + instance.DisplayName + " on server: " + server.ServerName); instance.Stop(server, SetStatusLabel); } List <string> pushedImages = new List <string>(); foreach (Business.Instance instance in server.Instances) { if (pushedImages.Contains(instance.ImageBasePath) == false) { SetStatusLabel("Sending new software version to server: " + server.ServerName); server.EnsureExecutableIsAvailabeOnServer(instance.ImageBasePath, true); pushedImages.Add(instance.ImageBasePath); } } foreach (Business.Instance instance in server.Instances) { SetStatusLabel("Starting instance: " + instance.DisplayName + " on server: " + server.ServerName); instance.Start(server, SetStatusLabel); } ResetInstanceMonitor(); SetStatusLabel("Refreshing stats."); _instanceMonitor.RefreshServerStatistics(); } finally { SetStatusLabel("Ready."); Cursor = Cursors.Default; } } }
//private string _serviceUserName; //private string _servicePassword; internal void UpdateInstanceOnServer(Business.Server server, SetStatusLabelDelegate setStatusLabelDelegate) { //ImpersonateUser impersonateUser = null; try { //if (server.UseImpersonation == true) //{ // setStatusLabelDelegate("Impersonating user: "******"Checking MemCacheD.exe on remote server."); string binaryPath = server.EnsureExecutableIsAvailabeOnServer(false); string userName = null; string password = null; if (server.UseImpersonation == true) { userName = server.UserName; password = Encryption.Decrypt(server.Password); } setStatusLabelDelegate("Updating service on remote server."); WmiService.CreateOrUpdate(server.ServerName, userName, password, this.ServiceName, this.DisplayName, this.CreateImagePath(), StartMode.Auto, null, null); } finally { //if (impersonateUser != null && impersonateUser.IsImpersonating == true) // impersonateUser.Undo(); } /* * string description = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + _serviceController.ServiceName).GetValue("Description").ToString(); * string imagePath = Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + _serviceController.ServiceName).GetValue("ImagePath").ToString(); * string newImagePath = imagePath.Substring(0, imagePath.LastIndexOf("memcached.exe") + ((string)("memcached.exe")).Length); * * int tcpPort; * if (int.TryParse(txtTcpPort.Text, out tcpPort) == true) * newImagePath += " -p " + tcpPort; * * int udpPort; * if (int.TryParse(txtUdpPort.Text, out udpPort) == true) * newImagePath += " -U " + udpPort; * * if (chkMaximizeCoreFile.Checked == true) * newImagePath += " -r"; * * int maxMemory; * if (int.TryParse(txtMemoryLimit.Text, out maxMemory) == true) * newImagePath += " -m " + maxMemory; * * Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + _serviceController.ServiceName, true).SetValue("ImagePath", newImagePath); * * Registry.LocalMachine.OpenSubKey(@"SYSTEM\CurrentControlSet\Services\" + _serviceController.ServiceName, true).SetValue("DisplayName", txtInstanceName.Text); * * bool requiresRestart = false; * if (_serviceController.Status == ServiceControllerStatus.Running) * { * requiresRestart = true; * lblStatus.Text = "Stopping " + txtInstanceName.Text; * Refresh(); * * _serviceController.Stop(); * } * * lblStatus.Text = "Removing " + _serviceController.DisplayName; * Refresh(); * ServiceUtility.UninstallService(_serviceController.ServiceName); * * lblStatus.Text = "Reinstalling " + txtInstanceName.Text; * Refresh(); * ServiceUtility.InstallService(_serviceController.ServiceName, txtInstanceName.Text, description, newImagePath); * * if (requiresRestart == true) * { * lblStatus.Text = "Starting " + txtInstanceName.Text; * Refresh(); * _serviceController.Start(); * } * * lblStatus.Text = "Ready."; * */ }