How to get environment variable and information in startup task

Proposed How to get environment variable and information in startup task

  • Friday, December 24, 2010 2:33 AM
     
     

    I am trying the new  startup task feature from azure 1.3

    But I don't know how to get the enviroment variables in the startup task, such as role approot, and local resource path. As I want to do some processing in startup task.


    <WebRole name="WebRole1">
      <Startup>
         <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
         </Task>
      </Startup>
    </WebRole>

All Replies

  • Thursday, January 20, 2011 4:50 AM
     
     

    Hi,
    If I understood it correctly..you want to set and access environment variable from cmd / code file.

    You can define the environment variable in CSDEF file http://msdn.microsoft.com/en-us/library/gg432991.aspx and you should be able to access it in your code using something like this System.Environment.GetEnvironmentVariable .

    In .cmd/batch file you should be able to access it using "%VARIABLE%" (Variable is the name of environment variable here)

    Hope this helps.

    -Sachin Sancheti


    -Life was much simpler when apple and blackberries were just fruits.
  • Thursday, March 24, 2011 7:13 PM
    Moderator
     
     

    Maybe late but still - you can use %ROLEROOT% which points to your Role's root folder. Your role's approot folder is %ROLEROOT%\Approot.

    Hope this helps.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
  • Thursday, May 05, 2011 11:23 AM
     
     

    to add to this

    can I have parameters for my start up tasks ?

    eg I have to unzip a file lying somewhere on c drive but it can be any xyz file .. so can i specify name as argu to my start up task !

     


    S Arora
  • Thursday, May 05, 2011 2:34 PM
     
     Proposed
    No, but your startup task can just be a batch file that calls something else with a parameter. So if you want to call "foo.exe xyz" just make a batch file called foo.cmd with "foo.exe xyz" in it, and then call foo.cmd as a startup task.
    • Proposed As Answer by Arora S Thursday, May 12, 2011 12:13 PM
    •  
  • Friday, May 06, 2011 4:17 AM
     
     

    Thanks Steve

    however how do I make that parameter reach till that nested foo.exe through my startup task.

    PS : your blog and cloud cover videos are simply great Steve.

     

     


    S Arora
  • Thursday, May 12, 2011 12:13 PM
     
     Proposed

    I am now calling my process from worker role with Process.start and passing argument with process start info

     


    S Arora
    • Proposed As Answer by Arora S Thursday, May 12, 2011 12:13 PM
    •  
  • Wednesday, August 10, 2011 8:41 AM
     
     

    Hello Steve, but i think there is another problem, in staging i can see more units, c: d: e: and in my code i must to autodetect in witch of those units is installed IIS, then i configure my ISAPI for perl in the Web.config and i must to put the full path (and i don´t know witch the correct path). How can i ask in the method onstart where is installed IIS or which is the correct unit or the full path incluyin unit? in producction i see less unit only see c: and d: and i don´t know why.

    Thank you for you help

  • Wednesday, August 10, 2011 6:19 PM
     
     
    I'm not sure how your question relates to this thread. Perhaps you should start a new thread and clarify what you're trying to do?
  • Thursday, August 11, 2011 7:40 AM
     
     
    Ups, sorry, ok i will open a new thread.
  • Monday, September 17, 2012 12:59 PM
     
     

    Hi..

    I want to add Environment variable in my csdef file. When I <Environment> element in my ServiceDefinition.csdef file, it's giving me error.

    Warning    1    The element 'VirtualMachineRole' in namespace 'http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition' has invalid child element 'Startup' in namespace 'http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition'. List of possible elements expected: 'Certificates, LocalResources, Endpoints, ConfigurationSettings' in namespace 'http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition'.    c:\users\administrator\documents\visual studio 2010\Projects\WindowsAzure6_Env\WindowsAzure6_Env\ServiceDefinition.csdef    7    6    WindowsAzure6_Env

    My File look like below

    <?xml version="1.0" encoding="utf-8"?>
    <ServiceDefinition name="WindowsAzure6_Env" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition" schemaVersion="2012-05.1.7">
      <VirtualMachineRole name="VMRole1" vmsize="Small">
        <Imports>
          <Import moduleName="Diagnostics" />
        </Imports>
        <Startup>
               <Environment>
              <Variable name="MY_ENV" value="my_value" />
            </Environment>
         </Startup>
        <Runtime>
          <Environment>
            <Variable name="MY_SECOND_ENV" value="my_value2" />
          </Environment>
        </Runtime>
      </VirtualMachineRole>
    </ServiceDefinition>

    Please let me know if you have any solution.Thanks