wtorek, 23 lipca 2013

New Relic on Azure - role instances are taking longer than expected to start

I was installing New Relic in my Azure Cloud Service role. I followed instructions from New Relic's page and... it didn't worked. On my local machine I no longer could start the instance. I saw the message "role instances are taking longer than expected to start".



 

I expected that problem is caused by startup script that is added by New Relic to ServiceDefinition.csdef:
    
      
        
          
            
          
          
        
      
    

asd

After debugging I found that New Relic batch script is not compatible with non-english Windows version, causing problems on date parsing and running in folder with spaces in path. So I've changed the script a little bit and now everything is working well. You can see code of the script below - just replace the content of existing newrelic.cmd file, and enter your valid LICENSE_KEY

Final source code of newrelic.cmd




SETLOCAL EnableExtensions

IF EXIST "%RoleRoot%\nr.log" (
    ECHO The New Relic .net Agent is already installed. Exiting. >> "%RoleRoot%\nr.log" 2>&1
    GOTO :EXIT
)

ECHO Begin installing the New Relic .net Agent >> "%RoleRoot%\nr.log" 2>&1

:: Update with your license key
SET LICENSE_KEY=**********
:: Current version of the installer
SET NR_INSTALLER_NAME=NewRelicAgent_x64_2.8.135.0.msi
:: Path used for custom configuration and worker role environment varibles
SET NR_HOME=%ALLUSERSPROFILE%\New Relic\.NET Agent\

ECHO Installing the New Relic .net Agent. >> "%RoleRoot%\nr.log" 2>&1

msiexec.exe /i %NR_INSTALLER_NAME% /norestart /quiet NR_LICENSE_KEY=%LICENSE_KEY% /lv* "%RoleRoot%\nr_install.log"

:: CUSTOM newrelic.xml : Uncomment the line below if you want to copy a custom newrelic.xml file into your instance
REM copy /Y newrelic.xml %NR_HOME% >> %RoleRoot%\nr.log

:: CUSTOM INSTRUMENTATION : Uncomment the line below to copy custom instrumentation into the agent directory.
REM copy /y CustomInstrumentation.xml %NR_HOME%\extensions >> %RoleRoot%\nr.log

:: If we are in a Worker Role then there is no need to restart W3SVC
if "%IsWorkerRole%" EQU "true" goto :FINALIZE

:: If we are emulating locally then do not restart W3SVC
if "%EMULATED%" EQU "true" goto :FINALIZE

:: WEB ROLES : Restart the service to pick up the new environment variables
ECHO Restarting IIS and W3SVC to pick up the new environment variables >> "%RoleRoot%\nr.log" 2>&1
IISRESET
NET START W3SVC

:FINALIZE
IF %ERRORLEVEL% EQU 0 (
  REM  The New Relic .net Agent installed ok and does not need to be installed again.
  ECHO New Relic .net Agent was installed successfully. >> "%RoleRoot%\nr.log" 2>&1

) ELSE (
  REM   An error occurred. Log the error to a separate log and exit with the error code.
  ECHO  An error occurred installing the New Relic .net Agent 1. Errorlevel = %ERRORLEVEL%. >> "%RoleRoot%\nr_error.log" 2>&1

  EXIT %ERRORLEVEL%
)

:EXIT
EXIT /B 0