Reputation: 14375
I am trying to create a Worker Role project for Windows Azure that loads a custom EXE upon startup. I adapted the code from David Chou's Jetty server example found here:
http://blogs.msdn.com/b/dachou/archive/2010/03/21/run-java-with-jetty-in-windows-azure.aspx
Using Visual Web Developer 2010, I created a new Cloud project for Visual C# and dropped in his Worker Role class code shown here:
namespace WorkerRole1
{
public class WorkerRole : RoleEntryPoint
{
public override void Run()
{
string response = "";
string S = "";
try
{
System.IO.StreamReader sr;
string port = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["HttpIn"].IPEndpoint.Port.ToString();
string roleRoot = Environment.GetEnvironmentVariable("RoleRoot");
S = "roleRoot is: " + roleRoot;
Trace.TraceInformation(S);
// string myAzureAppHome = roleRoot + @"\approot\app";
string myAzureAppHome = System.IO.Path.Combine(roleRoot + @"\", @"approot\");
S = "myAzureAppHome is: " + myAzureAppHome;
Trace.TraceInformation(S);
// string jreHome = roleRoot + @"\approot\app\jre6";
Process proc = new Process();
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
//proc.StartInfo.FileName = String.Format("\"{0}\\bin\\java.exe\"", jreHome);
// proc.StartInfo.Arguments = String.Format("-Djetty.port={0} -Djetty.home=\"{1}\" -jar \"{1}\\start.jar\"", port, myAzureAppHome);
proc.StartInfo.FileName = String.Format("\"{0}\\myAzureAppPRJ.exe\"", myAzureAppHome);
S = "Attempting to run file: " + proc.StartInfo.FileName;
Trace.TraceInformation(S);
proc.EnableRaisingEvents = false;
proc.Start();
sr = proc.StandardOutput;
response = sr.ReadToEnd();
}
catch (Exception ex)
{
response = ex.Message;
Trace.TraceError(response);
}
}
public override bool OnStart()
{
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
return base.OnStart();
}
}
}
The problem is that the directory I am getting back for the RoleRoot does not match where my "app" support files are showing up when I run the project against the storage emulator. The "app" folder ends up in this directory which I found by searching the WindowsAzureProject2 directory tree:
C:\Users\mycomp\Documents\Visual Studio 2010\Projects\WindowsAzureProject2\WorkerRole1\app
But GetEnvironmentVariable("RoleRoot") reports the following as the RoleRoot directory as dumped by my Trace statement:
C:\Users\mycomp\documents\visual studio 2010\Projects\WindowsAzureProject2\WindowsAzureProject2\bin\Debug\WindowsAzureProject2.csx\roles\WorkerRole1
Which of course leads to a file not found Exception when proc.Start() is called because the custom EXE file is in the former directory, and not the latter.
Can anyone tell my why the roleRoot path appears to be botched and what I can do to fix this? Note, I'm aware of the double backslash problem before the EXE in my assignment to proc.StartInfo.FileName (is Visual Web Developer C# different from Visual Studio Pro C#?), but fixing that would not change the path problem I am having since the directory being returned by GetEnvironmentVariable("RoleRoot") flat out does not contain my "app" directory.
UPDATE: After doing some more reading it appears to me that what's really happening is that the "approot" directory is not being created and my "app" folder files are not being copied over either. I still can't figure out why.
-- roschler
Upvotes: 1
Views: 1385
Reputation: 60143
Looks like you didn't add the files in the app directory to the Visual Studio project. Make sure they're added and have their "Copy to Output Directory" property set to "Copy Always" (or "Copy if Newer"). Then they should end up under %RoleRoot% like you expect.
Upvotes: 2