由于启动脚本,Azure部署失败

时间:2012-11-11 09:03:14

标签: deployment azure startupscript

我在ServiceDefinition.csdef

中按照以下内容启动了启动脚本
<Startup>
  <Task commandLine="Microsoft.WindowsAzure.Caching\ClientPerfCountersInstaller.exe install" executionContext="elevated" taskType="simple" />
  <Task commandLine="startup.cmd" executionContext="elevated" taskType="simple" />
</Startup>

startup.cmd文件是

@echo off
REM StartupLog.txt can be found at (E or F):\approot\bin

Echo Copying MyUtil to system root                                                        >> StartupLog.txt 2>&1
copy /y MyUtil.exe %SystemRoot%                                                           >> StartupLog.txt 2>&1
IF ERRORLEVEL 1 GOTO ErrorExit

REM It's ok if the next fails, the task may not be scheduled 1st time
Echo Trying to delete MyUtil from scheduler                                               >> StartupLog.txt 2>&1
schtasks /Delete /F /TN "MyUtil"                                                          >> StartupLog.txt 2>&1

Echo Adding MyUtil to Scheduler                                                           >> StartupLog.txt 2>&1
schtasks /Create /SC MINUTE /MO 2 /SD 11/01/2012 /TN "MyUtil" /TR %SystemRoot%\MyUtil.exe >> StartupLog.txt 2>&1
IF ERRORLEVEL 1 GOTO ErrorExit                                                            >> StartupLog.txt 2>&1
GOTO End

:ErrorExit
REM   Report the date, time, and ERRORLEVEL of the error.
%ERRORLEVEL%                                                      >> StartupLog.txt 2>&1
DATE /T                                                           >> StartupLog.txt 2>&1
TIME /T                                                           >> StartupLog.txt 2>&1
ECHO An error occurred during startup. ERRORLEVEL = %ERRORLEVEL%  >> StartupLog.txt 2>&1
ECHO -----------------------------------------------------------  >> StartupLog.txt 2>&1
EXIT /B 1

:End    
ECHO Exiting at end with 0                                        >> StartupLog.txt 2>&1
ECHO -----------------------------------------------------------  >> StartupLog.txt 2>&1
EXIT /B 0

(E:或F:)\ approot \ bin中的错误是:

Copying MyUtil to system root                                                        
        1 file(s) copied.
Trying to delete MyUtil from scheduler                                                
SUCCESS: The scheduled task "MyUtil" was successfully deleted.
Adding MyUtil to Scheduler                                                            
ERROR: No mapping between account names and security IDs was done.

(43,4):LogonType:'1' is not recognized as an internal or external command,
operable program or batch file.

如果我在RDPing到WebRole后运行startup.cmd文件,那么任务就会被添加到调度程序中。由于某种原因,它总是通过部署失败。有谁知道如何解决这一问题?我恢复到OSVersion = 2,直到我能解决这个问题。

2 个答案:

答案 0 :(得分:0)

原因可能是执行脚本的用户(还)没有AppData目录。您可以尝试在启动任务的顶部添加这些吗?

md "%~dp0appdata"
reg add "hku\.default\software\microsoft\windows\currentversion\explorer\user shell folders" /v "Local AppData" /t REG_EXPAND_SZ /d "%~dp0appdata" /f

答案 1 :(得分:0)

我有完全相同的问题,在浪费了几个小时后认为这是一个权限问题,结果发现它想要在指定为/ TR参数的路径周围使用双引号。其实我有命令行参数,所以我需要指定它像“\”appname.exe \“\”参数\“”

和你一样,我在我的任务中使用了环境变量 - 这可能是相关的,尽管我不确定为什么。也像你一样,当我作为我的RDP用户启动时,任务运行正常,它在SYSTEM作为实际启动任务运行时失败了。

我知道几个月过去所以你可能已经离开了这个问题,但我很好奇报价是否也为你解决了问题(以及奖励积分,解释为什么它关心!)