WorkerRole.cs
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using Microsoft.WindowsAzure.Diagnostics;
using Microsoft.WindowsAzure.ServiceRuntime;
using System.IO;
using System.Xml;
namespace Tomcat
{
public class WorkerRole : RoleEntryPoint
{
/// <summary>
/// Run method to start tomcat process in the worker role instances
/// </summary>
public override void Run()
{
string tomcatLocation = RoleEnvironment.GetLocalResource("TomcatLocation").RootPath;
string phpLocation = RoleEnvironment.GetLocalResource("TomcatLocation").RootPath;
// Initalising RunTomcat
RunTomcat runTomcat = new RunTomcat();
// Calling StartTomcat method to start the tomcat process
runTomcat.StartTomcat(RoleEnvironment.GetLocalResource("TomcatLocation").RootPath
,RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Tomcat"].IPEndpoint.Port.ToString());
// Initalising RunPhp,RunMySQL
RunPhp runPhp = new RunPhp();
RunMySql runMySql = new RunMySql();
// Calling StartTomcat method to start the tomcat process
// runPhp.StartPhp(RoleEnvironment.GetLocalResource("TomcatLocation").RootPath
// , RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Phpcgi"].IPEndpoint.Port.ToString());
runPhp.StartPhp(RoleEnvironment.GetLocalResource("TomcatLocation").RootPath, "6666");
runMySql.StartMySql(RoleEnvironment.GetLocalResource("TomcatLocation").RootPath, "3306");
runTomcat.StartTomcatProcess(RoleEnvironment.GetLocalResource("TomcatLocation").RootPath);
while (true)
{
Thread.Sleep(10000);
Trace.WriteLine("Working", "Information");
}
}
/// <summary>
/// OnStart() which will start the DiagnosticMonitor
/// </summary>
/// <returns></returns>
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
DiagnosticMonitor.Start("DiagnosticsConnectionString");
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
RoleEnvironment.Changing += RoleEnvironmentChanging;
return base.OnStart();
}
/// <summary>
/// This method is to restart the role instance when a configuration setting is changing
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
{
// If a configuration setting is changing
if (e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange))
{
// Set e.Cancel to true to restart this role instance
e.Cancel = true;
}
}
}
}
最終更新:2010年12月06日 19:33