Some of you may remember a little project I created last year called RubyRole, which let you host Ruby applications as a Windows Azure hosted service (now called a cloud service.) I updated it the other day to fix a few issues with the recent spring update to Windows Azure, and discovered some interesting things with the new Windows Azure PowerShell.
Windows Azure PowerShell and Ruby
The Windows Azure PowerShell is included with the Windows version of the Windows Azure Node.js SDK and PHP SDK, but I’ve discovered that it’s generically useful for deploying and managing cloud services like RubyRole (or really anything that’s a cloud service, such as Rob Blackwell’s AzureRunme.) The trick is that the project has to have updated ServiceConfiguration and ServiceDefinition files for the spring update, and that there has to be a deploymentSettings.json file in the root of the project.
With the Other SDK, I had to use run.cmd to launch the application in the emulator. It worked, but it didn’t have a stop and you had to be in the right directory when you ran the command, etc. Windows Azure PowerShell provides the following cmdlets for working with the emulator:
Start-AzureEmulator – Starts the emulator. The optional
-launchswitch will launch your browser to the URL of the application in the emulator once it’s started.
Stop-AzureEmulator – Stops the emulator.
Importing Subscription Info
While the emulator commands work out of the box, the rest of the commands I talk about below require some information about your subscription. This is a pretty painless process, and you just have to do it once. Here’s the steps:
Download a .publishsettings file that contains your subscription information plus a management certificate that lets you manage your Windows Azure services from the command line. You can do this using the Get-AzurePublishSettingsFile cmdlet.
This will launch the browser and prompt you to login, then download the .publishsettings file. Save this file somewhere secure, as it contains information that can be used to access and manage your subscription.
Import the .publishsettingsfile by using the Import-AzurePublishSettingsFile cmdlet as follows:
This will import the information contained in the file and store it in the .azure directory under your user directory.
Note: You should delete the .publishsettings file after the import, as anyone can import it and use it to manage your subscription.
That’s it. Once you do those steps, you’re set for publishing/managing your services from PowerShell.
Note: If you have multiple Windows Azure Subscriptions associated with your login, the .publishsettings file will contain information for all of them and will default to one of them. You can see them all by using Get-AzureSubscription and can set the default by using Set-AzureSubscription. Many commands also allow you to use a
-subscription parameter and specify the subscription name to indicate which subscription to perform the action against.
Prior to the spring update the only way to deploy the RubyRole project was to use the pack.cmd batch file, which only packaged up the service; you still had to manually upload it. Windows Azure PowerShell provides functionality to pack and deploy the application straight from the command line.
The cmdlet to deploy the project is Publish-AzureServiceProject. This packages up the project, creates a Windows Azure storage account if one isn’t already available, and uploads the project to it. Then it creates a cloud service out of the project and starts it.
This command also takes a
-launch parameter, which will launch your browser and navigate to the hosted application after the cloud service is up and running.
So you’ve got an application in RubyRole and it works in the emulator, but blows up in the cloud. What to do? Your first step should probably be to use the Enable-AzureServiceProjectRemoteDesktop cmdlet to turn on remote desktop for the project. Once deployed, you can then use the Windows Azure portal to remote into the virtualized environment, look at logs, debug, etc. To turn this off, just use Disable-AzureServiceProjectRemoteDesktop.
Unfortunately this still only works with the Windows remote desktop client.
There are several other management style things you can do with Windows Azure PowerShell, such as:
Stop-AzureService – stop a running cloud service
Remove-AzureService – removes a cloud service
Start-AzureService – starts a stopped cloud service
You can get a full list of the basic developer cmdlets by running
help node-dev or
help php-dev and a full list of the Windows Azure cmdlets by running
As you can see, these are much better than the simple run.cmd and pack.cmd functions available in the Other SDK. They make it much easier for working with projects like RubyRole from the command line. For more information on Windows Azure PowerShell, see How to Use Windows Azure PowerShell.
Note: These cmdlets won’t work with the older version of RubyRole because of some changes to the ServiceDefinition and ServiceConfig structure. Also because they rely on a deploymentSettings.json file in the root of your web project.