问题
I've deployed an Azure service - once in a while I see in my logs that OnStop()
is called, then after about 20 minutes OnStart()
is called. I'd like to know why that's happening.
How can I know whether my role is restarted manually or by Azure runtime?
回答1:
Can you explain what you mean by restarted manually? Is that someone logging in via RDP and hitting reboot?
You only have a few options that can trigger a reboot:
- Someone logged in via RDP and literally rebooted. No way to track that one. Turn off RDP if you are worried about that being a common scenario. I am not sure OnStop would even be called here.
- The fabric controller shuts down the instance to a.) patch the guest OS if allowed (specifying * as guest OS version) or b.) patch the root OS occasionally. You can most likely track this from looking at the infrastructure logs. Setup diagnostics to watch and transfer those logs. I have not personally tried this, but it would be my best guess to tie it together.
- Someone hit 'Reboot' from portal or API. There is a List Operations history API call that you can check that will tell you which LiveID or certificate called the Reboot instance API.
So, if you see a OnStop, there is not much you can do about #1 short of turning off RDP (and as I said, I am not sure it would even trigger a OnStop). You can otherwise look to the infrastructure logs and List Operations API to see what initiated it.
来源:https://stackoverflow.com/questions/7062054/how-do-i-know-whether-my-azure-role-was-shut-down-by-runtime-or-manually