public void Restart(string serviceName) { _logger.Log(String.Format("Restarting service '{0}' ...", serviceName)); _serviceStopper.Stop(serviceName); _serviceStarter.Start(serviceName); _logger.Log(String.Format("Restart of service '{0}' successful.", serviceName)); }
public ExecutableResult Execute(string value) { try { Statics.ShouldPollXenStore = false; _logger.Log(String.Format("Updater Update value: {0}\r\nWill resume in 60 seconds", value)); _sleeper.Sleep(60); _connectionChecker.Check(); var agentUpdateInfo = _agentUpdateMessageHandler.Handle(value); _downloader.Download(agentUpdateInfo.url, Constants.UpdaterReleasePackage); _checksumValidator.Validate(agentUpdateInfo.signature, Constants.UpdaterReleasePackage); _unzipper.Unzip(Constants.UpdaterReleasePackage, Constants.UpdaterUnzipPath, ""); _serviceStopper.Stop("RackspaceCloudServersAgentUpdater"); _fileCopier.CopyFiles(Constants.UpdaterUnzipPath, Constants.UpdaterPath, _logger); _serviceStarter.Start("RackspaceCloudServersAgentUpdater"); Statics.ShouldPollXenStore = true; return(new ExecutableResult()); } catch (Exception ex) { _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", ex.Message, ex.StackTrace)); return(new ExecutableResult { Error = new List <string> { "Update failed" }, ExitCode = "1" }); } finally { _finalizer.Finalize(new List <string> { Constants.UpdaterUnzipPath, Constants.UpdaterReleasePackage }); } }
static void Main(string[] args) { System.ServiceModel.Activities.WorkflowServiceHost host = null; try { waitEvent = new AutoResetEvent(false); string baseAddr = "net.pipe://localhost/GuessingGame"; host = new System.ServiceModel.Activities.WorkflowServiceHost( new GuessingGame35Interop(), new Uri(baseAddr)); System.Workflow.Activities.ExternalDataExchangeService des = new System.Workflow.Activities.ExternalDataExchangeService(); ggService = new GuessingGameService(); ggService.MessageReceived += new EventHandler <MessageReceivedEventArgs>( Service_MessageReceived); des.AddService(ggService); WorkflowRuntimeEndpoint endpoint = new WorkflowRuntimeEndpoint(); endpoint.AddService(des); host.AddServiceEndpoint(endpoint); host.AddDefaultEndpoints(); ////configure persistence //string connectionString = ConfigurationManager.ConnectionStrings // ["InstanceStore"].ConnectionString; //SqlWorkflowInstanceStoreBehavior storeBehavior = // new SqlWorkflowInstanceStoreBehavior(connectionString); //host.Description.Behaviors.Add(storeBehavior); //WorkflowIdleBehavior idleBehavior = new WorkflowIdleBehavior(); //idleBehavior.TimeToUnload = TimeSpan.FromSeconds(0); //host.Description.Behaviors.Add(idleBehavior); host.Open(); IServiceStarter client = ChannelFactory <IServiceStarter> .CreateChannel( new NetNamedPipeBinding(), new EndpointAddress(baseAddr)); client.Start(); waitEvent.WaitOne(TimeSpan.FromMinutes(2)); Console.WriteLine("Program exiting..."); } catch (Exception exception) { Console.WriteLine("Unhandled exception: {0}", exception.Message); } finally { if (host != null) { host.Close(); } } }
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IServiceStarter starter, IDbSeeder seeder) { loggerFactory.AddDebug(); loggerFactory.AddSerilog(); app.UseExceptionHandler(options => { options.Run( async context => { context.Response.StatusCode = (int)HttpStatusCode.InternalServerError; var ex = context.Features.Get <IExceptionHandlerFeature>(); if (ex != null) { var err = $"Error: {ex.Error.Message}{ex.Error.StackTrace}"; Log.Error(ex.Error, "Server Error", ex); await context.Response.WriteAsync(err).ConfigureAwait(false); } }); }); app.UseCors("CorsPolicy"); seeder.Seed(Configuration.GetSection("AppSettings:ConnectionString").Value); starter.Start(); app.UseSwagger(); app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); app.UseAuthentication(); app.UseStatusCodePages(); app.UseStaticFiles(); app.UseDefaultFiles(); app.UseMvc(); }
public ExecutableResult Execute(string value) { var backupCreated = false; try { Statics.ShouldPollXenStore = false; string versionNumber = _versionChecker.Check(Version.AGENT_UPDATER_PATH); System.Version version; try { version = new System.Version(versionNumber); } catch (Exception ex) { _logger.Log(string.Format("Version check failed, installing embedded updater. Version Reported: {0} Stack Trace: {1}", versionNumber, ex)); version = new System.Version("0.0.0.0"); } if (version < UpdaterFiles.Updater.MinimumVersion) { _logger.Log(String.Format("Updating the Agent Updater... \r\nWill resume in 10 seconds...")); _sleeper.Sleep(10); _extractEmbededResource.Extract(SvcConfiguration.AgentVersionUpdatesPath, Constants.UpdaterEmbeddedReleasePackagePath, Constants.UpdaterReleasePackageName); _logger.Log("Waiting to unzip package."); _unzipper.Unzip(Constants.UpdaterReleasePackage, Constants.UpdaterUnzipPath, ""); _serviceStopper.Stop("RackspaceCloudServersAgentUpdater"); _backupUpdater.Backup(Constants.UpdaterPath, Constants.UpdaterBackupPath); backupCreated = true; _fileCopier.CopyFiles(Constants.UpdaterUnzipPath, Constants.UpdaterPath, _logger); } else { _logger.Log(string.Format("Agent Updater Version: {0} detected, not updating updater.", version)); } return(new ExecutableResult()); } catch (Exception ex) { try { if (backupCreated) { _serviceStopper.Stop("RackspaceCloudServersAgentUpdater"); _backupUpdater.Restore(Constants.UpdaterPath, Constants.UpdaterBackupPath); } } catch (Exception exRestore) { _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", exRestore.Message, exRestore.StackTrace)); } _logger.Log(String.Format("Exception was : {0}\nStackTrace Was: {1}", ex.Message, ex.StackTrace)); return(new ExecutableResult { Error = new List <string> { "Update failed" }, ExitCode = "1" }); } finally { Statics.ShouldPollXenStore = true; _serviceStarter.Start("RackspaceCloudServersAgentUpdater"); _finalizer.Finalize(new List <string> { Constants.UpdaterUnzipPath, Constants.UpdaterReleasePackage }); } }