/// <summary> /// Initializes button actions /// </summary> private void InitButtons() { btnClear.Visible = true; btnClearCache.Visible = true; btnRestart.Visible = true; btnRestartWebfarm.Visible = WebFarmButtonVisible; btnRestartServices.Visible = SystemContext.IsFullTrustLevel && WinServiceHelper.ServicesAvailable(); btnClearCounters.Visible = SystemContext.IsFullTrustLevel && LicenseHelper.CheckFeature(RequestContext.CurrentDomain, FeatureEnum.HealthMonitoring); }
/// <summary> /// Enables tasks after separation is over. /// </summary> private void EnableTasks() { if (ValidationHelper.GetBoolean(PersistentStorageHelper.GetValue("CMSSchedulerTasksEnabled"), false)) { SettingsKeyInfoProvider.SetGlobalValue("CMSSchedulerTasksEnabled", true); // Restart win service WinServiceHelper.RestartService(WinServiceHelper.HM_SERVICE_BASENAME, false); } PersistentStorageHelper.RemoveValue("CMSSchedulerTasksEnabled"); }
static void Main(string[] args) { try { #region 参数相关功能 if (args.Length != 0) { switch (args[0].ToUpper()) { case "/I": WinServiceHelper.InstallAndStart(FilePath, Name, Display, Description); return; case "/U": WinServiceHelper.Unstall(Name); return; default: Console.WriteLine("args:"); Console.WriteLine("\t/i\t\t 安装服务"); Console.WriteLine("\t/u\t\t 卸载服务"); return; } } else { try { #if DEBUG ConsoleStart(); #else VersionType = "WinService版"; _service = new SAEARESTEDService(); _service.Run(); #endif } catch (Exception ex) { SystemLoger("启动失败,原因:" + ex.Message + ex.Source); } } #endregion } catch (Exception ex) { SystemLoger("启动失败,原因:" + ex.Message + ex.Source); } }
/// <summary> /// Enables tasks after separation is over. /// </summary> private void EnableTasks() { if (ValidationHelper.GetBoolean(PersistentStorageHelper.GetValue("CMSSchedulerTasksEnabled"), false)) { SettingsKeyInfoProvider.SetGlobalValue("CMSSchedulerTasksEnabled", true); // Restart win service WinServiceItem def = WinServiceHelper.GetServiceDefinition(WinServiceHelper.HM_SERVICE_BASENAME); if (def != null) { WinServiceHelper.RestartService(def.GetServiceName()); } } PersistentStorageHelper.RemoveValue("CMSSchedulerTasksEnabled"); }
/// <summary> /// Stop tasks. /// </summary> void btnStopTasks_Click(object sender, EventArgs e) { // Stop tasks PersistentStorageHelper.SetValue("CMSSchedulerTasksEnabled", SettingsKeyInfoProvider.GetBoolValue("CMSSchedulerTasksEnabled")); if (SchedulingHelper.EnableScheduler) { SettingsKeyInfoProvider.SetGlobalValue("CMSSchedulerTasksEnabled", false); } WinServiceHelper.RestartService(WinServiceHelper.HM_SERVICE_BASENAME, false); // Display stopping progress iconHelp.Visible = btnStopTasks.Visible = false; DisplayStoppingTasks(); TasksManuallyStopped = true; }
/// <summary> /// Initializes header actions /// </summary> private void InitHeaderActions() { HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnRestart"), ButtonStyle = ButtonStyle.Primary, CommandName = "Restart", }); HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnRestartWebfarm"), ButtonStyle = ButtonStyle.Primary, CommandName = "RestartWebFarm", Visible = WebFarmButtonVisible, }); HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnClearCache"), ButtonStyle = ButtonStyle.Primary, CommandName = "ClearCache", }); HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnClearCounters"), ButtonStyle = ButtonStyle.Default, CommandName = "ClearCounters", Visible = SystemContext.IsFullTrustLevel && LicenseHelper.CheckFeature(RequestContext.CurrentDomain, FeatureEnum.HealthMonitoring), }); HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnClear"), ButtonStyle = ButtonStyle.Default, CommandName = "ClearMemory", }); HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnRestartServices"), ButtonStyle = ButtonStyle.Default, CommandName = "RestartServices", Visible = SystemContext.IsFullTrustLevel && WinServiceHelper.ServicesAvailable(), }); }
public static bool IsSeclogonWinServiceRunning() { var ret = false; var servName = "seclogon"; try { if (WinServiceHelper.GetStatus(servName) == (int)ServiceControllerStatus.Running //& WinServiceHelper.GetStartMode("seclogon") == (int)ServiceStartMode.Automatic ) { ret = true; } } catch (Exception ex) { return(false); } return(ret); }
/// <summary> /// Stop tasks. /// </summary> void btnStopTasks_Click(object sender, EventArgs e) { // Stop tasks PersistentStorageHelper.SetValue("CMSSchedulerTasksEnabled", SettingsKeyInfoProvider.GetBoolValue("CMSSchedulerTasksEnabled")); if (SchedulingHelper.EnableScheduler) { SettingsKeyInfoProvider.SetValue("CMSSchedulerTasksEnabled", false); } // Restart win service WinServiceItem def = WinServiceHelper.GetServiceDefinition(WinServiceHelper.HM_SERVICE_BASENAME); if (def != null) { WinServiceHelper.RestartService(def.GetServiceName()); } // Display stopping progress iconHelp.Visible = btnStopTasks.Visible = false; DisplayStoppingTasks(); TasksManuallyStopped = true; }
/// <summary> /// Initializes header actions /// </summary> private void InitHeaderActions() { HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnRestart"), ButtonStyle = ButtonStyle.Primary, CommandName = "Restart", }); HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnRestartWebfarm"), ButtonStyle = ButtonStyle.Default, CommandName = "RestartWebFarm", Visible = WebFarmButtonVisible, }); HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnClearCache"), ButtonStyle = ButtonStyle.Default, CommandName = "ClearCache", }); HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnClear"), ButtonStyle = ButtonStyle.Default, CommandName = "ClearMemory", }); HeaderActions.AddAction(new HeaderAction { Text = GetString("Administration-System.btnRestartServices"), ButtonStyle = ButtonStyle.Default, CommandName = "RestartServices", Visible = WinServiceHelper.ServicesAvailable(), }); }
private static void RunBatch() { Task.Run(() => { while (true) { try { if (__services.Count > 0) { foreach (var service in __services) { if (!WinServiceHelper.IsServiceInstalled(service)) { _log.Error($"service {service} not installed!"); } if (!WinServiceHelper.IsServiceRunning(service)) { _log.Error($"service {service} is down. now bring is up ."); WinServiceHelper.StartService(service); _log.Info( $"service {service} status is : {WinServiceHelper.ServiceStatus(service).ToString()}"); } } } } catch (Exception ex) { _log.Error(ex); } finally { Thread.Sleep(60000); } } }); }
/// <summary> /// Restart windows services. /// </summary> protected void RestartServices(object sender = null, EventArgs args = null) { if (StopProcessing) { return; } // Resets values of counters try { WinServiceHelper.RestartService(null); // Log event EventLogProvider.LogEvent(EventType.INFORMATION, "System", "RESTARTWINSERVICES", GetString("Administration-System.WinServicesRestarted")); } catch (Exception ex) { EventLogProvider.LogException("WinServiceHelper", "RestartService", ex); } string url = URLHelper.UpdateParameterInUrl(RequestContext.CurrentURL, "lastaction", "WinServicesRestarted"); URLHelper.Redirect(url); }
private static void RunBatch() { Task.Run(() => { while (true) { try { var now = DateTime.Now; //var nowMin = now.TimeOfDay.TotalMinutes; foreach (var service in __services) { var serviceName = service.Key; var serviceInfo = __services[serviceName]; if (serviceInfo.LastStartTime == DateTime.MinValue || (now - serviceInfo.LastStartTime).TotalMinutes > serviceInfo.RebootFrequency) { Print($"Stopping service {serviceName}"); __services[service.Key].LastStartTime = now; WinServiceHelper.StopService(serviceName); var counter = 0; while (counter <= 100) { if (WinServiceHelper.ServiceStatus(serviceName) == ServiceControllerStatus.Stopped) { break; } counter++; Thread.Sleep(10 * 1000); } Print($"Starting service {serviceName}"); while (true) { WinServiceHelper.StartService(serviceName); Thread.Sleep(10 * 1000); if (WinServiceHelper.ServiceStatus(serviceName) == ServiceControllerStatus.Running) { break; } } Print($"Done :{serviceName}"); } else { // Print($"{serviceName} last start : {serviceInfo.LastStartTime}"); // Print($" {(now-serviceInfo.LastStartTime).TotalMinutes} > {serviceInfo.RebootFrequency} ?"); //wait } } } catch (Exception ex) { Print(ex.Message); _log.Error(ex); } finally { Thread.Sleep(60000); } } }); }
public void GetServiceExePath() { string file = WinServiceHelper.GetExePath("DeployerServer"); string stop = ""; }
public void StopService() { WinServiceHelper.Stop("DeployerServer"); }
public void StartService() { WinServiceHelper.Start("DeployerServer"); }
protected void Page_Load(object sender, EventArgs e) { this.timRefresh.Interval = 1000 * ValidationHelper.GetInteger(this.drpRefresh.SelectedValue, 0); // Check permissions RaiseOnCheckPermissions("READ", this); if (StopProcessing) { return; } // Get values from counters long totalSystemRequests = RequestHelper.TotalSystemPageRequests.GetValue(null); long totalPageRequests = RequestHelper.TotalPageRequests.GetValue(null); long totalPageNotFoundRequests = RequestHelper.TotalPageNotFoundRequests.GetValue(null); long totalNonPageRequests = RequestHelper.TotalNonPageRequests.GetValue(null); long totalGetFileRequests = RequestHelper.TotalGetFileRequests.GetValue(null); // Reevaluate RPS if (mLastRPS != DateTime.MinValue) { double seconds = DateTime.Now.Subtract(mLastRPS).TotalSeconds; if ((seconds < 3) && (seconds > 0)) { mRPSSystemPageRequests = (totalSystemRequests - mLastSystemPageRequests) / seconds; mRPSPageRequests = (totalPageRequests - mLastPageRequests) / seconds; mRPSPageNotFoundRequests = (totalPageNotFoundRequests - mLastPageNotFoundRequests) / seconds; mRPSNonPageRequests = (totalNonPageRequests - mLastNonPageRequests) / seconds; mRPSGetFileRequests = (totalGetFileRequests - mLastGetFileRequests) / seconds; } else { mRPSGetFileRequests = -1; mRPSNonPageRequests = -1; mRPSPageNotFoundRequests = -1; mRPSPageRequests = -1; mRPSSystemPageRequests = -1; } } mLastRPS = DateTime.Now; // Update last values mLastGetFileRequests = totalGetFileRequests; mLastNonPageRequests = totalNonPageRequests; mLastPageNotFoundRequests = totalPageNotFoundRequests; mLastPageRequests = totalPageRequests; mLastSystemPageRequests = totalSystemRequests; // Do not count this page with async postback if (RequestHelper.IsAsyncPostback()) { RequestHelper.TotalSystemPageRequests.Decrement(null); } pnlSystemInfo.GroupingText = GetString("Administration-System.SystemInfo"); pnlSystemTime.GroupingText = GetString("Administration-System.SystemTimeInfo"); pnlDatabaseInfo.GroupingText = GetString("Administration-System.DatabaseInfo"); lblServerName.Text = GetString("Administration-System.ServerName"); lblServerVersion.Text = GetString("Administration-System.ServerVersion"); lblDBName.Text = GetString("Administration-System.DatabaseName"); lblDBSize.Text = GetString("Administration-System.DatabaseSize"); lblMachineName.Text = GetString("Administration-System.MachineName"); lblMachineNameValue.Text = HTTPHelper.MachineName; lblAspAccount.Text = GetString("Administration-System.Account"); lblValueAspAccount.Text = System.Security.Principal.WindowsIdentity.GetCurrent().Name; // Get application pool name lblPool.Text = GetString("Administration-System.Pool"); lblValuePool.Text = GetString("General.NA"); try { lblValuePool.Text = SystemHelper.GetApplicationPoolName(); } catch { } // Get application trust level lblTrustLevel.Text = GetString("Administration-System.TrustLevel"); lblValueTrustLevel.Text = GetString("General.NA"); try { lblValueTrustLevel.Text = SystemHelper.CurrentTrustLevel.ToString(); } catch { } lblAspVersion.Text = GetString("Administration-System.Version"); lblValueAspVersion.Text = System.Environment.Version.ToString(); pnlMemory.GroupingText = GetString("Administration-System.MemoryStatistics"); lblAlocatedMemory.Text = GetString("Administration-System.Memory"); lblPeakMemory.Text = GetString("Administration-System.PeakMemory"); lblVirtualMemory.Text = GetString("Administration-System.VirtualMemory"); lblPhysicalMemory.Text = GetString("Administration-System.PhysicalMemory"); lblIP.Text = GetString("Administration-System.IP"); pnlPageViews.GroupingText = GetString("Administration-System.PageViews"); lblPageViewsValues.Text = GetString("Administration-System.PageViewsValues"); lblPages.Text = GetString("Administration-System.Pages"); lblSystemPages.Text = GetString("Administration-System.SystemPages"); lblNonPages.Text = GetString("Administration-System.NonPages"); lblGetFilePages.Text = GetString("Administration-System.GetFilePages"); lblPagesNotFound.Text = GetString("Administration-System.PagesNotFound"); lblPending.Text = GetString("Administration-System.Pending"); pnlCache.GroupingText = GetString("Administration-System.CacheStatistics"); lblCacheExpired.Text = GetString("Administration-System.CacheExpired"); lblCacheRemoved.Text = GetString("Administration-System.CacheRemoved"); lblCacheUnderused.Text = GetString("Administration-System.CacheUnderused"); lblCacheItems.Text = GetString("Administration-System.CacheItems"); lblCacheDependency.Text = GetString("Administration-System.CacheDependency"); pnlGC.GroupingText = GetString("Administration-System.GC"); btnClear.Text = GetString("Administration-System.btnClear"); btnClearCache.Text = GetString("Administration-System.btnClearCache"); btnRestart.Text = GetString("Administration-System.btnRestart"); btnRestartWebfarm.Text = GetString("Administration-System.btnRestartWebfarm"); btnClearCounters.Text = GetString("Administration-System.btnClearCounters"); btnRestartServices.Text = GetString("Administration-System.btnRestartServices"); // Hide button if wefarms are not enabled or disallow restarting webfarms for Windows Azure if (!WebSyncHelperClass.WebFarmEnabled || AzureHelper.IsRunningOnAzure) { this.btnRestartWebfarm.Visible = false; } // Hide the web farm restart button if this web farm server is not enabled if (!RequestHelper.IsPostBack()) { WebFarmServerInfo webFarmServerObj = WebFarmServerInfoProvider.GetWebFarmServerInfo(WebSyncHelperClass.ServerName); if ((webFarmServerObj != null) && (!webFarmServerObj.ServerEnabled)) { this.btnRestartWebfarm.Visible = false; } } // Hide restart service button if services folder doesn't exist this.btnRestartServices.Visible = SystemHelper.IsFullTrustLevel && WinServiceHelper.ServicesAvailable(); // Hide the performance counters clear button if the health monitoring is not enabled or feature is not available this.btnClearCounters.Visible = SystemHelper.IsFullTrustLevel && LicenseHelper.CheckFeature(URLHelper.GetCurrentDomain(), FeatureEnum.HealthMonitoring); LoadData(); if (!RequestHelper.IsPostBack()) { switch (QueryHelper.GetString("lastaction", String.Empty).ToLower()) { case "restarted": lblInfo.Text = GetString("Administration-System.RestartSuccess"); break; case "webfarmrestarted": if (ValidationHelper.ValidateHash("WebfarmRestarted", QueryHelper.GetString("restartedhash", String.Empty))) { lblInfo.Text = GetString("Administration-System.WebframRestarted"); // Restart other servers - create webfarm task for application restart WebSyncHelperClass.CreateTask(WebFarmTaskTypeEnum.RestartApplication, "RestartApplication", "", null); } else { lblInfo.Text = GetString("general.actiondenied"); } break; case "countercleared": lblInfo.Text = GetString("Administration-System.CountersCleared"); break; case "winservicesrestarted": lblInfo.Text = GetString("Administration-System.WinServicesRestarted"); break; } } lblRunTime.Text = GetString("Administration.System.RunTime"); lblServerTime.Text = GetString("Administration.System.ServerTime"); // Remove miliseconds from the end of the time string string timeSpan = (DateTime.Now - CMSAppBase.ApplicationStart).ToString(); int index = timeSpan.LastIndexOf('.'); if (index >= 0) { timeSpan = timeSpan.Remove(index); } // Display application run time lblRunTimeValue.Text = timeSpan; lblServerTimeValue.Text = Convert.ToString(DateTime.Now) + " " + TimeZoneHelper.GetGMTStringOffset(TimeZoneHelper.ServerTimeZone); lblIPValue.Text = Request.UserHostAddress; }
/// <summary> /// Clears the cache to apply the settings to the web site. /// </summary> private void ClearCache(string keyName, object keyValue) { var clearCache = false; var clearOutputCache = false; var clearCSSCache = false; var clearPartialCache = false; string serviceBaseName = null; var serviceEnabled = false; // Clear the cached items switch (keyName.ToLowerCSafe()) { case "cmsemailsenabled": if ((mSiteId <= 0) && (keyValue.ToString().EqualsCSafe("false", true))) { // Stop current sending of e-mails and newsletters if e-mails are disabled in global settings EmailHelper.Queue.CancelSending(); ModuleCommands.CancelNewsletterSending(); } break; case "cmslogsize": // Log size changed EventLogProvider.Clear(); break; case "cmscacheminutes": case "cmscachepageinfo": case "cmscacheimages": case "cmsmaxcachefilesize": case "cmsdefaultaliaspath": case "cmsdefaultculturecode": case "cmscombinewithdefaultculture": // Clear cache upon change clearCache = true; break; case "cmspagekeywordsprefix": case "cmspagedescriptionprefix": case "cmspagetitleformat": case "cmspagetitleprefix": case "cmscontrolelement": case "cmsenableoutputcache": case "cmsfilesystemoutputcacheminutes": // Clear output cache upon change clearOutputCache = true; break; case "cmsenablepartialcache": // Clear output cache upon change clearPartialCache = true; break; case "cmsresourcecompressionenabled": case "cmsstylesheetminificationenabled": case "cmsresolvemacrosincss": // Clear the CSS styles clearCSSCache = true; break; case "cmsuseexternalservice": case "cmsservicehealthmonitoringinterval": case "cmsenablehealthmonitoring": // Restart Health Monitoring service { serviceBaseName = WinServiceHelper.HM_SERVICE_BASENAME; serviceEnabled = HealthMonitoringHelper.UseExternalService; // Clear status of health monitoring HealthMonitoringHelper.Clear(); } break; case "cmsprogressivecaching": CacheHelper.ProgressiveCaching = ValidationHelper.GetBoolean(keyValue, false); break; case "cmsscheduleruseexternalservice": case "cmsschedulerserviceinterval": case "cmsschedulertasksenabled": // Restart Scheduler service serviceBaseName = WinServiceHelper.SCHEDULER_SERVICE_BASENAME; serviceEnabled = SchedulingHelper.UseExternalService; break; case "cmsresizeimagestodevice": CacheHelper.TouchKey(DeviceProfileInfoProvider.DEVICE_IMAGE_CACHE_KEY); break; case "cmstranslationscomurl": case "cmstranslationscomusername": case "cmstranslationscompassword": case "cmstranslationscomprojectcode": AbstractHumanTranslationService.ClearHashtables(); break; case "cmsuseeventloglistener": if (ValidationHelper.GetBoolean(keyValue, false)) { EventLogSourceHelper.RegisterDefaultEventLogListener(); } else { EventLogSourceHelper.UnregisterDefaultEventLogListener(); } break; } // Clear the cache to apply the settings to the web site if (clearCache) { CacheHelper.ClearCache(null); } // Restart windows service else if (serviceBaseName != null) { try { WinServiceItem def = WinServiceHelper.GetServiceDefinition(serviceBaseName); if (def != null) { if (serviceEnabled) { WinServiceHelper.RestartService(def.GetServiceName()); } else { WinServiceHelper.DeleteServiceFile(def.GetServiceName()); } } } catch (Exception ex) { EventLogProvider.LogException("Settings", "RestartService", ex); } } else { // Clear only cache portions if (clearOutputCache) { CacheHelper.ClearFullPageCache(); } if (clearCSSCache) { CacheHelper.ClearCSSCache(); } if (clearPartialCache) { CacheHelper.ClearPartialCache(); } } }
public void GetLaunchType() { WinServiceHelper.GetLaunchType("W32Time"); }
public void IsExistByDisplayName() { bool isExist = WinServiceHelper.IsExistByDisplayName("Windows Time"); }
public void Install() { WinServiceHelper.Install(@"F:\John's Dir\Principal Project\更新发布工具\Deployer\beta0.1\DeployerServer\bin\Debug\DeployerServer.exe", "DeployerServer"); }
public void Uninstall() { WinServiceHelper.Unintall("DeployerUpdater"); }