How to get environment variable and information in startup task

Proposed How to get environment variable and information in startup task

  • venerdì 24 dicembre 2010 02:33
     
     

    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>

Tutte le risposte

  • giovedì 20 gennaio 2011 04:50
     
     

    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.
  • giovedì 24 marzo 2011 19:13
    Moderatore
     
     

    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.
  • giovedì 5 maggio 2011 11:23
     
     

    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
  • giovedì 5 maggio 2011 14:34
     
     Risposta suggerita
    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.
    • Proposto come risposta Arora S giovedì 12 maggio 2011 12:13
    •  
  • venerdì 6 maggio 2011 04:17
     
     

    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
  • giovedì 12 maggio 2011 12:13
     
     Risposta suggerita

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

     


    S Arora
    • Proposto come risposta Arora S giovedì 12 maggio 2011 12:13
    •  
  • mercoledì 10 agosto 2011 08:41
     
     

    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

  • mercoledì 10 agosto 2011 18:19
     
     
    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?
  • giovedì 11 agosto 2011 07:40
     
     
    Ups, sorry, ok i will open a new thread.
  • lunedì 17 settembre 2012 12:59
     
     

    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