简体   繁体   中英

How to restarting server from an IIS process running on Azure?

We're running a WCF service on Azure and we want to be able to restart the machine from code.

I've attempted the following methods:

Method 1 - Using Process.Start("shutdown.exe")

http://msdn.microsoft.com/en-us/library/vstudio/system.diagnostics.process.start

Problem with this method - IIS 7 has security by the application pool, and manually changing permissions/etc on Azure resets and can't be trusted.

I've attempted using icacls ( http://technet.microsoft.com/en-us/library/cc753525.aspx ) to give IIS permission to run shutdown.exe but unfortunately it seems that it doesn't work on files inside the system32 folder.

Method 2 - Calling RoleEnvironment.RequestRecycle

http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.requestrecycle.aspx

We've used this function, it works well - however we require a full server restart and not just a role instance recycle.

Method 3 - Using Azure's REST API

http://msdn.microsoft.com/en-us/library/azure/gg441298.aspx

This so far looks the most promising method of achieving this, I was able to get this to work from my dev machine by generating a certificate, uploading it as a management certificate on the Azure portal, however, for the life of me I couldn't get the management certificate from the Azure instance itself.


So - If anyone can think of a way to make method 1 or 3 work is great, or if you can think of another option - it would be greatly appreciated.

Another option would be to use Azure Powershell cmdlets( http://azure.microsoft.com/en-us/documentation/articles/install-configure-powershell/ ).

You can then run Restart-AzureVM ( http://msdn.microsoft.com/en-us/library/dn495199.aspx ) + many other other management commands

I ended up using Method 3 (Using Azure's Management Libraries), and I used the base64 encoded management certificate inside the Publish settings file (which can be downloaded here https://windows.azure.com/download/publishprofile.aspx ).

Inside there was the base64 string of the management certificate attached to my subscription.

Not the prettiest solution, but it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM