April 29, 2013
I spoke to an MS contact the other day asking me how I've been going setting up Azure. It seems 90% of my issues all kept coming back to correctly creating / configuring a startup script.
Creating the script
The script is basically a text file saved with a .cmd extension. I called mine LaunchOnStartup.cmd and inside it contains my scripts to be run. Eg,
powershell -Command "Set-ExecutionPolicy Unrestricted"
powershell new-eventlog -logname 'Application' -Source 'MyAppDB'
powershell new-eventlog -logname 'Application' -Source 'MyAppService'
See my post on Azure Event Viewer EventLog ... Logging
for an important tip on setting osFamily
Once last thing to remember is to select your file in the Visual Studio project, properties. And select the "Copy to Output Directory" = "Copy Always".
Text format ANSI
Once gotcha I faced was the script file's format. I created the file in visual studio, saved ... all good. But guess what, Azure server never starts. After running the script manually on the server in command prompt (knowing my powershell script wouldn't work but still I was desperate) I noticed two funky strange characters at the beginning of the script. They didn't show up in notepad but certainly did in command prompt. As a result .... "Bad command or filename" (well something similar).
The solution I eventually arrived at was to do my editing of the script. Then close it in visual studio. Open it in notepad, save as. Overwrite the same file but ensure the text format
. Once this was done my script ran fine in the command prompt and what do you know, ran fine in Azure also!
Place the reference to the file at the top of your ServiceDefinition.csdef
I should test this again as it was bundled in with all the other issues I was facing around startup scripts. But certainly placing it at the top of the file just below the
<WebRole name="MyApp" vmsize="Small">
<Task commandLine="LaunchOnStartup.cmd" executionContext="elevated" taskType="simple">
I have a few more posts on working with Azure
so why not take a quick moment to browse the tag cloud.