开发者

Does OnStart() have a maximum time limit?

开发者 https://www.devze.com 2023-03-23 05:52 出处:网络
I\'m using the AzureRubyRails sln which is a WorkerRole that extends the RoleEntryPoint class. I have noticed that my app gets to a specific point (just before the copying) and then Azure decides to r

I'm using the AzureRubyRails sln which is a WorkerRole that extends the RoleEntryPoint class. I have noticed that my app gets to a specific point (just before the copying) and then Azure decides to restart the role without any reasoning in the Table log. Is it possible that I am exceeding my timelimit in OnStart?

public override bool OnStart()
{
    try
    {
        LogInfo("Worker Role OnStart Entered");

        RoleEnvironment.Changing += RoleEnvironmentChanging;

        DiagnosticMonitorConfiguration dmc = DiagnosticMonitor.GetDefaultInitialConfiguration();

        dmc.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1);
        dmc.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;

        DiagnosticMonitor.Start("DiagnosticsConnectionString", dmc);

        this.roleId = RoleEnvironment.CurrentRoleInstance.Id;
        string outputContainer = RoleEnvironment.GetConfigurationSettingValue("OutputContainer");
        CloudStorageAccount storageAccount = CloudStorageAccount.Parse(RoleEnvironment.GetConfigurationSettingValue("StorageAccount"));
        CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
        this.container = blobClient.GetContainerReference(outputContainer);
        this.container.CreateIfNotExist();

        BlobContainerPermissions permissions = this.container.GetPermissions();
        permissions.PublicAccess = BlobContainerPublicAccessType.Container;
        this.container.SetPermissions(permissions);

        //Get the local Storage resources 
        LocalResource disk = RoleEnvironment.GetLocalResource("App");

        //Copy files across (log files and database are writeable)

        DirectoryInfo localStorageRoot = new DirectoryInfo(disk.RootPath);

        //Get the root of this role

        this.roleRoot = System.Environment.GetEnvironmentVariable("RoleRoot");
        this.roleRoot += "\\approot";

        try
        {
            LogInfo("Starting Git extract");
            var proc = new Process
            {
                StartInfo = new ProcessStartInfo(string.Format("{0}\\Ruby\\7za.exe", this.roleRoot), "x -oGit -y Git.7z")
                {
                    UseShellExecute = false,
                    WorkingDirectory = string.Format("{0}\\Ruby", this.roleRoot)
                },
                EnableRaisingEvents = true
            };
            proc.Start();

            proc.WaitForExit();
        }
        catch (Exception fErr)
        {
            LogError(fErr.Message);
        }

        try
        {
            LogInfo("Starting Git clone");
            var proc = new Process
            {
                StartInfo = new ProcessStartInfo(string.Format("{0}\\Ruby\\git\\bin\\git.exe", this.roleRoot), string.Format("clone git://github.com/callumj/InPerthAzure.git web_app", this.roleRoot))
                {
                    UseShellExecute = false,
                    WorkingDirectory = string.Format("{0}\\Ruby", this.roleRoot)
                },
                EnableRaisingEvents = true
            };
            proc.Start();

            proc.WaitForExit();
        }
        catch (Exception fErr)
        {
            LogError(fErr.Message);
        }

        string rubyFolderName = RoleEnvironment.GetConfigurationSettingValue("RubyFolder");
        this.rubyLocation = string.Format("{0}\\{1}", localStorageRoot.FullName, rubyFolderName);

        string rubySrc = string.Format("{0}\\{1}", this.roleRoot, rubyFolderName);

        try
        {
            LogInfo("Starting Ruby extraction");
            var proc = new Process
            {
                StartInfo = new ProcessStartInfo(Path.Combine(rubySrc, @"Ruby"))
                {
                    UseShellExecute = false,
                    WorkingDirectory = rubySrc
                },
                EnableRaisingEvents = true
            };
            proc.Start();

            proc.WaitForExit();
        }
        catch (Exception fErr)
        {
            LogError(fErr.Message);
        }

        LogInfo("Beginning copy");
        CopyFolder(string.Format("{0}\\{1}", this.roleRoot, rubyFolderName), this.rubyLocation);

        string appFolderName = RoleEnvironment.GetConfigurationSettingValue("AppFolder");
        this.appLocation = string.Format("{0}\\{1}", localStorageRoot.FullName, appFolderName);
        //CopyFolder(string.Format("{0}\\{1}", this.roleRoot, appFolderName), this.appLocation);

        string memcacheFolderName = RoleEnvironment.GetConfigurationSettingValue("MemcacheFolder");
        this.memcacheLocation = string.Format("{0}\\{1}", localStorageRoot.FullName, memcacheFolderName);

        //Get the local endpoint 
        LogInfo("Acquiring endpoint");
        this.endPoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["Server"].IPEndpoint;

        // Start the server

        LogInfo("Beginning bootup");

        BootApp();

        LogInfo("Worker Role OnStart Exited");
    }
    catch (Exception err)
    {
        LogError(err.Message);
    }
    return base开发者_运维百科.OnStart();
}

I find it working well on my local developer compute emulator (but I'm assuming that doesn't mean much).


I suspect your code is crashing in the Role because some dependencies are missing. To troubleshoot this, I would try to split apart your code into a console application with a huge try/catch. I would then log onto the machine using RDP and just try to run the console app. This will give you your stack trace and allow you to figure out where you are failing. Just make sure you launch it from the same directory as your RoleEntryPoint so it has the same relative pathing.

But generally speaking, there is not a timeout in the OnStart() that you will run into. Your role will look perpetually busy and may be reported as 'unresponsive', but it will still be running the OnStart.

My general rule of thumb is that your OnStart and Startup tasks should take less than 20 mins to complete or you are doing too much.

Finally - since you are doing stuff with Git and whatnot - take a look at Steve's smarxrole (bing it), as it has all the startup stuff working and is a good starting point for this type of thing.

0

精彩评论

暂无评论...
验证码 换一张
取 消