共用方式為


常見的雲端服務 (傳統) 啟動工作

這很重要

截至 2024 年 9 月 1 日,所有客戶的雲端服務 (傳統) 均已淘汰。 從 2024 年 10 月開始,Microsoft 將停止並關閉任何現有的執行中部署,且資料將會永久遺失。 新的部署應該使用新的 Azure Resource Manager 型部署模型 Azure 雲端服務(外延支援)。

本文提供一些常見的啟動工作範例,做為您在雲端服務中執行的參考。 您可以使用啟動任務,在角色啟動之前執行操作。 您可能想要執行的作業包括安裝元件、註冊元件物件模型 (COM) 元件、設定登錄機碼,或啟動長時間執行的處理序。

請參閱 本文 以了解啟動工作的運作方式,特別是如何建立定義啟動工作的專案。

備註

啟動工作不適用於虛擬機器,只適用於雲端服務 Web 和工作者角色。

定義角色啟動前的環境變數

如果您需要針對特定工作定義的環境變數,請使用Task元素內的Environment元素。

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
    <WorkerRole name="WorkerRole1">
        ...
        <Startup>
            <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
                <Environment>
                    <Variable name="MyEnvironmentVariable" value="MyVariableValue" />
                </Environment>
            </Task>
        </Startup>
    </WorkerRole>
</ServiceDefinition>

變數也可以使用 有效的 Azure XPath 值 來參考有關部署的內容。 而不是使用 value 屬性,而是定義 RoleInstanceValue 子專案。

<Variable name="PathToStartupStorage">
    <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='StartupLocalStorage']/@path" />
</Variable>

使用 AppCmd.exe 設定 IIS 啟動

AppCmd.exe 命令行工具可用來在 Azure 啟動時管理 Internet Information Service (IIS) 設定。 AppCmd.exe 提供方便的命令行存取組態設定,以用於 Azure 上的啟動工作。 當您使用 AppCmd.exe時,可以新增、修改或移除應用程式和網站的網站設定。

不過,使用 AppCmd.exe 作為啟動工作時,有一些需要注意的事項:

  • 啟動工作可以在重新開機之間執行多次。 例如,角色回收時。
  • 如果執行 AppCmd.exe 動作一次以上,它可能會產生錯誤。 例如,嘗試將區段新增至 Web.config 兩次可能會產生錯誤。
  • 如果啟動工作傳回非零結束碼或 錯誤層級,啟動工作就會失敗。 例如, AppCmd.exe 產生錯誤時。

呼叫 AppCmd.exe之後檢查錯誤層級是很好的作法,如果您使用.cmd檔案包裝呼叫 AppCmd.exe,則很容易執行此動作。 如果您偵測到已知的 錯誤層級 回應,您可以忽略它,或將其傳回。

AppCmd.exe 傳回的錯誤層級值會列在 winerror.h 檔案中,也可以在Microsoft開發人員網路 (MSDN) 上看到。

管理錯誤層級的範例

本範例會將 JSON 的壓縮區段和壓縮專案新增至 Web.config 檔案,並顯示錯誤處理和記錄。

此處顯示 ServiceDefinition.csdef 檔案的相關區段,包括將 executionContext 屬性設定為 elevated ,以提供 AppCmd.exe 足夠的許可權來變更 Web.config 檔案中的設定:

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
    <WorkerRole name="WorkerRole1">
        ...
        <Startup>
            <Task commandLine="Startup.cmd" executionContext="elevated" taskType="simple" />
        </Startup>
    </WorkerRole>
</ServiceDefinition>

Startup.cmd批處理檔會使用 AppCmd.exe,將 JSON 的壓縮區段和壓縮專案新增至 Web.config 檔案。 預期的錯誤層級為 183,可使用命令列程式 VERIFY.EXE 設為零。 非預期的 errorlevel 會記錄至 StartupErrorLog.txt。

REM   *** Add a compression section to the Web.config file. ***
%windir%\system32\inetsrv\appcmd set config /section:urlCompression /doDynamicCompression:True /commit:apphost >> "%TEMP%\StartupLog.txt" 2>&1

REM   ERRORLEVEL 183 occurs when trying to add a section that already exists. This error is expected if this
REM   batch file were executed twice. This can occur and must be accounted for in an Azure startup
REM   task. To handle this situation, set the ERRORLEVEL to zero by using the Verify command. The Verify
REM   command will safely set the ERRORLEVEL to zero.
IF %ERRORLEVEL% EQU 183 VERIFY > NUL

REM   If the ERRORLEVEL is not zero at this point, some other error occurred.
IF %ERRORLEVEL% NEQ 0 (
    ECHO Error adding a compression section to the Web.config file. >> "%TEMP%\StartupLog.txt" 2>&1
    GOTO ErrorExit
)

REM   *** Add compression for json. ***
%windir%\system32\inetsrv\appcmd set config  -section:system.webServer/httpCompression /+"dynamicTypes.[mimeType='application/json; charset=utf-8',enabled='True']" /commit:apphost >> "%TEMP%\StartupLog.txt" 2>&1
IF %ERRORLEVEL% EQU 183 VERIFY > NUL
IF %ERRORLEVEL% NEQ 0 (
    ECHO Error adding the JSON compression type to the Web.config file. >> "%TEMP%\StartupLog.txt" 2>&1
    GOTO ErrorExit
)

REM   *** Exit batch file. ***
EXIT /b 0

REM   *** Log error and exit ***
:ErrorExit
REM   Report the date, time, and ERRORLEVEL of the error.
DATE /T >> "%TEMP%\StartupLog.txt" 2>&1
TIME /T >> "%TEMP%\StartupLog.txt" 2>&1
ECHO An error occurred during startup. ERRORLEVEL = %ERRORLEVEL% >> "%TEMP%\StartupLog.txt" 2>&1
EXIT %ERRORLEVEL%

新增防火牆規則

Azure 實際上擁有兩個防火牆。 第一道防火牆會控制虛擬機器與外界之間的連結。 ServiceDefinition.csdef 檔案中的 EndPoints 元素會控制此防火牆。

第二道防火牆會控制虛擬機器與該虛擬機器中處理序之間的連結。 您可以從 netsh advfirewall firewall 命令行工具控制此防火牆。

Azure 會針對在角色內啟動的處理序建立防火牆規則。 例如,在您啟動服務或程式時,Azure 會自動建立必要的防火牆規則,藉此允許該服務與網際網路通訊。 不過,如果您建立的服務是由角色外部的處理序啟動 (像是 COM+ 服務,或是 Windows 排程器工作),您就必須手動建立防火牆規則以允許存取該服務。 您可以使用啟動工作建立這些防火牆規則。

建立防火牆規則的啟動工作必須具有提升executionContext。 將下列啟動工作新增至 ServiceDefinition.csdef 檔案。

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
    <WorkerRole name="WorkerRole1">
        ...
        <Startup>
            <Task commandLine="AddFirewallRules.cmd" executionContext="elevated" taskType="simple" />
        </Startup>
    </WorkerRole>
</ServiceDefinition>

若要加入防火牆規則,您必須在啟動批次檔中使用適當的 netsh advfirewall firewall 命令。 在此範例中,啟動工作的傳輸控制通訊協定 (TCP) 連接埠 80 需要具備高安全性與加密功能。

REM   Add a firewall rule in a startup task.

REM   Add an inbound rule requiring security and encryption for TCP port 80 traffic.
netsh advfirewall firewall add rule name="Require Encryption for Inbound TCP/80" protocol=TCP dir=in localport=80 security=authdynenc action=allow >> "%TEMP%\StartupLog.txt" 2>&1

REM   If an error occurred, return the errorlevel.
EXIT /B %errorlevel%

封鎖特定的 IP 位址

您可以藉由修改 IIS web.config 檔案,限制對一組指定IP位址的 Azure Web 角色存取。 您也需要使用命令檔案來解除鎖定 ApplicationHost.config 檔案的ipSecurity區段。

若要解除鎖定 ApplicationHost.config 檔案的ipSecurity區段,請建立在角色啟動時執行的命令檔案。 在名為 startup 的 Web 角色根層級建立資料夾,並在此資料夾中建立名為 startup.cmd 的批處理檔。 將這個檔案新增至 Visual Studio 專案,並將屬性設為 [一律複製],以確保將它納入套件中。

將下列啟動工作新增至 ServiceDefinition.csdef 檔案。

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
    <WebRole name="WebRole1">
        ...
        <Startup>
            <Task commandLine="startup.cmd" executionContext="elevated" />
        </Startup>
    </WebRole>
</ServiceDefinition>

將此指令新增至 startup.cmd 檔案:

@echo off
@echo Installing "IPv4 Address and Domain Restrictions" feature 
powershell -ExecutionPolicy Unrestricted -command "Install-WindowsFeature Web-IP-Security"
@echo Unlocking configuration for "IPv4 Address and Domain Restrictions" feature 
%windir%\system32\inetsrv\AppCmd.exe unlock config -section:system.webServer/security/ipSecurity

此工作會在每次初始化 Web 角色時執行 startup.cmd 批處理檔,以確保必要的 ipSecurity 區 段已解除鎖定。

最後,修改 web 角色 web.config 檔案的 system.webServer 區段,以新增已授與存取權的 IP 位址清單,如下列範例所示:

此範例設定 可讓 所有IP存取伺服器,但兩個定義的IP除外

<system.webServer>
    <security>
    <!--Unlisted IP addresses are granted access-->
    <ipSecurity>
        <!--The following IP addresses are denied access-->
        <add allowed="false" ipAddress="192.168.100.1" subnetMask="255.255.0.0" />
        <add allowed="false" ipAddress="192.168.100.2" subnetMask="255.255.0.0" />
    </ipSecurity>
    </security>
</system.webServer>

此範例設定 會拒絕 存取伺服器的所有IP,但已定義的兩個IP除外。

<system.webServer>
    <security>
    <!--Unlisted IP addresses are denied access-->
    <ipSecurity allowUnlisted="false">
        <!--The following IP addresses are granted access-->
        <add allowed="true" ipAddress="192.168.100.1" subnetMask="255.255.0.0" />
        <add allowed="true" ipAddress="192.168.100.2" subnetMask="255.255.0.0" />
    </ipSecurity>
    </security>
</system.webServer>

建立 PowerShell 啟動工作

無法直接從 ServiceDefinition.csdef 檔案呼叫 Windows PowerShell 腳本,但可以從啟動批處理檔中叫用這些腳本。

PowerShell (依預設) 不會執行未簽署的指令碼。 除非簽署指令碼,否則需要將 PowerShell 設為執行未簽署的指令碼。 若要執行未簽署的腳本, ExecutionPolicy 必須設定為 [不受限制]。 您使用的 ExecutionPolicy 設定是以 Windows PowerShell 版本為基礎。

REM   Run an unsigned PowerShell script and log the output
PowerShell -ExecutionPolicy Unrestricted .\startup.ps1 >> "%TEMP%\StartupLog.txt" 2>&1

REM   If an error occurred, return the errorlevel.
EXIT /B %errorlevel%

如果您使用的客體 OS 是執行 PowerShell 2.0 或 1.0,可以強制執行第 2 版,如果無法這麼做,請改用第 1 版。

REM   Attempt to set the execution policy by using PowerShell version 2.0 syntax.
PowerShell -Version 2.0 -ExecutionPolicy Unrestricted .\startup.ps1 >> "%TEMP%\StartupLog.txt" 2>&1

REM   If PowerShell version 2.0 isn't available. Set the execution policy by using the PowerShell
IF %ERRORLEVEL% EQU -393216 (
   PowerShell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
   PowerShell .\startup.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
)

REM   If an error occurred, return the errorlevel.
EXIT /B %errorlevel%

透過啟動工作在本機儲存體中建立檔案

您可以使用本機儲存資源,儲存啟動工作所建立的檔案,以便日後存取您的應用程式。

若要建立本機記憶體資源,請將 LocalResources 區段新增至 ServiceDefinition.csdef 檔案,然後新增 LocalStorage 子元素。 將本機儲存體資源命名為不重複的名稱,然後為啟動工作提供適當的大小。

若要在啟動工作中使用本機儲存體資源,您需要建立環境變數來參考本機儲存體資源的位置。 接著,啟動工作和應用程式就能對本機儲存資源讀取及寫入檔案。

ServiceDefinition.csdef 檔案的相關區段如下所示:

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WorkerRole name="WorkerRole1">
    ...

    <LocalResources>
      <LocalStorage name="StartupLocalStorage" sizeInMB="5"/>
    </LocalResources>

    <Startup>
      <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
        <Environment>
          <Variable name="PathToStartupStorage">
            <RoleInstanceValue xpath="/RoleEnvironment/CurrentInstance/LocalResources/LocalResource[@name='StartupLocalStorage']/@path" />
          </Variable>
        </Environment>
      </Task>
    </Startup>
  </WorkerRole>
</ServiceDefinition>

例如,這個 Startup.cmd 批處理檔會使用 PathToStartupStorage 環境變數,在本機儲存位置上建立檔案 MyTest.txt

REM   Create a simple text file.

ECHO This text will go into the MyTest.txt file which will be in the    >  "%PathToStartupStorage%\MyTest.txt"
ECHO path pointed to by the PathToStartupStorage environment variable.  >> "%PathToStartupStorage%\MyTest.txt"
ECHO The contents of the PathToStartupStorage environment variable is   >> "%PathToStartupStorage%\MyTest.txt"
ECHO "%PathToStartupStorage%".                                          >> "%PathToStartupStorage%\MyTest.txt"

REM   Exit the batch file with ERRORLEVEL 0.

EXIT /b 0

您可以使用 GetLocalResource 方法,從 Azure SDK 存取本機記憶體資料夾。

string localStoragePath = Microsoft.WindowsAzure.ServiceRuntime.RoleEnvironment.GetLocalResource("StartupLocalStorage").RootPath;

string fileContent = System.IO.File.ReadAllText(System.IO.Path.Combine(localStoragePath, "MyTestFile.txt"));

在模擬器或雲端中執行

當啟動工作在雲端中運作時,您可以讓啟動工作執行有別於在計算模擬器中運作時的步驟。 例如,在模擬器中執行時,您可能只想使用 SQL 資料的全新複本。 或者,您可能想針對雲端執行一些效能最佳化作業,而這是不需要的作業。

在計算模擬器和雲端上執行不同動作的能力,可以在 ServiceDefinition.csdef 檔案中建立環境變數來完成。 然後,您會在啟動工作中測試該環境變數的值。

若要建立環境變數,請新增 Variable/RoleInstanceValue 元素,並建立的 /RoleEnvironment/Deployment/@emulatedXPath 值。 %ComputeEmulatorRunning% 環境變數的值是在true計算模擬器上執行,以及在false雲端上執行時。

<ServiceDefinition name="MyService" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceDefinition">
  <WorkerRole name="WorkerRole1">

    ...

    <Startup>
      <Task commandLine="Startup.cmd" executionContext="limited" taskType="simple">
        <Environment>
          <Variable name="ComputeEmulatorRunning">
            <RoleInstanceValue xpath="/RoleEnvironment/Deployment/@emulated" />
          </Variable>
        </Environment>
      </Task>
    </Startup>

  </WorkerRole>
</ServiceDefinition>

這項任務現在能夠檢查 %ComputeEmulatorRunning% 環境變數,來決定角色在雲端或模擬器中的執行方式。 以下是檢查該環境變數的 .cmd 命令介面指令碼。

REM   Check if this task is running on the compute emulator.

IF "%ComputeEmulatorRunning%" == "true" (
    REM   This task is running on the compute emulator. Perform tasks that must be run only in the compute emulator.
) ELSE (
    REM   This task is running on the cloud. Perform tasks that must be run only in the cloud.
)

偵測工作是否已在執行

角色可能會未經重新開機便進行回收,導致您的啟動工作再執行一次。 沒有旗標可指出已在主機虛擬機器 (VM) 上執行的工作。 可能有些工作即便多次執行也沒關係。 不過,在某些情況下,您必須避免工作執行一次以上。

偵測工作已執行的最簡單方式,是在工作成功時,在 %TEMP% 資料夾中建立檔案,並在工作開始時尋找檔案。 以下是可為您執行此作業的範例 cmd Shell 指令碼。

REM   If Task1_Success.txt exists, then Application 1 is already installed.
IF EXIST "%PathToApp1Install%\Task1_Success.txt" (
  ECHO Application 1 is already installed. Exiting. >> "%TEMP%\StartupLog.txt" 2>&1
  GOTO Finish
)

REM   Run your real exe task
ECHO Running XYZ >> "%TEMP%\StartupLog.txt" 2>&1
"%PathToApp1Install%\setup.exe" >> "%TEMP%\StartupLog.txt" 2>&1

IF %ERRORLEVEL% EQU 0 (
  REM   The application installed without error. Create a file to indicate that the task
  REM   does not need to be run again.

  ECHO This line will create a file to indicate that Application 1 installed correctly. > "%PathToApp1Install%\Task1_Success.txt"

) ELSE (
  REM   An error occurred. Log the error and exit with the error code.

  DATE /T >> "%TEMP%\StartupLog.txt" 2>&1
  TIME /T >> "%TEMP%\StartupLog.txt" 2>&1
  ECHO  An error occurred running task 1. Errorlevel = %ERRORLEVEL%. >> "%TEMP%\StartupLog.txt" 2>&1

  EXIT %ERRORLEVEL%
)

:Finish

REM   Exit normally.
EXIT /B 0

工作最佳作法

為 Web 或背景工作角色設定工作時,應該遵循的最佳作法如下。

務必記錄啟動活動

Visual Studio 並未提供可逐步執行批次檔的偵錯工具,因此最好盡可能取得越多批次檔作業上的資料。 記錄批處理文件的輸出, stdoutstderr,可以在嘗試偵錯和修正批處理檔時提供重要資訊。 若要將 stdoutstderr 記錄至 %TEMP% 環境變數所指向之目錄中的 StartupLog.txt 檔案,請將文字 >> "%TEMP%\\StartupLog.txt" 2>&1 新增至您想要記錄的特定行尾。 例如,若要在 %PathToApp1Install% 目錄中執行 setup.exe: "%PathToApp1Install%\setup.exe" >> "%TEMP%\StartupLog.txt" 2>&1

為了簡化您的 xml,您可以建立包裝函式 Cmd 檔案,以呼叫所有啟動工作以及記錄,並確保每個子工作共用相同的環境變數。

不過,您可能會覺得在每個啟動工作的一端使用 >> "%TEMP%\StartupLog.txt" 2>&1 很麻煩。 您可以建立會為您處理記錄的包裝函式,以強制執行工作記錄。 此包裝函式會呼叫您要執行的實際批次檔。 目標批處理檔的任何輸出會重新導向至 Startuplog.txt 檔案。

以下範例示範如何從啟動批次檔重新導向所有的輸出。 在此範例中,ServerDefinition.csdef 檔案會建立呼叫 logwrap.cmd 的啟動工作。 logwrap.cmd 呼叫 Startup2.cmd,將所有輸出重新導向至 %TEMP%\StartupLog.txt

ServiceDefinition.cmd:

<Startup>
    <Task commandLine="logwrap.cmd startup2.cmd" executionContext="limited" taskType="simple" />
</Startup>

logwrap.cmd:

@ECHO OFF

REM   logwrap.cmd calls passed in batch file, redirecting all output to the StartupLog.txt log file.

ECHO [%date% %time%] == START logwrap.cmd ============================================== >> "%TEMP%\StartupLog.txt" 2>&1
ECHO [%date% %time%] Running %1 >> "%TEMP%\StartupLog.txt" 2>&1

REM   Call the child command batch file, redirecting all output to the StartupLog.txt log file.
START /B /WAIT %1 >> "%TEMP%\StartupLog.txt" 2>&1

REM   Log the completion of child command.
ECHO [%date% %time%] Done >> "%TEMP%\StartupLog.txt" 2>&1

IF %ERRORLEVEL% EQU 0 (

   REM   No errors occurred. Exit logwrap.cmd normally.
   ECHO [%date% %time%] == END logwrap.cmd ================================================ >> "%TEMP%\StartupLog.txt" 2>&1
   ECHO.  >> "%TEMP%\StartupLog.txt" 2>&1
   EXIT /B 0

) ELSE (

   REM   Log the error.
   ECHO [%date% %time%] An error occurred. The ERRORLEVEL = %ERRORLEVEL%.  >> "%TEMP%\StartupLog.txt" 2>&1
   ECHO [%date% %time%] == END logwrap.cmd ================================================ >> "%TEMP%\StartupLog.txt" 2>&1
   ECHO.  >> "%TEMP%\StartupLog.txt" 2>&1
   EXIT /B %ERRORLEVEL%

)

Startup2.cmd:

@ECHO OFF

REM   This is the batch file where the startup steps should be performed. Because of the
REM   way Startup2.cmd was called, all commands and their outputs will be stored in the
REM   StartupLog.txt file in the directory pointed to by the TEMP environment variable.

REM   If an error occurs, the following command will pass the ERRORLEVEL back to the
REM   calling batch file.

ECHO [%date% %time%] Some log information about this task
ECHO [%date% %time%] Some more log information about this task

EXIT %ERRORLEVEL%

StartupLog.txt 檔案中的範例輸出:

[Mon 10/17/2016 20:24:46.75] == START logwrap.cmd ============================================== 
[Mon 10/17/2016 20:24:46.75] Running command1.cmd 
[Mon 10/17/2016 20:24:46.77] Some log information about this task
[Mon 10/17/2016 20:24:46.77] Some more log information about this task
[Mon 10/17/2016 20:24:46.77] Done 
[Mon 10/17/2016 20:24:46.77] == END logwrap.cmd ================================================ 

小提示

StartupLog.txt 檔案位於 C:\Resources\temp\{role identifier}\RoleTemp 資料夾中。

正確設定啟動工作的 executionContext

正確設定啟動工作的權限。 有時候,即使角色是以正常的權限執行,啟動工作也必須以較高的權限執行。

executionContext 屬性會設定啟動工作的許可權等級。 使用 executionContext="limited" 表示啟動工作有和角色相同的權限等級。 使用 executionContext="elevated" 表示啟動工作有系統管理員權限,您不用將系統管理員權限提供給您的角色,便可讓啟動工作執行系統管理員工作。

需要提高許可權的啟動工作範例是使用 AppCmd.exe 來設定IIS的啟動工作。 AppCmd.exe 需要 executionContext="elevated"

使用正確的 taskType

taskType 屬性會決定啟動工作的執行方式。 有三個值: 簡單背景前景。 background 和 foreground 工作會以非同步方式啟動,而 simple 工作會以同步方式執行,一次一個。

透過 簡單的 啟動工作,您可以設定工作依 ServiceDefinition.csdef 檔案中列出工作的順序執行的順序。 如果 簡單的 工作以非零結束代碼結束,啟動程式就會停止,且角色不會啟動。

背景啟動工作與前景啟動工作之間的差異在於前景工作會讓角色持續執行,直到前景工作結束為止。 這個結構表示,如果 前景 工作停止回應或當機,角色會保持未回收,直到 前景 工作強制關閉為止。 基於這個理由,建議使用背景工作來執行異步啟動任務,除非您需要前景工作的那個功能。

以 EXIT /B 0 結束批次檔

只有當每個簡單啟動任務的 errorlevel 為零時,角色才會啟動。 並非所有程式都已正確設定 errorlevel (結束代碼),因此如果一切正常執行,批處理文件應該以 EXIT /B 0 結尾。

啟動批次檔的結尾遺漏 EXIT /B 0 ,是角色無法啟動的常見原因。

備註

我注意到使用 /B 參數時,巢狀批次檔有時會停止回應。 如果另一個批處理檔呼叫目前的批處理檔,例如使用 記錄包裝函式,您可能想要確定此問題不會發生。 在此案例中,您可以省略 /B 參數。

啟動工作預計會執行一次以上

並非所有角色回收都會重新開機,但所有角色回收都會執行全部的啟動工作。 此設計表示啟動工作必須在重新啟動之間能夠執行多次,並且不會有任何問題,如上一節所述。

使用本機儲存體儲存必須在角色中存取的檔案

如果您想要在啟動工作期間複製或建立檔案,然後供您的角色存取,則該檔案必須放在本機儲存體中。 請參閱 上一節

後續步驟

檢閱雲端 服務模型和套件

深入瞭解 工作 的運作方式。

建立及部署 您的雲端服務套件。